source: josm/trunk/src/org/openstreetmap/josm/tools/I18n.java@ 6906

Last change on this file since 6906 was 6830, checked in by Don-vip, 10 years ago

javadoc fixes for jdk8 compatibility

  • Property svn:eol-style set to native
File size: 26.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.io.BufferedInputStream;
5import java.io.File;
6import java.io.FileInputStream;
7import java.io.IOException;
8import java.io.InputStream;
9import java.net.URL;
10import java.text.MessageFormat;
11import java.util.ArrayList;
12import java.util.Arrays;
13import java.util.Collection;
14import java.util.Comparator;
15import java.util.HashMap;
16import java.util.Locale;
17import java.util.Map;
18import java.util.jar.JarInputStream;
19import java.util.zip.ZipEntry;
20
21import javax.swing.JColorChooser;
22import javax.swing.JFileChooser;
23import javax.swing.UIManager;
24
25import org.openstreetmap.gui.jmapviewer.FeatureAdapter.TranslationAdapter;
26import org.openstreetmap.josm.Main;
27
28/**
29 * Internationalisation support.
30 *
31 * @author Immanuel.Scholz
32 */
33public final class I18n {
34
35 private I18n() {
36 // Hide default constructor for utils classes
37 }
38
39 private enum PluralMode { MODE_NOTONE, MODE_NONE, MODE_GREATERONE,
40 MODE_CS/*, MODE_AR*/, MODE_PL/*, MODE_RO*/, MODE_RU, MODE_SK/*, MODE_SL*/}
41 private static PluralMode pluralMode = PluralMode.MODE_NOTONE; /* english default */
42 private static String loadedCode = "en";
43
44 /* Localization keys for file chooser (and color chooser). */
45 private static final String[] javaInternalMessageKeys = new String[] {
46 /* JFileChooser windows laf */
47 "FileChooser.detailsViewActionLabelText",
48 "FileChooser.detailsViewButtonAccessibleName",
49 "FileChooser.detailsViewButtonToolTipText",
50 "FileChooser.fileAttrHeaderText",
51 "FileChooser.fileDateHeaderText",
52 "FileChooser.fileNameHeaderText",
53 "FileChooser.fileNameLabelText",
54 "FileChooser.fileSizeHeaderText",
55 "FileChooser.fileTypeHeaderText",
56 "FileChooser.filesOfTypeLabelText",
57 "FileChooser.homeFolderAccessibleName",
58 "FileChooser.homeFolderToolTipText",
59 "FileChooser.listViewActionLabelText",
60 "FileChooser.listViewButtonAccessibleName",
61 "FileChooser.listViewButtonToolTipText",
62 "FileChooser.lookInLabelText",
63 "FileChooser.newFolderAccessibleName",
64 "FileChooser.newFolderActionLabelText",
65 "FileChooser.newFolderToolTipText",
66 "FileChooser.refreshActionLabelText",
67 "FileChooser.saveInLabelText",
68 "FileChooser.upFolderAccessibleName",
69 "FileChooser.upFolderToolTipText",
70 "FileChooser.viewMenuLabelText",
71
72 /* JFileChooser gtk laf */
73 "FileChooser.acceptAllFileFilterText",
74 "FileChooser.cancelButtonText",
75 "FileChooser.cancelButtonToolTipText",
76 "FileChooser.deleteFileButtonText",
77 "FileChooser.filesLabelText",
78 "FileChooser.filterLabelText",
79 "FileChooser.foldersLabelText",
80 "FileChooser.newFolderButtonText",
81 "FileChooser.newFolderDialogText",
82 "FileChooser.openButtonText",
83 "FileChooser.openButtonToolTipText",
84 "FileChooser.openDialogTitleText",
85 "FileChooser.pathLabelText",
86 "FileChooser.renameFileButtonText",
87 "FileChooser.renameFileDialogText",
88 "FileChooser.renameFileErrorText",
89 "FileChooser.renameFileErrorTitle",
90 "FileChooser.saveButtonText",
91 "FileChooser.saveButtonToolTipText",
92 "FileChooser.saveDialogTitleText",
93
94 /* JFileChooser motif laf */
95 //"FileChooser.cancelButtonText",
96 //"FileChooser.cancelButtonToolTipText",
97 "FileChooser.enterFileNameLabelText",
98 //"FileChooser.filesLabelText",
99 //"FileChooser.filterLabelText",
100 //"FileChooser.foldersLabelText",
101 "FileChooser.helpButtonText",
102 "FileChooser.helpButtonToolTipText",
103 //"FileChooser.openButtonText",
104 //"FileChooser.openButtonToolTipText",
105 //"FileChooser.openDialogTitleText",
106 //"FileChooser.pathLabelText",
107 //"FileChooser.saveButtonText",
108 //"FileChooser.saveButtonToolTipText",
109 //"FileChooser.saveDialogTitleText",
110 "FileChooser.updateButtonText",
111 "FileChooser.updateButtonToolTipText",
112
113 /* gtk color chooser */
114 "GTKColorChooserPanel.blueText",
115 "GTKColorChooserPanel.colorNameText",
116 "GTKColorChooserPanel.greenText",
117 "GTKColorChooserPanel.hueText",
118 "GTKColorChooserPanel.nameText",
119 "GTKColorChooserPanel.redText",
120 "GTKColorChooserPanel.saturationText",
121 "GTKColorChooserPanel.valueText",
122
123 /* JOptionPane */
124 "OptionPane.okButtonText",
125 "OptionPane.yesButtonText",
126 "OptionPane.noButtonText",
127 "OptionPane.cancelButtonText"
128 };
129 private static Map<String, String> strings = null;
130 private static Map<String, String[]> pstrings = null;
131 private static Map<String, PluralMode> languages = new HashMap<String, PluralMode>();
132
133 /**
134 * Translates some text for the current locale.
135 * These strings are collected by a script that runs on the source code files.
136 * After translation, the localizations are distributed with the main program.
137 * <br>
138 * For example, {@code tr("JOSM''s default value is ''{0}''.", val)}.
139 * <br>
140 * Use {@link #trn} for distinguishing singular from plural text, i.e.,
141 * do not use {@code tr(size == 1 ? "singular" : "plural")} nor
142 * {@code size == 1 ? tr("singular") : tr("plural")}
143 *
144 * @param text the text to translate.
145 * Must be a string literal. (No constants or local vars.)
146 * Can be broken over multiple lines.
147 * An apostrophe ' must be quoted by another apostrophe.
148 * @param objects the parameters for the string.
149 * Mark occurrences in {@code text} with {@code {0}}, {@code {1}}, ...
150 * @return the translated string.
151 * @see #trn
152 * @see #trc
153 * @see #trnc
154 */
155 public static final String tr(String text, Object... objects) {
156 if (text == null) return null;
157 return MessageFormat.format(gettext(text, null), objects);
158 }
159
160 /**
161 * Translates some text in a context for the current locale.
162 * There can be different translations for the same text within different contexts.
163 *
164 * @param context string that helps translators to find an appropriate
165 * translation for {@code text}.
166 * @param text the text to translate.
167 * @return the translated string.
168 * @see #tr
169 * @see #trn
170 * @see #trnc
171 */
172 public static final String trc(String context, String text) {
173 if (context == null)
174 return tr(text);
175 if (text == null)
176 return null;
177 return MessageFormat.format(gettext(text, context), (Object)null);
178 }
179
180 public static final String trc_lazy(String context, String text) {
181 if (context == null)
182 return tr(text);
183 if (text == null)
184 return null;
185 return MessageFormat.format(gettext_lazy(text, context), (Object)null);
186 }
187
188 /**
189 * Marks a string for translation (such that a script can harvest
190 * the translatable strings from the source files).
191 *
192 * For example, {@code
193 * String[] options = new String[] {marktr("up"), marktr("down")};
194 * lbl.setText(tr(options[0]));}
195 * @param text the string to be marked for translation.
196 * @return {@code text} unmodified.
197 */
198 public static final String marktr(String text) {
199 return text;
200 }
201
202 public static final String marktrc(String context, String text) {
203 return text;
204 }
205
206 /**
207 * Translates some text for the current locale and distinguishes between
208 * {@code singularText} and {@code pluralText} depending on {@code n}.
209 * <br>
210 * For instance, {@code trn("There was an error!", "There were errors!", i)} or
211 * {@code trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)}.
212 *
213 * @param singularText the singular text to translate.
214 * Must be a string literal. (No constants or local vars.)
215 * Can be broken over multiple lines.
216 * An apostrophe ' must be quoted by another apostrophe.
217 * @param pluralText the plural text to translate.
218 * Must be a string literal. (No constants or local vars.)
219 * Can be broken over multiple lines.
220 * An apostrophe ' must be quoted by another apostrophe.
221 * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
222 * @param objects the parameters for the string.
223 * Mark occurrences in {@code singularText} and {@code pluralText} with {@code {0}}, {@code {1}}, ...
224 * @return the translated string.
225 * @see #tr
226 * @see #trc
227 * @see #trnc
228 */
229 public static final String trn(String singularText, String pluralText, long n, Object... objects) {
230 return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);
231 }
232
233 /**
234 * Translates some text in a context for the current locale and distinguishes between
235 * {@code singularText} and {@code pluralText} depending on {@code n}.
236 * There can be different translations for the same text within different contexts.
237 *
238 * @param context string that helps translators to find an appropriate
239 * translation for {@code text}.
240 * @param singularText the singular text to translate.
241 * Must be a string literal. (No constants or local vars.)
242 * Can be broken over multiple lines.
243 * An apostrophe ' must be quoted by another apostrophe.
244 * @param pluralText the plural text to translate.
245 * Must be a string literal. (No constants or local vars.)
246 * Can be broken over multiple lines.
247 * An apostrophe ' must be quoted by another apostrophe.
248 * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
249 * @param objects the parameters for the string.
250 * Mark occurrences in {@code singularText} and {@code pluralText} with {@code {0}}, {@code {1}}, ...
251 * @return the translated string.
252 * @see #tr
253 * @see #trc
254 * @see #trn
255 */
256 public static final String trnc(String context, String singularText, String pluralText, long n, Object... objects) {
257 return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);
258 }
259
260 private static final String gettext(String text, String ctx, boolean lazy)
261 {
262 int i;
263 if(ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0)
264 {
265 ctx = text.substring(2,i-1);
266 text = text.substring(i+1);
267 }
268 if(strings != null)
269 {
270 String trans = strings.get(ctx == null ? text : "_:"+ctx+"\n"+text);
271 if(trans != null)
272 return trans;
273 }
274 if(pstrings != null) {
275 i = pluralEval(1);
276 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+"\n"+text);
277 if(trans != null && trans.length > i)
278 return trans[i];
279 }
280 return lazy ? gettext(text, null) : text;
281 }
282
283 private static final String gettext(String text, String ctx) {
284 return gettext(text, ctx, false);
285 }
286
287
288 /* try without context, when context try fails */
289 private static final String gettext_lazy(String text, String ctx) {
290 return gettext(text, ctx, true);
291 }
292
293 private static final String gettextn(String text, String plural, String ctx, long num)
294 {
295 int i;
296 if(ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0)
297 {
298 ctx = text.substring(2,i-1);
299 text = text.substring(i+1);
300 }
301 if(pstrings != null)
302 {
303 i = pluralEval(num);
304 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+"\n"+text);
305 if(trans != null && trans.length > i)
306 return trans[i];
307 }
308
309 return num == 1 ? text : plural;
310 }
311
312 public static String escape(String msg) {
313 if (msg == null) return null;
314 return msg.replace("\'", "\'\'").replace("{", "\'{\'").replace("}", "\'}\'");
315 }
316
317 private static URL getTranslationFile(String lang) {
318 return Main.class.getResource("/data/"+lang+".lang");
319 }
320
321 /**
322 * Get a list of all available JOSM Translations.
323 * @return an array of locale objects.
324 */
325 public static final Locale[] getAvailableTranslations() {
326 Collection<Locale> v = new ArrayList<Locale>(languages.size());
327 if(getTranslationFile("en") != null)
328 {
329 for (String loc : languages.keySet()) {
330 if(getTranslationFile(loc) != null) {
331 v.add(LanguageInfo.getLocale(loc));
332 }
333 }
334 }
335 v.add(Locale.ENGLISH);
336 Locale[] l = new Locale[v.size()];
337 l = v.toArray(l);
338 Arrays.sort(l, new Comparator<Locale>() {
339 @Override
340 public int compare(Locale o1, Locale o2) {
341 return o1.toString().compareTo(o2.toString());
342 }
343 });
344 return l;
345 }
346
347 public static boolean hasCode(String code)
348 {
349 return languages.containsKey(code);
350 }
351
352 public static void init()
353 {
354 //languages.put("ar", PluralMode.MODE_AR);
355 languages.put("bg", PluralMode.MODE_NOTONE);
356 languages.put("ca", PluralMode.MODE_NOTONE);
357 languages.put("cs", PluralMode.MODE_CS);
358 languages.put("da", PluralMode.MODE_NOTONE);
359 languages.put("de", PluralMode.MODE_NOTONE);
360 languages.put("el", PluralMode.MODE_NOTONE);
361 languages.put("en_AU", PluralMode.MODE_NOTONE);
362 languages.put("en_GB", PluralMode.MODE_NOTONE);
363 languages.put("es", PluralMode.MODE_NOTONE);
364 languages.put("et", PluralMode.MODE_NOTONE);
365 languages.put("eu", PluralMode.MODE_NOTONE);
366 languages.put("fi", PluralMode.MODE_NOTONE);
367 languages.put("fr", PluralMode.MODE_GREATERONE);
368 languages.put("gl", PluralMode.MODE_NOTONE);
369 //languages.put("he", PluralMode.MODE_NOTONE);
370 languages.put("hu", PluralMode.MODE_NOTONE);
371 languages.put("id", PluralMode.MODE_NONE);
372 //languages.put("is", PluralMode.MODE_NOTONE);
373 languages.put("it", PluralMode.MODE_NOTONE);
374 languages.put("ja", PluralMode.MODE_NONE);
375 languages.put("nb", PluralMode.MODE_NOTONE);
376 languages.put("nl", PluralMode.MODE_NOTONE);
377 languages.put("pl", PluralMode.MODE_PL);
378 languages.put("pt", PluralMode.MODE_NOTONE);
379 languages.put("pt_BR", PluralMode.MODE_GREATERONE);
380 //languages.put("ro", PluralMode.MODE_RO);
381 languages.put("ru", PluralMode.MODE_RU);
382 languages.put("sk", PluralMode.MODE_SK);
383 //languages.put("sl", PluralMode.MODE_SL);
384 languages.put("sv", PluralMode.MODE_NOTONE);
385 languages.put("tr", PluralMode.MODE_NONE);
386 languages.put("uk", PluralMode.MODE_RU);
387 languages.put("zh_CN", PluralMode.MODE_NONE);
388 languages.put("zh_TW", PluralMode.MODE_NONE);
389
390 /* try initial language settings, may be changed later again */
391 if(!load(Locale.getDefault().toString())) {
392 Locale.setDefault(Locale.ENGLISH);
393 }
394 }
395
396 public static void addTexts(File source)
397 {
398 if(loadedCode.equals("en"))
399 return;
400 FileInputStream fis = null;
401 JarInputStream jar = null;
402 FileInputStream fisTrans = null;
403 JarInputStream jarTrans = null;
404 String enfile = "data/en.lang";
405 String langfile = "data/"+loadedCode+".lang";
406 try
407 {
408 ZipEntry e;
409 fis = new FileInputStream(source);
410 jar = new JarInputStream(fis);
411 boolean found = false;
412 while(!found && (e = jar.getNextEntry()) != null)
413 {
414 String name = e.getName();
415 if(name.equals(enfile))
416 found = true;
417 }
418 if(found)
419 {
420 fisTrans = new FileInputStream(source);
421 jarTrans = new JarInputStream(fisTrans);
422 found = false;
423 while(!found && (e = jarTrans.getNextEntry()) != null)
424 {
425 String name = e.getName();
426 if(name.equals(langfile))
427 found = true;
428 }
429 if(found)
430 load(jar, jarTrans, true);
431 }
432 } catch(IOException e) {
433 // Ignore
434 } finally {
435 Utils.close(jar);
436 Utils.close(fis);
437 Utils.close(jarTrans);
438 Utils.close(fisTrans);
439 }
440 }
441
442 private static boolean load(String l)
443 {
444 if(l.equals("en") || l.equals("en_US"))
445 {
446 strings = null;
447 pstrings = null;
448 loadedCode = "en";
449 pluralMode = PluralMode.MODE_NOTONE;
450 return true;
451 }
452 URL en = getTranslationFile("en");
453 if(en == null)
454 return false;
455 URL tr = getTranslationFile(l);
456 if(tr == null || !languages.containsKey(l))
457 {
458 int i = l.indexOf('_');
459 if (i > 0) {
460 l = l.substring(0, i);
461 }
462 tr = getTranslationFile(l);
463 if(tr == null || !languages.containsKey(l))
464 return false;
465 }
466 InputStream enStream = null;
467 InputStream trStream = null;
468 try {
469 enStream = en.openStream();
470 trStream = tr.openStream();
471 if (load(enStream, trStream, false)) {
472 pluralMode = languages.get(l);
473 loadedCode = l;
474 return true;
475 }
476 } catch(IOException e) {
477 // Ignore exception
478 } finally {
479 Utils.close(trStream);
480 Utils.close(enStream);
481 }
482 return false;
483 }
484
485 private static boolean load(InputStream en, InputStream tr, boolean add) {
486 Map<String, String> s;
487 Map<String, String[]> p;
488 if (add) {
489 s = strings;
490 p = pstrings;
491 } else {
492 s = new HashMap<String, String>();
493 p = new HashMap<String, String[]>();
494 }
495 /* file format:
496 Files are always a group. English file and translated file must provide identical datasets.
497
498 for all single strings:
499 {
500 unsigned short (2 byte) stringlength
501 - length 0 indicates missing translation
502 - length 0xFFFE indicates translation equal to original, but otherwise is equal to length 0
503 string
504 }
505 unsigned short (2 byte) 0xFFFF (marks end of single strings)
506 for all multi strings:
507 {
508 unsigned char (1 byte) stringcount
509 - count 0 indicates missing translations
510 - count 0xFE indicates translations equal to original, but otherwise is equal to length 0
511 for stringcount
512 unsigned short (2 byte) stringlength
513 string
514 }
515 */
516 try
517 {
518 InputStream ens = new BufferedInputStream(en);
519 InputStream trs = new BufferedInputStream(tr);
520 byte[] enlen = new byte[2];
521 byte[] trlen = new byte[2];
522 boolean multimode = false;
523 byte[] str = new byte[4096];
524 for(;;)
525 {
526 if(multimode)
527 {
528 int ennum = ens.read();
529 int trnum = trs.read();
530 if(trnum == 0xFE) /* marks identical string, handle equally to non-translated */
531 trnum = 0;
532 if((ennum == -1 && trnum != -1) || (ennum != -1 && trnum == -1)) /* files do not match */
533 return false;
534 if(ennum == -1) {
535 break;
536 }
537 String[] enstrings = new String[ennum];
538 String[] trstrings = new String[trnum];
539 for(int i = 0; i < ennum; ++i)
540 {
541 int val = ens.read(enlen);
542 if(val != 2) /* file corrupt */
543 return false;
544 val = (enlen[0] < 0 ? 256+enlen[0]:enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);
545 if(val > str.length) {
546 str = new byte[val];
547 }
548 int rval = ens.read(str, 0, val);
549 if(rval != val) /* file corrupt */
550 return false;
551 enstrings[i] = new String(str, 0, val, Utils.UTF_8);
552 }
553 for(int i = 0; i < trnum; ++i)
554 {
555 int val = trs.read(trlen);
556 if(val != 2) /* file corrupt */
557 return false;
558 val = (trlen[0] < 0 ? 256+trlen[0]:trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);
559 if(val > str.length) {
560 str = new byte[val];
561 }
562 int rval = trs.read(str, 0, val);
563 if(rval != val) /* file corrupt */
564 return false;
565 trstrings[i] = new String(str, 0, val, Utils.UTF_8);
566 }
567 if(trnum > 0 && !p.containsKey(enstrings[0])) {
568 p.put(enstrings[0], trstrings);
569 }
570 }
571 else
572 {
573 int enval = ens.read(enlen);
574 int trval = trs.read(trlen);
575 if(enval != trval) /* files do not match */
576 return false;
577 if(enval == -1) {
578 break;
579 }
580 if(enval != 2) /* files corrupt */
581 return false;
582 enval = (enlen[0] < 0 ? 256+enlen[0]:enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);
583 trval = (trlen[0] < 0 ? 256+trlen[0]:trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);
584 if(trval == 0xFFFE) /* marks identical string, handle equally to non-translated */
585 trval = 0;
586 if(enval == 0xFFFF)
587 {
588 multimode = true;
589 if(trval != 0xFFFF) /* files do not match */
590 return false;
591 }
592 else
593 {
594 if(enval > str.length) {
595 str = new byte[enval];
596 }
597 if(trval > str.length) {
598 str = new byte[trval];
599 }
600 int val = ens.read(str, 0, enval);
601 if(val != enval) /* file corrupt */
602 return false;
603 String enstr = new String(str, 0, enval, Utils.UTF_8);
604 if(trval != 0)
605 {
606 val = trs.read(str, 0, trval);
607 if(val != trval) /* file corrupt */
608 return false;
609 String trstr = new String(str, 0, trval, Utils.UTF_8);
610 if(!s.containsKey(enstr))
611 s.put(enstr, trstr);
612 }
613 }
614 }
615 }
616 }
617 catch(IOException e)
618 {
619 return false;
620 }
621 if(!s.isEmpty())
622 {
623 strings = s;
624 pstrings = p;
625 return true;
626 }
627 return false;
628 }
629
630 /**
631 * Sets the default locale (see {@link Locale#setDefault(Locale)} to the local
632 * given by <code>localName</code>.
633 *
634 * Ignored if localeName is null. If the locale with name <code>localName</code>
635 * isn't found the default local is set to <tt>en</tt> (english).
636 *
637 * @param localeName the locale name. Ignored if null.
638 */
639 public static void set(String localeName){
640 if (localeName != null) {
641 Locale l = LanguageInfo.getLocale(localeName);
642 if (load(LanguageInfo.getJOSMLocaleCode(l))) {
643 Locale.setDefault(l);
644 } else {
645 if (!l.getLanguage().equals("en")) {
646 Main.info(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
647 l.getDisplayName(), Locale.getDefault().getDisplayName()));
648 } else {
649 strings = null;
650 pstrings = null;
651 }
652 }
653 }
654 }
655
656 /**
657 * Localizations for file chooser dialog.
658 * For some locales (e.g. de, fr) translations are provided
659 * by Java, but not for others (e.g. ru, uk).
660 */
661 public static void translateJavaInternalMessages() {
662 Locale l = Locale.getDefault();
663
664 JFileChooser.setDefaultLocale(l);
665 JColorChooser.setDefaultLocale(l);
666 for (String key : javaInternalMessageKeys) {
667 String us = UIManager.getString(key, Locale.US);
668 String loc = UIManager.getString(key, l);
669 // only provide custom translation if it is not already localized by Java
670 if (us != null && us.equals(loc)) {
671 UIManager.put(key, tr(us));
672 }
673 }
674 }
675
676 private static int pluralEval(long n)
677 {
678 switch(pluralMode)
679 {
680 case MODE_NOTONE: /* bg, da, de, el, en, en_GB, es, et, eu, fi, gl, is, it, iw_IL, nb, nl, sv */
681 return ((n != 1) ? 1 : 0);
682 case MODE_NONE: /* ja, tr, zh_CN, zh_TW */
683 return 0;
684 case MODE_GREATERONE: /* fr, pt_BR */
685 return ((n > 1) ? 1 : 0);
686 case MODE_CS:
687 return ((n == 1) ? 0 : (((n >= 2) && (n <= 4)) ? 1 : 2));
688 //case MODE_AR:
689 // return ((n == 0) ? 0 : ((n == 1) ? 1 : ((n == 2) ? 2 : ((((n % 100) >= 3)
690 // && ((n % 100) <= 10)) ? 3 : ((((n % 100) >= 11) && ((n % 100) <= 99)) ? 4 : 5)))));
691 case MODE_PL:
692 return ((n == 1) ? 0 : (((((n % 10) >= 2) && ((n % 10) <= 4))
693 && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2));
694 //case MODE_RO:
695 // return ((n == 1) ? 0 : ((((n % 100) > 19) || (((n % 100) == 0) && (n != 0))) ? 2 : 1));
696 case MODE_RU:
697 return ((((n % 10) == 1) && ((n % 100) != 11)) ? 0 : (((((n % 10) >= 2)
698 && ((n % 10) <= 4)) && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2));
699 case MODE_SK:
700 return ((n == 1) ? 1 : (((n >= 2) && (n <= 4)) ? 2 : 0));
701 //case MODE_SL:
702 // return (((n % 100) == 1) ? 1 : (((n % 100) == 2) ? 2 : ((((n % 100) == 3)
703 // || ((n % 100) == 4)) ? 3 : 0)));
704 }
705 return 0;
706 }
707
708 public static TranslationAdapter getTranslationAdapter() {
709 return new TranslationAdapter() {
710 @Override
711 public String tr(String text, Object... objects) {
712 return I18n.tr(text, objects);
713 }
714 };
715 }
716}
Note: See TracBrowser for help on using the repository browser.