1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-02 22:52:12 +01:00

97 lines
2.8 KiB
Java
Raw Normal View History

/*
* by Shigeru KANEMOTO at SWITCHSCIENCE.
*
* Extract strings to be translated by:
* % xgettext -L Java --from-code=utf-8 -k_ -d Resources_ja *.java
* Extract and merge by:
* % xgettext -j -L Java --from-code=utf-8 -k_ -d Resources_ja *.java
*
* Edit "Resources_ja.po".
* Convert to the properties file format by:
* % msgcat -p Resources_ja.po > Resources_ja.properties
*/
package processing.app;
import java.text.MessageFormat;
2013-10-02 17:34:09 +02:00
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
2012-12-13 15:18:22 +01:00
private static ResourceBundle i18n;
// prompt text stuff
public static String PROMPT_YES;
public static String PROMPT_NO;
public static String PROMPT_CANCEL;
public static String PROMPT_OK;
public static String PROMPT_BROWSE;
2013-10-02 17:34:09 +02:00
static protected void init(String language) throws MissingResourceException {
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");
PROMPT_OK = _("OK");
PROMPT_BROWSE = _("Browse");
}
public static String _(String s) {
String res;
try {
if (i18n == null)
res = s;
else
res = i18n.getString(s);
} catch (MissingResourceException e) {
res = s;
}
2013-10-02 17:34:09 +02:00
// The single % is the arguments selector in .PO files.
// We must put double %% inside the translations to avoid
// getting .PO processing in the way.
res = res.replace("%%", "%");
2013-10-02 17:34:09 +02:00
return res;
}
2013-10-02 17:34:09 +02:00
public static String format(String fmt, Object... args) {
// Single quote is used to escape curly bracket arguments.
2013-10-02 17:34:09 +02:00
// - Prevents strings fixed at translation time to be fixed again
fmt = fmt.replace("''", "'");
// - Replace ' with the escaped version ''
fmt = fmt.replace("'", "''");
return MessageFormat.format(fmt, args);
}
2013-10-02 17:34:09 +02:00
/**
* Does nothing.
2013-10-02 17:34:09 +02:00
* <p/>
* This method is an hack to extract words with gettext tool.
*/
protected static void unusedStrings() {
// These phrases are defined in the "platform.txt".
_("Arduino AVR Boards");
_("Arduino ARM (32-bits) Boards");
// This word is defined in the "boards.txt".
_("Processor");
}
}