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

Last change on this file since 1523 was 1169, checked in by stoecker, 15 years ago

removed usage of tab stops

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import java.text.MessageFormat;
5import java.util.Arrays;
6import java.util.Comparator;
7import java.util.Locale;
8import java.util.Vector;
9
10/**
11 * Internationalisation support.
12 *
13 * @author Immanuel.Scholz
14 */
15public class I18n {
16
17 /* Base name for translation data. Used for detecting available translations */
18 private static final String TR_BASE = "org.openstreetmap.josm.i18n.Translation_";
19
20 /**
21 * Set by MainApplication. Changes here later will probably mess up everything, because
22 * many strings are already loaded.
23 */
24 public static org.xnap.commons.i18n.I18n i18n;
25
26 public static final String tr(String text, Object... objects) {
27 if (i18n == null)
28 return MessageFormat.format(text, objects);
29 return i18n.tr(text, objects);
30 }
31
32 public static final String tr(String text) {
33 if (i18n == null)
34 return text;
35 return i18n.tr(text);
36 }
37
38 public static final String marktr(String text) {
39 return text;
40 }
41
42 public static final String trn(String text, String pluralText, long n, Object... objects) {
43 if (i18n == null)
44 return n == 1 ? tr(text, objects) : tr(pluralText, objects);
45 return i18n.trn(text, pluralText, n, objects);
46 }
47
48 public static final String trn(String text, String pluralText, long n) {
49 if (i18n == null)
50 return n == 1 ? tr(text) : tr(pluralText);
51 return i18n.trn(text, pluralText, n);
52 }
53
54 /**
55 * Get a list of all available JOSM Translations.
56 * @return an array of locale objects.
57 */
58 public static final Locale[] getAvailableTranslations() {
59 Vector<Locale> v = new Vector<Locale>();
60 Locale[] l = Locale.getAvailableLocales();
61 for (int i = 0; i < l.length; i++) {
62 String cn = TR_BASE + l[i];
63 try {
64 Class.forName(cn);
65 v.add(l[i]);
66 } catch (ClassNotFoundException e) {
67 }
68 }
69 l = new Locale[v.size()];
70 l = v.toArray(l);
71 Arrays.sort(l, new Comparator<Locale>() {
72 public int compare(Locale o1, Locale o2) {
73 return o1.toString().compareTo(o2.toString());
74 }
75 });
76 return l;
77 }
78}
Note: See TracBrowser for help on using the repository browser.