- Timestamp:
- 2014-12-26T15:05:04+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/I18n.java
r7578 r7893 39 39 } 40 40 41 private enum PluralMode { MODE_NOTONE, MODE_NONE, MODE_GREATERONE, 41 private enum PluralMode { 42 MODE_NOTONE, MODE_NONE, MODE_GREATERONE, 42 43 MODE_CS/*, MODE_AR*/, MODE_PL/*, MODE_RO*/, MODE_RU, MODE_SK/*, MODE_SL*/} 43 44 private static PluralMode pluralMode = PluralMode.MODE_NOTONE; /* english default */ … … 138 139 * After translation, the localizations are distributed with the main program. 139 140 * <br> 140 * For example, {@code tr("JOSM''s default value is ''{0}''.", val)}.141 * For example, <code>tr("JOSM''s default value is ''{0}''.", val)</code>. 141 142 * <br> 142 143 * Use {@link #trn} for distinguishing singular from plural text, i.e., … … 149 150 * An apostrophe ' must be quoted by another apostrophe. 150 151 * @param objects the parameters for the string. 151 * Mark occurrences in {@code text} with {@code {0}}, {@code {1}}, ...152 * Mark occurrences in {@code text} with <code>{0}</code>, <code>{1}</code>, ... 152 153 * @return the translated string. 153 154 * @see #trn … … 192 193 * the translatable strings from the source files). 193 194 * 194 * For example, {@code195 * For example, <code> 195 196 * String[] options = new String[] {marktr("up"), marktr("down")}; 196 * lbl.setText(tr(options[0])); }197 * lbl.setText(tr(options[0]));</code> 197 198 * @param text the string to be marked for translation. 198 199 * @return {@code text} unmodified. … … 211 212 * <br> 212 213 * For instance, {@code trn("There was an error!", "There were errors!", i)} or 213 * {@code trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)}.214 * <code>trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)</code>. 214 215 * 215 216 * @param singularText the singular text to translate. … … 223 224 * @param n a number to determine whether {@code singularText} or {@code pluralText} is used. 224 225 * @param objects the parameters for the string. 225 * Mark occurrences in {@code singularText} and {@code pluralText} with {@code {0}}, {@code {1}}, ...226 * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ... 226 227 * @return the translated string. 227 228 * @see #tr … … 250 251 * @param n a number to determine whether {@code singularText} or {@code pluralText} is used. 251 252 * @param objects the parameters for the string. 252 * Mark occurrences in {@code singularText} and {@code pluralText} with {@code {0}}, {@code {1}}, ...253 * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ... 253 254 * @return the translated string. 254 255 * @see #tr … … 260 261 } 261 262 262 private static final String gettext(String text, String ctx, boolean lazy) 263 { 263 private static final String gettext(String text, String ctx, boolean lazy) { 264 264 int i; 265 if(ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) 266 { 265 if(ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) { 267 266 ctx = text.substring(2,i-1); 268 267 text = text.substring(i+1); 269 268 } 270 if(strings != null) 271 { 269 if(strings != null) { 272 270 String trans = strings.get(ctx == null ? text : "_:"+ctx+"\n"+text); 273 271 if(trans != null) … … 287 285 } 288 286 289 290 287 /* try without context, when context try fails */ 291 288 private static final String gettext_lazy(String text, String ctx) { … … 293 290 } 294 291 295 private static final String gettextn(String text, String plural, String ctx, long num) 296 { 292 private static final String gettextn(String text, String plural, String ctx, long num) { 297 293 int i; 298 if(ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) 299 { 294 if(ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) { 300 295 ctx = text.substring(2,i-1); 301 296 text = text.substring(i+1); 302 297 } 303 if(pstrings != null) 304 { 298 if(pstrings != null) { 305 299 i = pluralEval(num); 306 300 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+"\n"+text); … … 327 321 public static final Locale[] getAvailableTranslations() { 328 322 Collection<Locale> v = new ArrayList<>(languages.size()); 329 if(getTranslationFile("en") != null) 330 { 323 if(getTranslationFile("en") != null) { 331 324 for (String loc : languages.keySet()) { 332 325 if(getTranslationFile(loc) != null) { … … 347 340 } 348 341 349 public static boolean hasCode(String code) 350 { 342 /** 343 * Determines if a language exists for the given code. 344 * @param code The language code 345 * @return {@code true} if a language exists, {@code false} otherwise 346 */ 347 public static boolean hasCode(String code) { 351 348 return languages.containsKey(code); 352 349 } 353 350 354 public static void init() 355 { 351 /** 352 * I18n initialization. 353 */ 354 public static void init() { 356 355 //languages.put("ar", PluralMode.MODE_AR); 357 356 languages.put("bg", PluralMode.MODE_NOTONE); … … 499 498 } 500 499 */ 501 try 502 { 500 try { 503 501 InputStream ens = new BufferedInputStream(en); 504 502 InputStream trs = new BufferedInputStream(tr); … … 507 505 boolean multimode = false; 508 506 byte[] str = new byte[4096]; 509 for(;;) 510 { 511 if(multimode) 512 { 507 for(;;) { 508 if(multimode) { 513 509 int ennum = ens.read(); 514 510 int trnum = trs.read(); … … 522 518 String[] enstrings = new String[ennum]; 523 519 String[] trstrings = new String[trnum]; 524 for(int i = 0; i < ennum; ++i) 525 { 520 for(int i = 0; i < ennum; ++i) { 526 521 int val = ens.read(enlen); 527 522 if(val != 2) /* file corrupt */ … … 536 531 enstrings[i] = new String(str, 0, val, StandardCharsets.UTF_8); 537 532 } 538 for(int i = 0; i < trnum; ++i) 539 { 533 for(int i = 0; i < trnum; ++i) { 540 534 int val = trs.read(trlen); 541 535 if(val != 2) /* file corrupt */ … … 553 547 p.put(enstrings[0], trstrings); 554 548 } 555 } 556 else 557 { 549 } else { 558 550 int enval = ens.read(enlen); 559 551 int trval = trs.read(trlen); … … 569 561 if(trval == 0xFFFE) /* marks identical string, handle equally to non-translated */ 570 562 trval = 0; 571 if(enval == 0xFFFF) 572 { 563 if(enval == 0xFFFF) { 573 564 multimode = true; 574 565 if(trval != 0xFFFF) /* files do not match */ … … 596 587 } 597 588 } 598 } 599 catch (IOException e) { 589 } catch (IOException e) { 600 590 return false; 601 591 } … … 655 645 } 656 646 657 private static int pluralEval(long n) 658 { 659 switch(pluralMode) 660 { 647 private static int pluralEval(long n) { 648 switch(pluralMode) { 661 649 case MODE_NOTONE: /* bg, da, de, el, en, en_GB, es, et, eu, fi, gl, is, it, iw_IL, nb, nl, sv */ 662 650 return ((n != 1) ? 1 : 0);
Note:
See TracChangeset
for help on using the changeset viewer.