I prepared own class Internationalization which extends class ResourceBundle for exception hangling when key is not found in properties file.
public class Internationalization extends ResourceBundle{
private ResourceBundle bundle;
public Internationalization(ResourceBundle bundle) {
this.bundle = bundle;
}
public String getFormattedString(String key, Object[] args) {
if (bundle.containsKey(key)) {
String value = bundle.getString(key);
value = replaceSingleQuotes(value);
MessageFormat mf = new MessageFormat(value);
return mf.format(args);
} else {
return '!' + key + '!';
}
}
private static String replaceSingleQuotes(String template) {
return template.replace("'", "''");
}
@Override
protected Object handleGetObject(String key) {
if (bundle.containsKey(key)) {
return bundle.getString(key);
} else {
return '!' + key + '!';
}
}
@Override
public Enumeration<String> getKeys() {
return bundle.getKeys();
}
}
But FXMLLoader still throws exception "Resource "MissingKey" not found." when key is not in the properies file.
Internationalization lngStr = new Internationalization(ResourceBundle.getBundle("language/lngStr"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/LogIn.fxml"));
loader.setResources(lngStr);
Pane pane = loader.load();
scrMain.setContent((Node) pane);
Can you help me please to find where is the problem?