| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package processing.app; |
| 15 |
|
| 16 |
import java.text.MessageFormat; |
| 17 |
import java.util.Locale; |
| 18 |
import java.util.MissingResourceException; |
| 19 |
import java.util.ResourceBundle; |
| 20 |
|
| 21 |
public class I18n { |
| 22 |
|
| 23 |
static { |
| 24 |
tr("Arduino"); |
| 25 |
tr("Partner"); |
| 26 |
tr("Recommended"); |
| 27 |
tr("Contributed"); |
| 28 |
tr("Retired"); |
| 29 |
|
| 30 |
tr("Display"); |
| 31 |
tr("Communication"); |
| 32 |
tr("Signal Input/Output"); |
| 33 |
tr("Sensors"); |
| 34 |
tr("Device Control"); |
| 35 |
tr("Timing"); |
| 36 |
tr("Data Storage"); |
| 37 |
tr("Data Processing"); |
| 38 |
tr("Other"); |
| 39 |
tr("Uncategorized"); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
private static ResourceBundle i18n; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static String PROMPT_YES; |
| 48 |
public static String PROMPT_NO; |
| 49 |
public static String PROMPT_CANCEL; |
| 50 |
public static String PROMPT_OK; |
| 51 |
public static String PROMPT_BROWSE; |
| 52 |
|
| 53 |
static protected void init(String language) throws MissingResourceException { |
| 54 |
String[] languageParts = language.split("_"); |
| 55 |
Locale locale = Locale.getDefault(); |
| 56 |
|
| 57 |
if (languageParts.length == 2) { |
| 58 |
locale = new Locale(languageParts[0], languageParts[1]); |
| 59 |
|
| 60 |
} else if (languageParts.length == 1 && !"".equals(languageParts[0])) { |
| 61 |
locale = new Locale(languageParts[0]); |
| 62 |
} |
| 63 |
|
| 64 |
Locale.setDefault(locale); |
| 65 |
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", Locale.getDefault()); |
| 66 |
PROMPT_YES = tr("Yes"); |
| 67 |
PROMPT_NO = tr("No"); |
| 68 |
PROMPT_CANCEL = tr("Cancel"); |
| 69 |
PROMPT_OK = tr("OK"); |
| 70 |
PROMPT_BROWSE = tr("Browse"); |
| 71 |
} |
| 72 |
|
| 73 |
public static String tr(String s) { |
| 74 |
String res; |
| 75 |
try { |
| 76 |
if (i18n == null) |
| 77 |
res = s; |
| 78 |
else |
| 79 |
res = i18n.getString(s); |
| 80 |
} catch (MissingResourceException e) { |
| 81 |
res = s; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
res = res.replace("%%", "%"); |
| 88 |
|
| 89 |
return res; |
| 90 |
} |
| 91 |
|
| 92 |
public static String format(String fmt, Object... args) { |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
fmt = fmt.replace("''", "'"); |
| 97 |
|
| 98 |
fmt = fmt.replace("'", "''"); |
| 99 |
|
| 100 |
return MessageFormat.format(fmt, args); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
protected static void unusedStrings() { |
| 109 |
|
| 110 |
tr("Processor"); |
| 111 |
} |
| 112 |
} |