| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,21 +33,21 @@ | |||
| 33 | 33 | public class Language { | |
| 34 | 34 | // static private final String FILE = "processing.app.languages.PDE"; | |
| 35 | 35 | //static private final String LISTING = "processing/app/languages/languages.txt"; | |
| 36 | - | ||
| 36 | + | ||
| 37 | 37 | // Store the language information in a file separate from the preferences, | |
| 38 | 38 | // because preferences need the language on load time. | |
| 39 | 39 | static protected final String PREF_FILE = "language.txt"; | |
| 40 | 40 | static protected final File prefFile = Base.getSettingsFile(PREF_FILE); | |
| 41 | - | ||
| 41 | + | ||
| 42 | 42 | /** Single instance of this Language class */ | |
| 43 | 43 | static private volatile Language instance; | |
| 44 | - | ||
| 44 | + | ||
| 45 | 45 | /** The system language */ | |
| 46 | 46 | private String language; | |
| 47 | - | ||
| 47 | + | ||
| 48 | 48 | /** Available languages */ | |
| 49 | 49 | private HashMap<String, String> languages; | |
| 50 | - | ||
| 50 | + | ||
| 51 | 51 | //private ResourceBundle bundle; | |
| 52 | 52 | //private Settings bundle; | |
| 53 | 53 | private LanguageBundle bundle; | |
@@ -57,18 +57,18 @@ private Language() { | |||
| 57 | 57 | String systemLanguage = Locale.getDefault().getLanguage(); | |
| 58 | 58 | language = loadLanguage(); | |
| 59 | 59 | boolean writePrefs = false; | |
| 60 | - | ||
| 60 | + | ||
| 61 | 61 | if (language == null) { | |
| 62 | 62 | language = systemLanguage; | |
| 63 | 63 | writePrefs = true; | |
| 64 | 64 | } | |
| 65 | - | ||
| 65 | + | ||
| 66 | 66 | // Set available languages | |
| 67 | 67 | languages = new HashMap<String, String>(); | |
| 68 | 68 | for (String code : listSupported()) { | |
| 69 | 69 | languages.put(code, Locale.forLanguageTag(code).getDisplayLanguage(Locale.forLanguageTag(code))); | |
| 70 | 70 | } | |
| 71 | - | ||
| 71 | + | ||
| 72 | 72 | // Set default language | |
| 73 | 73 | if (!languages.containsKey(language)) { | |
| 74 | 74 | language = "en"; | |
@@ -87,8 +87,8 @@ private Language() { | |||
| 87 | 87 | e.printStackTrace(); | |
| 88 | 88 | } | |
| 89 | 89 | } | |
| 90 | - | ||
| 91 | - | ||
| 90 | + | ||
| 91 | + | ||
| 92 | 92 | static private String[] listSupported() { | |
| 93 | 93 | // List of languages in alphabetical order. (Add yours here.) | |
| 94 | 94 | // Also remember to add it to the corresponding build/build.xml rule. | |
@@ -99,7 +99,7 @@ static private String[] listSupported() { | |||
| 99 | 99 | "es", // Spanish | |
| 100 | 100 | "fr", // French, Français | |
| 101 | 101 | "ja", // Japanese | |
| 102 | - "ko", // Korean | ||
| 102 | + "ko", // Korean | ||
| 103 | 103 | "nl", // Dutch, Nederlands | |
| 104 | 104 | "pt", // Portuguese | |
| 105 | 105 | "tr", // Turkish | |
@@ -126,7 +126,7 @@ static private String[] listSupported() { | |||
| 126 | 126 | ||
| 127 | 127 | ||
| 128 | 128 | /** Read the saved language */ | |
| 129 | - static private String loadLanguage() { | ||
| 129 | + static private String loadLanguage() { | ||
| 130 | 130 | try { | |
| 131 | 131 | if (prefFile.exists()) { | |
| 132 | 132 | String language = PApplet.loadStrings(prefFile)[0]; | |
@@ -140,11 +140,11 @@ static private String loadLanguage() { | |||
| 140 | 140 | } | |
| 141 | 141 | return null; | |
| 142 | 142 | } | |
| 143 | - | ||
| 144 | - | ||
| 143 | + | ||
| 144 | + | ||
| 145 | 145 | /** | |
| 146 | - * Save the language directly to a settings file. This is 'save' and not | ||
| 147 | - * 'set' because a language change requires a restart of Processing. | ||
| 146 | + * Save the language directly to a settings file. This is 'save' and not | ||
| 147 | + * 'set' because a language change requires a restart of Processing. | ||
| 148 | 148 | */ | |
| 149 | 149 | static public void saveLanguage(String language) { | |
| 150 | 150 | try { | |
@@ -154,8 +154,8 @@ static public void saveLanguage(String language) { | |||
| 154 | 154 | } | |
| 155 | 155 | Base.getPlatform().saveLanguage(language); | |
| 156 | 156 | } | |
| 157 | - | ||
| 158 | - | ||
| 157 | + | ||
| 158 | + | ||
| 159 | 159 | /** Singleton constructor */ | |
| 160 | 160 | static public Language init() { | |
| 161 | 161 | if (instance == null) { | |
@@ -181,13 +181,13 @@ static public String text(String text) { | |||
| 181 | 181 | } | |
| 182 | 182 | } | |
| 183 | 183 | ||
| 184 | - | ||
| 184 | + | ||
| 185 | 185 | static public String interpolate(String text, Object... arguments) { | |
| 186 | 186 | // return String.format(init().bundle.getString(text), arguments); | |
| 187 | 187 | return String.format(init().bundle.getString(text), arguments); | |
| 188 | 188 | } | |
| 189 | 189 | ||
| 190 | - | ||
| 190 | + | ||
| 191 | 191 | static public String pluralize(String text, int count) { | |
| 192 | 192 | // ResourceBundle bundle = init().bundle; | |
| 193 | 193 | LanguageBundle bundle = init().bundle; | |
@@ -199,17 +199,17 @@ static public String pluralize(String text, int count) { | |||
| 199 | 199 | } | |
| 200 | 200 | return interpolate(String.format(fmt, "n"), count); | |
| 201 | 201 | } | |
| 202 | - | ||
| 202 | + | ||
| 203 | 203 | ||
| 204 | 204 | /** Get all available languages */ | |
| 205 | 205 | static public Map<String, String> getLanguages() { | |
| 206 | 206 | return init().languages; | |
| 207 | 207 | } | |
| 208 | 208 | ||
| 209 | 209 | ||
| 210 | - /** | ||
| 210 | + /** | ||
| 211 | 211 | * Get the current language. | |
| 212 | - * @return two digit ISO code (lowercase) | ||
| 212 | + * @return two digit ISO code (lowercase) | ||
| 213 | 213 | */ | |
| 214 | 214 | static public String getLanguage() { | |
| 215 | 215 | return init().language; | |
@@ -219,7 +219,7 @@ static public String getLanguage() { | |||
| 219 | 219 | // /** Set new language (called by Preferences) */ | |
| 220 | 220 | // static public void setLanguage(String language) { | |
| 221 | 221 | // this.language = language; | |
| 222 | - // | ||
| 222 | + // | ||
| 223 | 223 | // try { | |
| 224 | 224 | // File file = Base.getContentFile("lib/language.txt"); | |
| 225 | 225 | // Base.saveFile(language, file); | |
@@ -265,14 +265,14 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C | |||
| 265 | 265 | } | |
| 266 | 266 | } | |
| 267 | 267 | */ | |
| 268 | - | ||
| 269 | - | ||
| 268 | + | ||
| 269 | + | ||
| 270 | 270 | static class LanguageBundle { | |
| 271 | 271 | Map<String, String> table; | |
| 272 | - | ||
| 272 | + | ||
| 273 | 273 | LanguageBundle(String language) throws IOException { | |
| 274 | 274 | table = new HashMap<String, String>(); | |
| 275 | - | ||
| 275 | + | ||
| 276 | 276 | String baseFilename = "languages/PDE.properties"; | |
| 277 | 277 | String langFilename = "languages/PDE_" + language + ".properties"; | |
| 278 | 278 | ||
@@ -287,23 +287,38 @@ static class LanguageBundle { | |||
| 287 | 287 | if (userLangFile.exists()) { | |
| 288 | 288 | langFile = userLangFile; | |
| 289 | 289 | } | |
| 290 | - | ||
| 290 | + | ||
| 291 | 291 | read(baseFile); | |
| 292 | 292 | read(langFile); | |
| 293 | 293 | } | |
| 294 | - | ||
| 294 | + | ||
| 295 | 295 | void read(File additions) { | |
| 296 | 296 | String[] lines = PApplet.loadStrings(additions); | |
| 297 | - for (String line : lines) { | ||
| 297 | + //for (String line : lines) { | ||
| 298 | + for (int i = 0; i < lines.length; i++) { | ||
| 299 | + String line = lines[i]; | ||
| 298 | 300 | if ((line.length() == 0) || | |
| 299 | 301 | (line.charAt(0) == '#')) continue; | |
| 300 | 302 | ||
| 301 | - // this won't properly handle = signs being in the text | ||
| 303 | + // this won't properly handle = signs inside in the text | ||
| 302 | 304 | int equals = line.indexOf('='); | |
| 303 | 305 | if (equals != -1) { | |
| 304 | 306 | String key = line.substring(0, equals).trim(); | |
| 305 | 307 | String value = line.substring(equals + 1).trim(); | |
| 306 | - | ||
| 308 | + | ||
| 309 | + /* | ||
| 310 | + // Support for backslashes to continue lines... Nah. | ||
| 311 | + while (line.endsWith("\\")) { | ||
| 312 | + // remove the backslash from the previous | ||
| 313 | + value = value.substring(0, value.length() - 1); | ||
| 314 | + // get the next line | ||
| 315 | + line = lines[++i].trim(); | ||
| 316 | + // append the new line to the value (with a space) | ||
| 317 | + // This is imperfect since the prev may end <br> | ||
| 318 | + value += " " + line; | ||
| 319 | + } | ||
| 320 | + */ | ||
| 321 | + | ||
| 307 | 322 | // fix \n and \' | |
| 308 | 323 | value = value.replaceAll("\\\\n", "\n"); | |
| 309 | 324 | value = value.replaceAll("\\\\'", "'"); | |
@@ -312,11 +327,11 @@ void read(File additions) { | |||
| 312 | 327 | } | |
| 313 | 328 | } | |
| 314 | 329 | } | |
| 315 | - | ||
| 330 | + | ||
| 316 | 331 | String getString(String key) { | |
| 317 | 332 | return table.get(key); | |
| 318 | 333 | } | |
| 319 | - | ||
| 334 | + | ||
| 320 | 335 | boolean containsKey(String key) { | |
| 321 | 336 | return table.containsKey(key); | |
| 322 | 337 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments