| 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 | // start using current locale but still allow using the dropdown list later |
| 43 | private static ResourceBundle i18n; |
| 44 | |
| 45 | // prompt text stuff |
| 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 | // both language and country |
| 57 | if (languageParts.length == 2) { |
| 58 | locale = new Locale(languageParts[0], languageParts[1]); |
| 59 | // just language |
| 60 | } else if (languageParts.length == 1 && !"".equals(languageParts[0])) { |
| 61 | locale = new Locale(languageParts[0]); |
| 62 | } |
| 63 | // there might be a null pointer exception ... most likely will never happen but the jvm gets mad |
| 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 |