开发者

Define a default .properties file depending on language

开发者 https://www.devze.com 2023-01-01 13:33 出处:网络
I have 2 .properties files in my java project and I wa开发者_StackOverflownt to define one of them as default file to be used when the language of the operating system is different from the 2 language

I have 2 .properties files in my java project and I wa开发者_StackOverflownt to define one of them as default file to be used when the language of the operating system is different from the 2 languages already defined. Can you tell me please what should I add to my code to make that possible?


ResourceBundle is your ticket. Here is a tutorial


Name the 2 .properties files by the same base name plus the language code, e.g. prop_de.properties and prop_en.properties. Then copy one of them and name it prop.properties. This is the fallback. If the files are in package org.foo then

        ResourceBundle bundle = ResourceBundle.getBundle( "org.foo.prop" );

gives you a bundle with the behaviour you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号