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

Last change on this file since 6248 was 6248, checked in by Don-vip, 11 years ago

Rework console output:

  • new log level "error"
  • Replace nearly all calls to system.out and system.err to Main.(error|warn|info|debug)
  • Remove some unnecessary debug output
  • Some messages are modified (removal of "Info", "Warning", "Error" from the message itself -> notable i18n impact but limited to console error messages not seen by the majority of users, so that's ok)
  • Property svn:eol-style set to native
File size: 26.8 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.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.jar.JarInputStream;
18import java.util.zip.ZipEntry;
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 {@link #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 private static URL getTranslationFile(String lang) {
311 return Main.class.getResource("/data/"+lang+".lang");
312 }
313
314 /**
315 * Get a list of all available JOSM Translations.
316 * @return an array of locale objects.
317 */
318 public static final Locale[] getAvailableTranslations() {
319 Collection<Locale> v = new ArrayList<Locale>(languages.size());
320 if(getTranslationFile("en") != null)
321 {
322 for (String loc : languages.keySet()) {
323 if(getTranslationFile(loc) != null) {
324 v.add(LanguageInfo.getLocale(loc));
325 }
326 }
327 }
328 v.add(Locale.ENGLISH);
329 Locale[] l = new Locale[v.size()];
330 l = v.toArray(l);
331 Arrays.sort(l, new Comparator<Locale>() {
332 @Override
333 public int compare(Locale o1, Locale o2) {
334 return o1.toString().compareTo(o2.toString());
335 }
336 });
337 return l;
338 }
339
340 public static boolean hasCode(String code)
341 {
342 return languages.containsKey(code);
343 }
344
345 public static void init()
346 {
347 //languages.put("ar", PluralMode.MODE_AR);
348 languages.put("bg", PluralMode.MODE_NOTONE);
349 languages.put("ca", PluralMode.MODE_NOTONE);
350 languages.put("cs", PluralMode.MODE_CS);
351 languages.put("da", PluralMode.MODE_NOTONE);
352 languages.put("de", PluralMode.MODE_NOTONE);
353 languages.put("el", PluralMode.MODE_NOTONE);
354 languages.put("en_AU", PluralMode.MODE_NOTONE);
355 languages.put("en_GB", PluralMode.MODE_NOTONE);
356 languages.put("es", PluralMode.MODE_NOTONE);
357 languages.put("et", PluralMode.MODE_NOTONE);
358 languages.put("eu", PluralMode.MODE_NOTONE);
359 languages.put("fi", PluralMode.MODE_NOTONE);
360 languages.put("fr", PluralMode.MODE_GREATERONE);
361 languages.put("gl", PluralMode.MODE_NOTONE);
362 //languages.put("he", PluralMode.MODE_NOTONE);
363 languages.put("hu", PluralMode.MODE_NOTONE);
364 languages.put("id", PluralMode.MODE_NONE);
365 //languages.put("is", PluralMode.MODE_NOTONE);
366 languages.put("it", PluralMode.MODE_NOTONE);
367 languages.put("ja", PluralMode.MODE_NONE);
368 languages.put("nb", PluralMode.MODE_NOTONE);
369 languages.put("nl", PluralMode.MODE_NOTONE);
370 languages.put("pl", PluralMode.MODE_PL);
371 languages.put("pt", PluralMode.MODE_NOTONE);
372 languages.put("pt_BR", PluralMode.MODE_GREATERONE);
373 //languages.put("ro", PluralMode.MODE_RO);
374 languages.put("ru", PluralMode.MODE_RU);
375 languages.put("sk", PluralMode.MODE_SK);
376 //languages.put("sl", PluralMode.MODE_SL);
377 languages.put("sv", PluralMode.MODE_NOTONE);
378 languages.put("tr", PluralMode.MODE_NONE);
379 languages.put("uk", PluralMode.MODE_RU);
380 languages.put("zh_CN", PluralMode.MODE_NONE);
381 languages.put("zh_TW", PluralMode.MODE_NONE);
382
383 /* try initial language settings, may be changed later again */
384 if(!load(Locale.getDefault().toString())) {
385 Locale.setDefault(Locale.ENGLISH);
386 }
387 }
388
389 public static void addTexts(File source)
390 {
391 if(loadedCode.equals("en"))
392 return;
393 FileInputStream fis = null;
394 JarInputStream jar = null;
395 FileInputStream fisTrans = null;
396 JarInputStream jarTrans = null;
397 String enfile = "data/en.lang";
398 String langfile = "data/"+loadedCode+".lang";
399 try
400 {
401 ZipEntry e;
402 fis = new FileInputStream(source);
403 jar = new JarInputStream(fis);
404 boolean found = false;
405 while(!found && (e = jar.getNextEntry()) != null)
406 {
407 String name = e.getName();
408 if(name.equals(enfile))
409 found = true;
410 }
411 if(found)
412 {
413 fisTrans = new FileInputStream(source);
414 jarTrans = new JarInputStream(fisTrans);
415 found = false;
416 while(!found && (e = jarTrans.getNextEntry()) != null)
417 {
418 String name = e.getName();
419 if(name.equals(langfile))
420 found = true;
421 }
422 if(found)
423 load(jar, jarTrans, true);
424 }
425 } catch(IOException e) {
426 // Ignore
427 } finally {
428 Utils.close(jar);
429 Utils.close(fis);
430 Utils.close(jarTrans);
431 Utils.close(fisTrans);
432 }
433 }
434
435 private static boolean load(String l)
436 {
437 if(l.equals("en") || l.equals("en_US"))
438 {
439 strings = null;
440 pstrings = null;
441 loadedCode = "en";
442 pluralMode = PluralMode.MODE_NOTONE;
443 return true;
444 }
445 URL en = getTranslationFile("en");
446 if(en == null)
447 return false;
448 URL tr = getTranslationFile(l);
449 if(tr == null || !languages.containsKey(l))
450 {
451 int i = l.indexOf('_');
452 if (i > 0) {
453 l = l.substring(0, i);
454 }
455 tr = getTranslationFile(l);
456 if(tr == null || !languages.containsKey(l))
457 return false;
458 }
459 InputStream enStream = null;
460 InputStream trStream = null;
461 try {
462 enStream = en.openStream();
463 trStream = tr.openStream();
464 if (load(enStream, trStream, false)) {
465 pluralMode = languages.get(l);
466 loadedCode = l;
467 return true;
468 }
469 } catch(IOException e) {
470 // Ignore exception
471 } finally {
472 Utils.close(trStream);
473 Utils.close(enStream);
474 }
475 return false;
476 }
477
478 private static boolean load(InputStream en, InputStream tr, boolean add)
479 {
480 HashMap<String, String> s;
481 HashMap<String, String[]> p;
482 if(add)
483 {
484 s = strings;
485 p = pstrings;
486 }
487 else
488 {
489 s = new HashMap<String, String>();
490 p = new HashMap<String, String[]>();
491 }
492 /* file format:
493 Files are always a group. English file and translated file must provide identical datasets.
494
495 for all single strings:
496 {
497 unsigned short (2 byte) stringlength
498 - length 0 indicates missing translation
499 - length 0xFFFE indicates translation equal to original, but otherwise is equal to length 0
500 string
501 }
502 unsigned short (2 byte) 0xFFFF (marks end of single strings)
503 for all multi strings:
504 {
505 unsigned char (1 byte) stringcount
506 - count 0 indicates missing translations
507 - count 0xFE indicates translations equal to original, but otherwise is equal to length 0
508 for stringcount
509 unsigned short (2 byte) stringlength
510 string
511 }
512 */
513 try
514 {
515 InputStream ens = new BufferedInputStream(en);
516 InputStream trs = new BufferedInputStream(tr);
517 byte[] enlen = new byte[2];
518 byte[] trlen = new byte[2];
519 boolean multimode = false;
520 byte[] str = new byte[4096];
521 for(;;)
522 {
523 if(multimode)
524 {
525 int ennum = ens.read();
526 int trnum = trs.read();
527 if(trnum == 0xFE) /* marks identical string, handle equally to non-translated */
528 trnum = 0;
529 if((ennum == -1 && trnum != -1) || (ennum != -1 && trnum == -1)) /* files do not match */
530 return false;
531 if(ennum == -1) {
532 break;
533 }
534 String[] enstrings = new String[ennum];
535 String[] trstrings = new String[trnum];
536 for(int i = 0; i < ennum; ++i)
537 {
538 int val = ens.read(enlen);
539 if(val != 2) /* file corrupt */
540 return false;
541 val = (enlen[0] < 0 ? 256+enlen[0]:enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);
542 if(val > str.length) {
543 str = new byte[val];
544 }
545 int rval = ens.read(str, 0, val);
546 if(rval != val) /* file corrupt */
547 return false;
548 enstrings[i] = new String(str, 0, val, "utf-8");
549 }
550 for(int i = 0; i < trnum; ++i)
551 {
552 int val = trs.read(trlen);
553 if(val != 2) /* file corrupt */
554 return false;
555 val = (trlen[0] < 0 ? 256+trlen[0]:trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);
556 if(val > str.length) {
557 str = new byte[val];
558 }
559 int rval = trs.read(str, 0, val);
560 if(rval != val) /* file corrupt */
561 return false;
562 trstrings[i] = new String(str, 0, val, "utf-8");
563 }
564 if(trnum > 0 && !p.containsKey(enstrings[0])) {
565 p.put(enstrings[0], trstrings);
566 }
567 }
568 else
569 {
570 int enval = ens.read(enlen);
571 int trval = trs.read(trlen);
572 if(enval != trval) /* files do not match */
573 return false;
574 if(enval == -1) {
575 break;
576 }
577 if(enval != 2) /* files corrupt */
578 return false;
579 enval = (enlen[0] < 0 ? 256+enlen[0]:enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);
580 trval = (trlen[0] < 0 ? 256+trlen[0]:trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);
581 if(trval == 0xFFFE) /* marks identical string, handle equally to non-translated */
582 trval = 0;
583 if(enval == 0xFFFF)
584 {
585 multimode = true;
586 if(trval != 0xFFFF) /* files do not match */
587 return false;
588 }
589 else
590 {
591 if(enval > str.length) {
592 str = new byte[enval];
593 }
594 if(trval > str.length) {
595 str = new byte[trval];
596 }
597 int val = ens.read(str, 0, enval);
598 if(val != enval) /* file corrupt */
599 return false;
600 String enstr = new String(str, 0, enval, "utf-8");
601 if(trval != 0)
602 {
603 val = trs.read(str, 0, trval);
604 if(val != trval) /* file corrupt */
605 return false;
606 String trstr = new String(str, 0, trval, "utf-8");
607 if(!s.containsKey(enstr))
608 s.put(enstr, trstr);
609 }
610 }
611 }
612 }
613 }
614 catch(IOException e)
615 {
616 return false;
617 }
618 if(!s.isEmpty())
619 {
620 strings = s;
621 pstrings = p;
622 return true;
623 }
624 return false;
625 }
626
627 /**
628 * Sets the default locale (see {@link Locale#setDefault(Locale)} to the local
629 * given by <code>localName</code>.
630 *
631 * Ignored if localeName is null. If the locale with name <code>localName</code>
632 * isn't found the default local is set to <tt>en</tt> (english).
633 *
634 * @param localeName the locale name. Ignored if null.
635 */
636 public static void set(String localeName){
637 if (localeName != null) {
638 Locale l = LanguageInfo.getLocale(localeName);
639 if (load(LanguageInfo.getJOSMLocaleCode(l))) {
640 Locale.setDefault(l);
641 } else {
642 if (!l.getLanguage().equals("en")) {
643 Main.info(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
644 l.getDisplayName(), Locale.getDefault().getDisplayName()));
645 } else {
646 strings = null;
647 pstrings = null;
648 }
649 }
650 }
651 }
652
653 /**
654 * Localizations for file chooser dialog.
655 * For some locales (e.g. de, fr) translations are provided
656 * by Java, but not for others (e.g. ru, uk).
657 */
658 public static void translateJavaInternalMessages() {
659 Locale l = Locale.getDefault();
660
661 JFileChooser.setDefaultLocale(l);
662 JColorChooser.setDefaultLocale(l);
663 for (String key : javaInternalMessageKeys) {
664 String us = UIManager.getString(key, Locale.US);
665 String loc = UIManager.getString(key, l);
666 // only provide custom translation if it is not already localized by Java
667 if (us != null && us.equals(loc)) {
668 UIManager.put(key, tr(us));
669 }
670 }
671 }
672
673 private static int pluralEval(long n)
674 {
675 switch(pluralMode)
676 {
677 case MODE_NOTONE: /* bg, da, de, el, en, en_GB, es, et, eu, fi, gl, is, it, iw_IL, nb, nl, sv */
678 return ((n != 1) ? 1 : 0);
679 case MODE_NONE: /* ja, tr, zh_CN, zh_TW */
680 return 0;
681 case MODE_GREATERONE: /* fr, pt_BR */
682 return ((n > 1) ? 1 : 0);
683 case MODE_CS:
684 return ((n == 1) ? 0 : (((n >= 2) && (n <= 4)) ? 1 : 2));
685 //case MODE_AR:
686 // return ((n == 0) ? 0 : ((n == 1) ? 1 : ((n == 2) ? 2 : ((((n % 100) >= 3)
687 // && ((n % 100) <= 10)) ? 3 : ((((n % 100) >= 11) && ((n % 100) <= 99)) ? 4 : 5)))));
688 case MODE_PL:
689 return ((n == 1) ? 0 : (((((n % 10) >= 2) && ((n % 10) <= 4))
690 && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2));
691 //case MODE_RO:
692 // return ((n == 1) ? 0 : ((((n % 100) > 19) || (((n % 100) == 0) && (n != 0))) ? 2 : 1));
693 case MODE_RU:
694 return ((((n % 10) == 1) && ((n % 100) != 11)) ? 0 : (((((n % 10) >= 2)
695 && ((n % 10) <= 4)) && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2));
696 case MODE_SK:
697 return ((n == 1) ? 1 : (((n >= 2) && (n <= 4)) ? 2 : 0));
698 //case MODE_SL:
699 // return (((n % 100) == 1) ? 1 : (((n % 100) == 2) ? 2 : ((((n % 100) == 3)
700 // || ((n % 100) == 4)) ? 3 : 0)));
701 }
702 return 0;
703 }
704
705 public static TranslationAdapter getTranslationAdapter() {
706 return new TranslationAdapter() {
707 @Override
708 public String tr(String text, Object... objects) {
709 return I18n.tr(text, objects);
710 }
711 };
712 }
713}
Note: See TracBrowser for help on using the repository browser.