Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #186: Fix i18n feature #189

Merged
merged 2 commits into from Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions app/src/main/java/com/oracle/javafx/scenebuilder/app/i18n/I18N.java
Expand Up @@ -33,31 +33,30 @@

import java.text.MessageFormat;
import java.util.ResourceBundle;

/**
*
*/

import com.oracle.javafx.scenebuilder.kit.i18n.I18NControl;

public class I18N {

private static ResourceBundle bundle;


private static ResourceBundle.Control utf8EncodingControl = new I18NControl();

public static String getString(String key) {
return getBundle().getString(key);
}

public static String getString(String key, Object... arguments) {
final String pattern = getString(key);
return MessageFormat.format(pattern, arguments);
}

public static synchronized ResourceBundle getBundle() {
if (bundle == null) {
final String packageName = I18N.class.getPackage().getName();
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderApp"); //NOI18N
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderApp",utf8EncodingControl); //NOI18N
}

return bundle;
}
}

Expand Up @@ -40,6 +40,8 @@
public class I18N {

private static ResourceBundle bundle;

private static ResourceBundle.Control utf8EncodingControl = new I18NControl();

public static String getString(String key) {
return getBundle().getString(key);
Expand All @@ -53,7 +55,7 @@ public static String getString(String key, Object... arguments) {
public static synchronized ResourceBundle getBundle() {
if (bundle == null) {
final String packageName = I18N.class.getPackage().getName();
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderKit"); //NOI18N
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderKit",utf8EncodingControl); //NOI18N
}

return bundle;
Expand Down
@@ -0,0 +1,25 @@
package com.oracle.javafx.scenebuilder.kit.i18n;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class I18NControl extends ResourceBundle.Control {
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
try (InputStream is = loader.getResourceAsStream(resourceName);
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader reader = new BufferedReader(isr)) {
return new PropertyResourceBundle(reader);
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
}
}