1 |
package skrueger.i8n; |
package skrueger.i8n; |
2 |
|
|
3 |
|
import java.util.Locale; |
4 |
import java.util.Set; |
import java.util.Set; |
5 |
import java.util.TreeSet; |
import java.util.TreeSet; |
6 |
|
|
7 |
public class I8NUtil { |
public class I8NUtil { |
8 |
|
|
9 |
private static Set<String> languageCodes = new TreeSet<String>(); |
private static Set<String> languageCodes = new TreeSet<String>(); |
10 |
static { |
static { |
11 |
for (String code : java.util.Locale.getISOLanguages()) { |
for (Locale locale : java.util.Locale.getAvailableLocales()) { |
12 |
getLanguageCodes().add(code); |
getLanguageCodes().add(locale.getLanguage()); |
13 |
} |
} |
14 |
} |
// for (String code : java.util.Locale.getISOLanguages()) { |
15 |
// |
// getLanguageCodes().add(code); |
16 |
// /** |
// } |
17 |
// * @Returns an ImageIcon for a given ISO code or null. |
} |
18 |
// * @param code ISO Country Code |
|
19 |
// */ |
// |
20 |
// public static ImageIcon getFlagIcon(String code) { |
// /** |
21 |
// |
// * @Returns an ImageIcon for a given ISO code or null. |
22 |
// String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif"; |
// * @param code ISO Country Code |
23 |
// |
// */ |
24 |
// URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename); |
// public static ImageIcon getFlagIcon(String code) { |
25 |
// |
// |
26 |
// if (resourceURL != null) |
// String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif"; |
27 |
// return new ImageIcon( resourceURL); |
// |
28 |
// |
// URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename); |
29 |
// return new ImageIcon(); |
// |
30 |
// } |
// if (resourceURL != null) |
31 |
// |
// return new ImageIcon( resourceURL); |
32 |
// /** |
// |
33 |
// * @Returns an {@link ImageIcon} flag for the language setup as Translation language |
// return new ImageIcon(); |
34 |
// */ |
// } |
35 |
// public static ImageIcon getFlagIcon() { |
// |
36 |
// return getFlagIcon( Translation.getActiveLang() ); |
// /** |
37 |
// } |
// * @Returns an {@link ImageIcon} flag for the language setup as |
38 |
|
// Translation language |
39 |
|
// */ |
40 |
|
// public static ImageIcon getFlagIcon() { |
41 |
|
// return getFlagIcon( Translation.getActiveLang() ); |
42 |
|
// } |
43 |
|
|
44 |
/** |
/** |
45 |
* @author Stefan Alfons Krüger |
* @author Stefan Alfons Krüger |
46 |
* @param code |
* @param code |
50 |
return getLanguageCodes().contains(code); |
return getLanguageCodes().contains(code); |
51 |
} |
} |
52 |
|
|
|
|
|
53 |
/** |
/** |
54 |
* @return All language codes available in java.util.Locale.getISOLanguages() without duplicates. |
* @return All language codes available in |
55 |
|
* java.util.Locale.getISOLanguages() without duplicates. |
56 |
*/ |
*/ |
57 |
public static Set<String> getLanguageCodes() { |
public static Set<String> getLanguageCodes() { |
58 |
return languageCodes; |
return languageCodes; |
59 |
} |
} |
|
} |
|
60 |
|
|
61 |
|
/** |
62 |
|
* @param code |
63 |
|
* A two-letter language code. |
64 |
|
* @return <code>null</code> or one (of many possible) {@link Locale} that |
65 |
|
* uses this language. |
66 |
|
*/ |
67 |
|
public static Locale getLocaleFor(String code) { |
68 |
|
for (Locale l : Locale.getAvailableLocales()) { |
69 |
|
System.out.println(l.getLanguage()+" not = "+code); |
70 |
|
if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) { |
71 |
|
return l; |
72 |
|
} |
73 |
|
} |
74 |
|
return null; |
75 |
|
} |
76 |
|
} |