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

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

see #8465 - global use of try-with-resources, according to

  • Property svn:eol-style set to native
File size: 26.6 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<>();
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<>(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 if ("en".equals(loadedCode))
398 return;
399 String enfile = "data/en.lang";
400 String langfile = "data/"+loadedCode+".lang";
401 try (
402 FileInputStream fis = new FileInputStream(source);
403 JarInputStream jar = new JarInputStream(fis)
404 ) {
405 ZipEntry e;
406 boolean found = false;
407 while (!found && (e = jar.getNextEntry()) != null) {
408 String name = e.getName();
409 if(name.equals(enfile))
410 found = true;
411 }
412 if (found) {
413 try (
414 FileInputStream fisTrans = new FileInputStream(source);
415 JarInputStream jarTrans = new JarInputStream(fisTrans)
416 ) {
417 found = false;
418 while(!found && (e = jarTrans.getNextEntry()) != null) {
419 String name = e.getName();
420 if (name.equals(langfile))
421 found = true;
422 }
423 if (found)
424 load(jar, jarTrans, true);
425 }
426 }
427 } catch (IOException e) {
428 // Ignore
429 }
430 }
431
432 private static boolean load(String l) {
433 if ("en".equals(l) || "en_US".equals(l)) {
434 strings = null;
435 pstrings = null;
436 loadedCode = "en";
437 pluralMode = PluralMode.MODE_NOTONE;
438 return true;
439 }
440 URL en = getTranslationFile("en");
441 if (en == null)
442 return false;
443 URL tr = getTranslationFile(l);
444 if (tr == null || !languages.containsKey(l)) {
445 int i = l.indexOf('_');
446 if (i > 0) {
447 l = l.substring(0, i);
448 }
449 tr = getTranslationFile(l);
450 if (tr == null || !languages.containsKey(l))
451 return false;
452 }
453 try (
454 InputStream enStream = en.openStream();
455 InputStream trStream = tr.openStream()
456 ) {
457 if (load(enStream, trStream, false)) {
458 pluralMode = languages.get(l);
459 loadedCode = l;
460 return true;
461 }
462 } catch (IOException e) {
463 // Ignore exception
464 }
465 return false;
466 }
467
468 private static boolean load(InputStream en, InputStream tr, boolean add) {
469 Map<String, String> s;
470 Map<String, String[]> p;
471 if (add) {
472 s = strings;
473 p = pstrings;
474 } else {
475 s = new HashMap<>();
476 p = new HashMap<>();
477 }
478 /* file format:
479 Files are always a group. English file and translated file must provide identical datasets.
480
481 for all single strings:
482 {
483 unsigned short (2 byte) stringlength
484 - length 0 indicates missing translation
485 - length 0xFFFE indicates translation equal to original, but otherwise is equal to length 0
486 string
487 }
488 unsigned short (2 byte) 0xFFFF (marks end of single strings)
489 for all multi strings:
490 {
491 unsigned char (1 byte) stringcount
492 - count 0 indicates missing translations
493 - count 0xFE indicates translations equal to original, but otherwise is equal to length 0
494 for stringcount
495 unsigned short (2 byte) stringlength
496 string
497 }
498 */
499 try
500 {
501 InputStream ens = new BufferedInputStream(en);
502 InputStream trs = new BufferedInputStream(tr);
503 byte[] enlen = new byte[2];
504 byte[] trlen = new byte[2];
505 boolean multimode = false;
506 byte[] str = new byte[4096];
507 for(;;)
508 {
509 if(multimode)
510 {
511 int ennum = ens.read();
512 int trnum = trs.read();
513 if(trnum == 0xFE) /* marks identical string, handle equally to non-translated */
514 trnum = 0;
515 if((ennum == -1 && trnum != -1) || (ennum != -1 && trnum == -1)) /* files do not match */
516 return false;
517 if(ennum == -1) {
518 break;
519 }
520 String[] enstrings = new String[ennum];
521 String[] trstrings = new String[trnum];
522 for(int i = 0; i < ennum; ++i)
523 {
524 int val = ens.read(enlen);
525 if(val != 2) /* file corrupt */
526 return false;
527 val = (enlen[0] < 0 ? 256+enlen[0]:enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);
528 if(val > str.length) {
529 str = new byte[val];
530 }
531 int rval = ens.read(str, 0, val);
532 if(rval != val) /* file corrupt */
533 return false;
534 enstrings[i] = new String(str, 0, val, Utils.UTF_8);
535 }
536 for(int i = 0; i < trnum; ++i)
537 {
538 int val = trs.read(trlen);
539 if(val != 2) /* file corrupt */
540 return false;
541 val = (trlen[0] < 0 ? 256+trlen[0]:trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);
542 if(val > str.length) {
543 str = new byte[val];
544 }
545 int rval = trs.read(str, 0, val);
546 if(rval != val) /* file corrupt */
547 return false;
548 trstrings[i] = new String(str, 0, val, Utils.UTF_8);
549 }
550 if(trnum > 0 && !p.containsKey(enstrings[0])) {
551 p.put(enstrings[0], trstrings);
552 }
553 }
554 else
555 {
556 int enval = ens.read(enlen);
557 int trval = trs.read(trlen);
558 if(enval != trval) /* files do not match */
559 return false;
560 if(enval == -1) {
561 break;
562 }
563 if(enval != 2) /* files corrupt */
564 return false;
565 enval = (enlen[0] < 0 ? 256+enlen[0]:enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);
566 trval = (trlen[0] < 0 ? 256+trlen[0]:trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);
567 if(trval == 0xFFFE) /* marks identical string, handle equally to non-translated */
568 trval = 0;
569 if(enval == 0xFFFF)
570 {
571 multimode = true;
572 if(trval != 0xFFFF) /* files do not match */
573 return false;
574 }
575 else
576 {
577 if(enval > str.length) {
578 str = new byte[enval];
579 }
580 if(trval > str.length) {
581 str = new byte[trval];
582 }
583 int val = ens.read(str, 0, enval);
584 if(val != enval) /* file corrupt */
585 return false;
586 String enstr = new String(str, 0, enval, Utils.UTF_8);
587 if(trval != 0)
588 {
589 val = trs.read(str, 0, trval);
590 if(val != trval) /* file corrupt */
591 return false;
592 String trstr = new String(str, 0, trval, Utils.UTF_8);
593 if(!s.containsKey(enstr))
594 s.put(enstr, trstr);
595 }
596 }
597 }
598 }
599 }
600 catch(IOException e)
601 {
602 return false;
603 }
604 if(!s.isEmpty())
605 {
606 strings = s;
607 pstrings = p;
608 return true;
609 }
610 return false;
611 }
612
613 /**
614 * Sets the default locale (see {@link Locale#setDefault(Locale)} to the local
615 * given by <code>localName</code>.
616 *
617 * Ignored if localeName is null. If the locale with name <code>localName</code>
618 * isn't found the default local is set to <tt>en</tt> (english).
619 *
620 * @param localeName the locale name. Ignored if null.
621 */
622 public static void set(String localeName){
623 if (localeName != null) {
624 Locale l = LanguageInfo.getLocale(localeName);
625 if (load(LanguageInfo.getJOSMLocaleCode(l))) {
626 Locale.setDefault(l);
627 } else {
628 if (!"en".equals(l.getLanguage())) {
629 Main.info(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
630 l.getDisplayName(), Locale.getDefault().getDisplayName()));
631 } else {
632 strings = null;
633 pstrings = null;
634 }
635 }
636 }
637 }
638
639 /**
640 * Localizations for file chooser dialog.
641 * For some locales (e.g. de, fr) translations are provided
642 * by Java, but not for others (e.g. ru, uk).
643 */
644 public static void translateJavaInternalMessages() {
645 Locale l = Locale.getDefault();
646
647 JFileChooser.setDefaultLocale(l);
648 JColorChooser.setDefaultLocale(l);
649 for (String key : javaInternalMessageKeys) {
650 String us = UIManager.getString(key, Locale.US);
651 String loc = UIManager.getString(key, l);
652 // only provide custom translation if it is not already localized by Java
653 if (us != null && us.equals(loc)) {
654 UIManager.put(key, tr(us));
655 }
656 }
657 }
658
659 private static int pluralEval(long n)
660 {
661 switch(pluralMode)
662 {
663 case MODE_NOTONE: /* bg, da, de, el, en, en_GB, es, et, eu, fi, gl, is, it, iw_IL, nb, nl, sv */
664 return ((n != 1) ? 1 : 0);
665 case MODE_NONE: /* ja, tr, zh_CN, zh_TW */
666 return 0;
667 case MODE_GREATERONE: /* fr, pt_BR */
668 return ((n > 1) ? 1 : 0);
669 case MODE_CS:
670 return ((n == 1) ? 0 : (((n >= 2) && (n <= 4)) ? 1 : 2));
671 //case MODE_AR:
672 // return ((n == 0) ? 0 : ((n == 1) ? 1 : ((n == 2) ? 2 : ((((n % 100) >= 3)
673 // && ((n % 100) <= 10)) ? 3 : ((((n % 100) >= 11) && ((n % 100) <= 99)) ? 4 : 5)))));
674 case MODE_PL:
675 return ((n == 1) ? 0 : (((((n % 10) >= 2) && ((n % 10) <= 4))
676 && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2));
677 //case MODE_RO:
678 // return ((n == 1) ? 0 : ((((n % 100) > 19) || (((n % 100) == 0) && (n != 0))) ? 2 : 1));
679 case MODE_RU:
680 return ((((n % 10) == 1) && ((n % 100) != 11)) ? 0 : (((((n % 10) >= 2)
681 && ((n % 10) <= 4)) && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2));
682 case MODE_SK:
683 return ((n == 1) ? 1 : (((n >= 2) && (n <= 4)) ? 2 : 0));
684 //case MODE_SL:
685 // return (((n % 100) == 1) ? 1 : (((n % 100) == 2) ? 2 : ((((n % 100) == 3)
686 // || ((n % 100) == 4)) ? 3 : 0)));
687 }
688 return 0;
689 }
690
691 public static TranslationAdapter getTranslationAdapter() {
692 return new TranslationAdapter() {
693 @Override
694 public String tr(String text, Object... objects) {
695 return I18n.tr(text, objects);
696 }
697 };
698 }
699}
Note: See TracBrowser for help on using the repository browser.