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

Last change on this file since 4549 was 4549, checked in by stoecker, 12 years ago

add 0xFE for multiple translated strings

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