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

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

fix #15662 - allow JOSM to open JAR URLs containing exclamation marks (workaround to https://bugs.openjdk.java.net/browse/JDK-4523159)

  • Property svn:eol-style set to native
File size: 25.5 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.IOException;
7import java.io.InputStream;
8import java.lang.annotation.Retention;
9import java.lang.annotation.RetentionPolicy;
10import java.net.URL;
11import java.nio.charset.StandardCharsets;
12import java.nio.file.Files;
13import java.nio.file.InvalidPathException;
14import java.text.MessageFormat;
15import java.util.ArrayList;
16import java.util.Arrays;
17import java.util.Collection;
18import java.util.Comparator;
19import java.util.HashMap;
20import java.util.Locale;
21import java.util.Map;
22import java.util.jar.JarInputStream;
23import java.util.zip.ZipEntry;
24
25/**
26 * Internationalisation support.
27 *
28 * @author Immanuel.Scholz
29 */
30public final class I18n {
31
32 /**
33 * This annotates strings which do not permit a clean i18n. This is mostly due to strings
34 * containing two nouns which can occur in singular or plural form.
35 * <br>
36 * No behaviour is associated with this annotation.
37 */
38 @Retention(RetentionPolicy.SOURCE)
39 public @interface QuirkyPluralString {
40 }
41
42 private I18n() {
43 // Hide default constructor for utils classes
44 }
45
46 /**
47 * Enumeration of possible plural modes. It allows us to identify and implement logical conditions of
48 * plural forms defined on <a href="https://help.launchpad.net/Translations/PluralForms">Launchpad</a>.
49 * See <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html">CLDR</a>
50 * for another complete list.
51 * @see #pluralEval
52 */
53 private enum PluralMode {
54 /** Plural = Not 1. This is the default for many languages, including English: 1 day, but 0 days or 2 days. */
55 MODE_NOTONE,
56 /** No plural. Mainly for Asian languages (Indonesian, Chinese, Japanese, ...) */
57 MODE_NONE,
58 /** Plural = Greater than 1. For some latin languages (French, Brazilian Portuguese) */
59 MODE_GREATERONE,
60 /* Special mode for
61 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ar">Arabic</a>.*
62 MODE_AR,*/
63 /** Special mode for
64 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#cs">Czech</a>. */
65 MODE_CS,
66 /** Special mode for
67 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#pl">Polish</a>. */
68 MODE_PL,
69 /* Special mode for
70 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ro">Romanian</a>.*
71 MODE_RO,*/
72 /** Special mode for
73 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#lt">Lithuanian</a>. */
74 MODE_LT,
75 /** Special mode for
76 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ru">Russian</a>. */
77 MODE_RU,
78 /** Special mode for
79 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#sk">Slovak</a>. */
80 MODE_SK,
81 /* Special mode for
82 * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#sl">Slovenian</a>.*
83 MODE_SL,*/
84 }
85
86 private static volatile PluralMode pluralMode = PluralMode.MODE_NOTONE; /* english default */
87 private static volatile String loadedCode = "en";
88
89
90 private static volatile Map<String, String> strings;
91 private static volatile Map<String, String[]> pstrings;
92 private static Map<String, PluralMode> languages = new HashMap<>();
93 static {
94 //languages.put("ar", PluralMode.MODE_AR);
95 languages.put("ast", PluralMode.MODE_NOTONE);
96 languages.put("bg", PluralMode.MODE_NOTONE);
97 languages.put("be", PluralMode.MODE_RU);
98 languages.put("ca", PluralMode.MODE_NOTONE);
99 languages.put("ca@valencia", PluralMode.MODE_NOTONE);
100 languages.put("cs", PluralMode.MODE_CS);
101 languages.put("da", PluralMode.MODE_NOTONE);
102 languages.put("de", PluralMode.MODE_NOTONE);
103 languages.put("el", PluralMode.MODE_NOTONE);
104 languages.put("en_AU", PluralMode.MODE_NOTONE);
105 languages.put("en_GB", PluralMode.MODE_NOTONE);
106 languages.put("es", PluralMode.MODE_NOTONE);
107 languages.put("et", PluralMode.MODE_NOTONE);
108 //languages.put("eu", PluralMode.MODE_NOTONE);
109 languages.put("fi", PluralMode.MODE_NOTONE);
110 languages.put("fr", PluralMode.MODE_GREATERONE);
111 languages.put("gl", PluralMode.MODE_NOTONE);
112 //languages.put("he", PluralMode.MODE_NOTONE);
113 languages.put("hu", PluralMode.MODE_NOTONE);
114 languages.put("id", PluralMode.MODE_NONE);
115 //languages.put("is", PluralMode.MODE_NOTONE);
116 languages.put("it", PluralMode.MODE_NOTONE);
117 languages.put("ja", PluralMode.MODE_NONE);
118 // fully supported only with Java 8 and later (needs CLDR)
119 languages.put("km", PluralMode.MODE_NONE);
120 languages.put("lt", PluralMode.MODE_LT);
121 languages.put("nb", PluralMode.MODE_NOTONE);
122 languages.put("nl", PluralMode.MODE_NOTONE);
123 languages.put("pl", PluralMode.MODE_PL);
124 languages.put("pt", PluralMode.MODE_NOTONE);
125 languages.put("pt_BR", PluralMode.MODE_GREATERONE);
126 //languages.put("ro", PluralMode.MODE_RO);
127 languages.put("ru", PluralMode.MODE_RU);
128 languages.put("sk", PluralMode.MODE_SK);
129 //languages.put("sl", PluralMode.MODE_SL);
130 languages.put("sv", PluralMode.MODE_NOTONE);
131 //languages.put("tr", PluralMode.MODE_NONE);
132 languages.put("uk", PluralMode.MODE_RU);
133 languages.put("vi", PluralMode.MODE_NONE);
134 languages.put("zh_CN", PluralMode.MODE_NONE);
135 languages.put("zh_TW", PluralMode.MODE_NONE);
136 }
137
138 /**
139 * Translates some text for the current locale.
140 * These strings are collected by a script that runs on the source code files.
141 * After translation, the localizations are distributed with the main program.
142 * <br>
143 * For example, <code>tr("JOSM''s default value is ''{0}''.", val)</code>.
144 * <br>
145 * Use {@link #trn} for distinguishing singular from plural text, i.e.,
146 * do not use {@code tr(size == 1 ? "singular" : "plural")} nor
147 * {@code size == 1 ? tr("singular") : tr("plural")}
148 *
149 * @param text the text to translate.
150 * Must be a string literal. (No constants or local vars.)
151 * Can be broken over multiple lines.
152 * An apostrophe ' must be quoted by another apostrophe.
153 * @param objects the parameters for the string.
154 * Mark occurrences in {@code text} with <code>{0}</code>, <code>{1}</code>, ...
155 * @return the translated string.
156 * @see #trn
157 * @see #trc
158 * @see #trnc
159 */
160 public static String tr(String text, Object... objects) {
161 if (text == null) return null;
162 return MessageFormat.format(gettext(text, null), objects);
163 }
164
165 /**
166 * Translates some text in a context for the current locale.
167 * There can be different translations for the same text within different contexts.
168 *
169 * @param context string that helps translators to find an appropriate
170 * translation for {@code text}.
171 * @param text the text to translate.
172 * @return the translated string.
173 * @see #tr
174 * @see #trn
175 * @see #trnc
176 */
177 public static String trc(String context, String text) {
178 if (context == null)
179 return tr(text);
180 if (text == null)
181 return null;
182 return MessageFormat.format(gettext(text, context), (Object) null);
183 }
184
185 public static String trcLazy(String context, String text) {
186 if (context == null)
187 return tr(text);
188 if (text == null)
189 return null;
190 return MessageFormat.format(gettextLazy(text, context), (Object) null);
191 }
192
193 /**
194 * Marks a string for translation (such that a script can harvest
195 * the translatable strings from the source files).
196 *
197 * For example, <code>
198 * String[] options = new String[] {marktr("up"), marktr("down")};
199 * lbl.setText(tr(options[0]));</code>
200 * @param text the string to be marked for translation.
201 * @return {@code text} unmodified.
202 */
203 public static String marktr(String text) {
204 return text;
205 }
206
207 public static String marktrc(String context, String text) {
208 return text;
209 }
210
211 /**
212 * Translates some text for the current locale and distinguishes between
213 * {@code singularText} and {@code pluralText} depending on {@code n}.
214 * <br>
215 * For instance, {@code trn("There was an error!", "There were errors!", i)} or
216 * <code>trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)</code>.
217 *
218 * @param singularText the singular text to translate.
219 * Must be a string literal. (No constants or local vars.)
220 * Can be broken over multiple lines.
221 * An apostrophe ' must be quoted by another apostrophe.
222 * @param pluralText the plural text to translate.
223 * Must be a string literal. (No constants or local vars.)
224 * Can be broken over multiple lines.
225 * An apostrophe ' must be quoted by another apostrophe.
226 * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
227 * @param objects the parameters for the string.
228 * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ...
229 * @return the translated string.
230 * @see #tr
231 * @see #trc
232 * @see #trnc
233 */
234 public static String trn(String singularText, String pluralText, long n, Object... objects) {
235 return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);
236 }
237
238 /**
239 * Translates some text in a context for the current locale and distinguishes between
240 * {@code singularText} and {@code pluralText} depending on {@code n}.
241 * There can be different translations for the same text within different contexts.
242 *
243 * @param context string that helps translators to find an appropriate
244 * translation for {@code text}.
245 * @param singularText the singular text to translate.
246 * Must be a string literal. (No constants or local vars.)
247 * Can be broken over multiple lines.
248 * An apostrophe ' must be quoted by another apostrophe.
249 * @param pluralText the plural text to translate.
250 * Must be a string literal. (No constants or local vars.)
251 * Can be broken over multiple lines.
252 * An apostrophe ' must be quoted by another apostrophe.
253 * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
254 * @param objects the parameters for the string.
255 * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ...
256 * @return the translated string.
257 * @see #tr
258 * @see #trc
259 * @see #trn
260 */
261 public static String trnc(String context, String singularText, String pluralText, long n, Object... objects) {
262 return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);
263 }
264
265 private static String gettext(String text, String ctx, boolean lazy) {
266 int i;
267 if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {
268 ctx = text.substring(2, i-1);
269 text = text.substring(i+1);
270 }
271 if (strings != null) {
272 String trans = strings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
273 if (trans != null)
274 return trans;
275 }
276 if (pstrings != null) {
277 i = pluralEval(1);
278 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
279 if (trans != null && trans.length > i)
280 return trans[i];
281 }
282 return lazy ? gettext(text, null) : text;
283 }
284
285 private static String gettext(String text, String ctx) {
286 return gettext(text, ctx, false);
287 }
288
289 /* try without context, when context try fails */
290 private static String gettextLazy(String text, String ctx) {
291 return gettext(text, ctx, true);
292 }
293
294 private static String gettextn(String text, String plural, String ctx, long num) {
295 int i;
296 if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {
297 ctx = text.substring(2, i-1);
298 text = text.substring(i+1);
299 }
300 if (pstrings != null) {
301 i = pluralEval(num);
302 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
303 if (trans != null && trans.length > i)
304 return trans[i];
305 }
306
307 return num == 1 ? text : plural;
308 }
309
310 public static String escape(String msg) {
311 if (msg == null) return null;
312 return msg.replace("\'", "\'\'").replace("{", "\'{\'").replace("}", "\'}\'");
313 }
314
315 private static URL getTranslationFile(String lang) {
316 return I18n.class.getResource("/data/"+lang.replace('@', '-')+".lang");
317 }
318
319 /**
320 * Get a list of all available JOSM Translations.
321 * @return an array of locale objects.
322 */
323 public static Locale[] getAvailableTranslations() {
324 Collection<Locale> v = new ArrayList<>(languages.size());
325 if (getTranslationFile("en") != null) {
326 for (String loc : languages.keySet()) {
327 if (getTranslationFile(loc) != null) {
328 v.add(LanguageInfo.getLocale(loc));
329 }
330 }
331 }
332 v.add(Locale.ENGLISH);
333 Locale[] l = new Locale[v.size()];
334 l = v.toArray(l);
335 Arrays.sort(l, Comparator.comparing(Locale::toString));
336 return l;
337 }
338
339 /**
340 * Determines if a language exists for the given code.
341 * @param code The language code
342 * @return {@code true} if a language exists, {@code false} otherwise
343 */
344 public static boolean hasCode(String code) {
345 return languages.containsKey(code);
346 }
347
348 static void setupJavaLocaleProviders() {
349 // Look up SPI providers first (for JosmDecimalFormatSymbolsProvider).
350 // Enable CLDR locale provider on Java 8 to get additional languages, such as Khmer.
351 // http://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr
352 // FIXME: This must be updated after we switch to Java 9.
353 // See https://docs.oracle.com/javase/9/docs/api/java/util/spi/LocaleServiceProvider.html
354 System.setProperty("java.locale.providers", "SPI,JRE,CLDR"); // Don't call Utils.updateSystemProperty to avoid spurious log at startup
355 }
356
357 /**
358 * I18n initialization.
359 */
360 public static void init() {
361 setupJavaLocaleProviders();
362
363 /* try initial language settings, may be changed later again */
364 if (!load(LanguageInfo.getJOSMLocaleCode())) {
365 Locale.setDefault(Locale.ENGLISH);
366 }
367 }
368
369 public static void addTexts(File source) {
370 if ("en".equals(loadedCode))
371 return;
372 final String enfile = "data/en.lang";
373 final String langfile = "data/"+loadedCode+".lang";
374 try (
375 InputStream fis = Files.newInputStream(source.toPath());
376 JarInputStream jar = new JarInputStream(fis)
377 ) {
378 ZipEntry e;
379 boolean found = false;
380 while (!found && (e = jar.getNextEntry()) != null) {
381 String name = e.getName();
382 if (enfile.equals(name))
383 found = true;
384 }
385 if (found) {
386 try (
387 InputStream fisTrans = Files.newInputStream(source.toPath());
388 JarInputStream jarTrans = new JarInputStream(fisTrans)
389 ) {
390 found = false;
391 while (!found && (e = jarTrans.getNextEntry()) != null) {
392 String name = e.getName();
393 if (name.equals(langfile))
394 found = true;
395 }
396 if (found)
397 load(jar, jarTrans, true);
398 }
399 }
400 } catch (IOException | InvalidPathException e) {
401 Logging.trace(e);
402 }
403 }
404
405 private static boolean load(String l) {
406 if ("en".equals(l) || "en_US".equals(l)) {
407 strings = null;
408 pstrings = null;
409 loadedCode = "en";
410 pluralMode = PluralMode.MODE_NOTONE;
411 return true;
412 }
413 URL en = getTranslationFile("en");
414 if (en == null)
415 return false;
416 URL tr = getTranslationFile(l);
417 if (tr == null || !languages.containsKey(l)) {
418 return false;
419 }
420 try (
421 InputStream enStream = Utils.openStream(en);
422 InputStream trStream = Utils.openStream(tr)
423 ) {
424 if (load(enStream, trStream, false)) {
425 pluralMode = languages.get(l);
426 loadedCode = l;
427 return true;
428 }
429 } catch (IOException e) {
430 // Ignore exception
431 Logging.trace(e);
432 }
433 return false;
434 }
435
436 private static boolean load(InputStream en, InputStream tr, boolean add) {
437 Map<String, String> s;
438 Map<String, String[]> p;
439 if (add) {
440 s = strings;
441 p = pstrings;
442 } else {
443 s = new HashMap<>();
444 p = new HashMap<>();
445 }
446 /* file format:
447 Files are always a group. English file and translated file must provide identical datasets.
448
449 for all single strings:
450 {
451 unsigned short (2 byte) stringlength
452 - length 0 indicates missing translation
453 - length 0xFFFE indicates translation equal to original, but otherwise is equal to length 0
454 string
455 }
456 unsigned short (2 byte) 0xFFFF (marks end of single strings)
457 for all multi strings:
458 {
459 unsigned char (1 byte) stringcount
460 - count 0 indicates missing translations
461 - count 0xFE indicates translations equal to original, but otherwise is equal to length 0
462 for stringcount
463 unsigned short (2 byte) stringlength
464 string
465 }
466 */
467 try {
468 InputStream ens = new BufferedInputStream(en);
469 InputStream trs = new BufferedInputStream(tr);
470 byte[] enlen = new byte[2];
471 byte[] trlen = new byte[2];
472 boolean multimode = false;
473 byte[] str = new byte[4096];
474 for (;;) {
475 if (multimode) {
476 int ennum = ens.read();
477 int trnum = trs.read();
478 if (trnum == 0xFE) /* marks identical string, handle equally to non-translated */
479 trnum = 0;
480 if ((ennum == -1 && trnum != -1) || (ennum != -1 && trnum == -1)) /* files do not match */
481 return false;
482 if (ennum == -1) {
483 break;
484 }
485 String[] enstrings = new String[ennum];
486 for (int i = 0; i < ennum; ++i) {
487 int val = ens.read(enlen);
488 if (val != 2) /* file corrupt */
489 return false;
490 val = (enlen[0] < 0 ? 256+enlen[0] : enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1] : enlen[1]);
491 if (val > str.length) {
492 str = new byte[val];
493 }
494 int rval = ens.read(str, 0, val);
495 if (rval != val) /* file corrupt */
496 return false;
497 enstrings[i] = new String(str, 0, val, StandardCharsets.UTF_8);
498 }
499 String[] trstrings = new String[trnum];
500 for (int i = 0; i < trnum; ++i) {
501 int val = trs.read(trlen);
502 if (val != 2) /* file corrupt */
503 return false;
504 val = (trlen[0] < 0 ? 256+trlen[0] : trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1] : trlen[1]);
505 if (val > str.length) {
506 str = new byte[val];
507 }
508 int rval = trs.read(str, 0, val);
509 if (rval != val) /* file corrupt */
510 return false;
511 trstrings[i] = new String(str, 0, val, StandardCharsets.UTF_8);
512 }
513 if (trnum > 0 && !p.containsKey(enstrings[0])) {
514 p.put(enstrings[0], trstrings);
515 }
516 } else {
517 int enval = ens.read(enlen);
518 int trval = trs.read(trlen);
519 if (enval != trval) /* files do not match */
520 return false;
521 if (enval == -1) {
522 break;
523 }
524 if (enval != 2) /* files corrupt */
525 return false;
526 enval = (enlen[0] < 0 ? 256+enlen[0] : enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1] : enlen[1]);
527 trval = (trlen[0] < 0 ? 256+trlen[0] : trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1] : trlen[1]);
528 if (trval == 0xFFFE) /* marks identical string, handle equally to non-translated */
529 trval = 0;
530 if (enval == 0xFFFF) {
531 multimode = true;
532 if (trval != 0xFFFF) /* files do not match */
533 return false;
534 } else {
535 if (enval > str.length) {
536 str = new byte[enval];
537 }
538 if (trval > str.length) {
539 str = new byte[trval];
540 }
541 int val = ens.read(str, 0, enval);
542 if (val != enval) /* file corrupt */
543 return false;
544 String enstr = new String(str, 0, enval, StandardCharsets.UTF_8);
545 if (trval != 0) {
546 val = trs.read(str, 0, trval);
547 if (val != trval) /* file corrupt */
548 return false;
549 String trstr = new String(str, 0, trval, StandardCharsets.UTF_8);
550 if (!s.containsKey(enstr))
551 s.put(enstr, trstr);
552 }
553 }
554 }
555 }
556 } catch (IOException e) {
557 Logging.trace(e);
558 return false;
559 }
560 if (!s.isEmpty()) {
561 strings = s;
562 pstrings = p;
563 return true;
564 }
565 return false;
566 }
567
568 /**
569 * Sets the default locale (see {@link Locale#setDefault(Locale)} to the local
570 * given by <code>localName</code>.
571 *
572 * Ignored if localeName is null. If the locale with name <code>localName</code>
573 * isn't found the default local is set to <tt>en</tt> (english).
574 *
575 * @param localeName the locale name. Ignored if null.
576 */
577 public static void set(String localeName) {
578 if (localeName != null) {
579 Locale l = LanguageInfo.getLocale(localeName);
580 if (load(LanguageInfo.getJOSMLocaleCode(l))) {
581 Locale.setDefault(l);
582 } else {
583 if (!"en".equals(l.getLanguage())) {
584 Logging.info(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
585 LanguageInfo.getDisplayName(l), LanguageInfo.getDisplayName(Locale.getDefault())));
586 } else {
587 strings = null;
588 pstrings = null;
589 }
590 }
591 }
592 }
593
594 private static int pluralEval(long n) {
595 switch(pluralMode) {
596 case MODE_NOTONE: /* bg, da, de, el, en, en_GB, es, et, eu, fi, gl, is, it, iw_IL, nb, nl, sv */
597 return (n != 1) ? 1 : 0;
598 case MODE_NONE: /* id, vi, ja, km, tr, zh_CN, zh_TW */
599 return 0;
600 case MODE_GREATERONE: /* fr, pt_BR */
601 return (n > 1) ? 1 : 0;
602 case MODE_CS:
603 return (n == 1) ? 0 : (((n >= 2) && (n <= 4)) ? 1 : 2);
604 //case MODE_AR:
605 // return ((n == 0) ? 0 : ((n == 1) ? 1 : ((n == 2) ? 2 : ((((n % 100) >= 3)
606 // && ((n % 100) <= 10)) ? 3 : ((((n % 100) >= 11) && ((n % 100) <= 99)) ? 4 : 5)))));
607 case MODE_PL:
608 return (n == 1) ? 0 : (((((n % 10) >= 2) && ((n % 10) <= 4))
609 && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2);
610 //case MODE_RO:
611 // return ((n == 1) ? 0 : ((((n % 100) > 19) || (((n % 100) == 0) && (n != 0))) ? 2 : 1));
612 case MODE_LT:
613 return ((n % 10) == 1) && ((n % 100) != 11) ? 0 : (((n % 10) >= 2)
614 && (((n % 100) < 10) || ((n % 100) >= 20)) ? 1 : 2);
615 case MODE_RU:
616 return (((n % 10) == 1) && ((n % 100) != 11)) ? 0 : (((((n % 10) >= 2)
617 && ((n % 10) <= 4)) && (((n % 100) < 10) || ((n % 100) >= 20))) ? 1 : 2);
618 case MODE_SK:
619 return (n == 1) ? 1 : (((n >= 2) && (n <= 4)) ? 2 : 0);
620 //case MODE_SL:
621 // return (((n % 100) == 1) ? 1 : (((n % 100) == 2) ? 2 : ((((n % 100) == 3)
622 // || ((n % 100) == 4)) ? 3 : 0)));
623 }
624 return 0;
625 }
626}
Note: See TracBrowser for help on using the repository browser.