I have the following Java i18n Message class.:
public class Messages {
private static final String BUNDLE_NAME = "languages.message";
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getI18n(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
public static String getI18n(String key, Object... params ) {
try {
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
I have created the following message properties files.:
message.properties
message_de.properties
message_de_DE.properties
In my program I get the translation according to the default locale of the system. If it is de_DE
, the german message properties message_de_DE.properties
loaded.
If the default locale is de_CH
, then there is no message properties file. Is then the message_de.properties
as fallback loaded or do I need to implement it by myself?
According to this blog post you are right.