source: josm/trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java@ 2610

Last change on this file since 2610 was 2512, checked in by stoecker, 14 years ago

i18n updated, fixed files to reduce problems when applying patches, fix #4017

File size: 2.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import java.util.Locale;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7public class LanguageInfo {
8
9 /**
10 * Replies the wiki language prefix for the given locale. The wiki language
11 * prefix has the form 'Xy:' where 'Xy' is a ISO 639 language code in title
12 * case.
13 *
14 * @param locale the locale
15 * @return the wiki language prefix
16 */
17 static public String getWikiLanguagePrefix(Locale locale) {
18 String code = getJOSMLocaleCode(locale);
19 if (code.length() == 2) {
20 if (code.equals("en")) return "";
21 } else if (code.matches("[^_]+_[^_]+")) {
22 code = code.substring(0,2);
23 } else {
24 System.err.println(tr("Warning: failed to derive wiki language prefix from JOSM locale code ''{0}''. Using default code ''en''.", code));
25 return "";
26 }
27 return code.substring(0,1).toUpperCase() + code.substring(1) + ":";
28 }
29
30 /**
31 * Replies the wiki language prefix for the current locale.
32 *
33 * @return the wiki language prefix
34 * @see Locale#getDefault()
35 * @see #getWikiLanguagePrefix(Locale)
36 */
37 static public String getWikiLanguagePrefix() {
38 return getWikiLanguagePrefix(Locale.getDefault());
39 }
40
41 /**
42 * Replies the JOSM locale code for the default locale.
43 *
44 * @return the JOSM locale code for the default locale
45 * @see #getJOSMLocaleCode(Locale)
46 */
47 static public String getJOSMLocaleCode() {
48 return getJOSMLocaleCode(Locale.getDefault());
49 }
50
51 /**
52 * Replies the local code used by JOSM for a given locale.
53 *
54 * In most cases JOSM uses the 2-character ISO 639 language code ({@see Locale#getLanguage()}
55 * to identify the locale of a localized resource, but in some cases it may use the
56 * programmatic name for locales, as replied by {@see Locale#toString()}.
57 *
58 * @param locale the locale. Replies "en" if null.
59 * @return the JOSM code for the given locale
60 */
61 static public String getJOSMLocaleCode(Locale locale) {
62 if (locale == null) return "en";
63 String full = locale.toString();
64 if (full.equals("iw_IL"))
65 return "he";
66 /* list of non-single codes supported by josm */
67 else if (full.equals("en_GB"))
68 return full;
69
70 return locale.getLanguage();
71 }
72
73 static public String getLanguageCodeXML()
74 {
75 return getJOSMLocaleCode()+".";
76 }
77 static public String getLanguageCodeManifest()
78 {
79 return getJOSMLocaleCode()+"_";
80 }
81}
Note: See TracBrowser for help on using the repository browser.