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

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

see #8465 - use String switch/case where applicable

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