1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

Fixed locale selection

This commit is contained in:
Federico Fissore 2013-10-02 17:34:09 +02:00
parent 2f38d1aaa5
commit 63914efb06

View File

@ -13,8 +13,10 @@
package processing.app;
import java.util.*;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class I18n {
// start using current locale but still allow using the dropdown list later
@ -31,13 +33,18 @@ public class I18n {
static protected void init(String language) throws MissingResourceException {
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
try {
if (language != null && language.trim().length() > 0) {
Locale locale = new Locale(language);
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", locale);
Locale.setDefault(locale);
} else {
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", Locale.getDefault());
String[] languageParts = language.split("_");
Locale locale = Locale.getDefault();
// both language and country
if (languageParts.length == 2) {
locale = new Locale(languageParts[0], languageParts[1]);
// just language
} else if (languageParts.length == 1 && !"".equals(languageParts[0])) {
locale = new Locale(languageParts[0]);
}
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
Locale.setDefault(locale);
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", Locale.getDefault());
PROMPT_YES = _("Yes");
PROMPT_NO = _("No");
PROMPT_CANCEL = _("Cancel");
@ -76,7 +83,7 @@ public class I18n {
/**
* Does nothing.
*
* <p/>
* This method is an hack to extract words with gettext tool.
*/
protected static void unusedStrings() {