mirror of https://github.com/noisymime/Arduino.git
Fixed locale selection
This commit is contained in:
parent
2f38d1aaa5
commit
63914efb06
|
@ -13,8 +13,10 @@
|
||||||
|
|
||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class I18n {
|
public class I18n {
|
||||||
// start using current locale but still allow using the dropdown list later
|
// start using current locale but still allow using the dropdown list later
|
||||||
|
@ -28,16 +30,21 @@ public class I18n {
|
||||||
static String PROMPT_OK;
|
static String PROMPT_OK;
|
||||||
static String PROMPT_BROWSE;
|
static String PROMPT_BROWSE;
|
||||||
|
|
||||||
static protected void init (String language) throws MissingResourceException {
|
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
|
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
|
||||||
try {
|
try {
|
||||||
if (language != null && language.trim().length() > 0) {
|
String[] languageParts = language.split("_");
|
||||||
Locale locale = new Locale(language);
|
Locale locale = Locale.getDefault();
|
||||||
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", locale);
|
// both language and country
|
||||||
Locale.setDefault(locale);
|
if (languageParts.length == 2) {
|
||||||
} else {
|
locale = new Locale(languageParts[0], languageParts[1]);
|
||||||
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", Locale.getDefault());
|
// 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_YES = _("Yes");
|
||||||
PROMPT_NO = _("No");
|
PROMPT_NO = _("No");
|
||||||
PROMPT_CANCEL = _("Cancel");
|
PROMPT_CANCEL = _("Cancel");
|
||||||
|
@ -54,18 +61,18 @@ public class I18n {
|
||||||
} catch (MissingResourceException e) {
|
} catch (MissingResourceException e) {
|
||||||
res = s;
|
res = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The single % is the arguments selector in .PO files.
|
// The single % is the arguments selector in .PO files.
|
||||||
// We must put double %% inside the translations to avoid
|
// We must put double %% inside the translations to avoid
|
||||||
// getting .PO processing in the way.
|
// getting .PO processing in the way.
|
||||||
res = res.replace("%%", "%");
|
res = res.replace("%%", "%");
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String format(String fmt, Object ... args) {
|
public static String format(String fmt, Object... args) {
|
||||||
// Single quote is used to escape curly bracket arguments.
|
// Single quote is used to escape curly bracket arguments.
|
||||||
|
|
||||||
// - Prevents strings fixed at translation time to be fixed again
|
// - Prevents strings fixed at translation time to be fixed again
|
||||||
fmt = fmt.replace("''", "'");
|
fmt = fmt.replace("''", "'");
|
||||||
// - Replace ' with the escaped version ''
|
// - Replace ' with the escaped version ''
|
||||||
|
@ -73,10 +80,10 @@ public class I18n {
|
||||||
|
|
||||||
return MessageFormat.format(fmt, args);
|
return MessageFormat.format(fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does nothing.
|
* Does nothing.
|
||||||
*
|
* <p/>
|
||||||
* This method is an hack to extract words with gettext tool.
|
* This method is an hack to extract words with gettext tool.
|
||||||
*/
|
*/
|
||||||
protected static void unusedStrings() {
|
protected static void unusedStrings() {
|
||||||
|
|
Loading…
Reference in New Issue