/[schmitzm]/trunk/src/skrueger/i8n/I8NUtil.java
ViewVC logotype

Contents of /trunk/src/skrueger/i8n/I8NUtil.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show annotations)
Mon Apr 6 19:14:55 2009 UTC (15 years, 10 months ago) by alfonx
File size: 1962 byte(s)
* Some corrections in I8N withthe ISO vs. Locale language codes
1 package skrueger.i8n;
2
3 import java.util.Locale;
4 import java.util.Set;
5 import java.util.TreeSet;
6
7 public class I8NUtil {
8
9 private static Set<String> languageCodes = new TreeSet<String>();
10 static {
11 for (Locale locale : java.util.Locale.getAvailableLocales()) {
12 getLanguageCodes().add(locale.getLanguage());
13 }
14 // for (String code : java.util.Locale.getISOLanguages()) {
15 // getLanguageCodes().add(code);
16 // }
17 }
18
19 //
20 // /**
21 // * @Returns an ImageIcon for a given ISO code or null.
22 // * @param code ISO Country Code
23 // */
24 // public static ImageIcon getFlagIcon(String code) {
25 //
26 // String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif";
27 //
28 // URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename);
29 //
30 // if (resourceURL != null)
31 // return new ImageIcon( resourceURL);
32 //
33 // return new ImageIcon();
34 // }
35 //
36 // /**
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
46 * @param code
47 * @return true if the code paramter is a valid ISO Language code
48 */
49 public static boolean isValidISOLangCode(String code) {
50 return getLanguageCodes().contains(code);
51 }
52
53 /**
54 * @return All language codes available in
55 * java.util.Locale.getISOLanguages() without duplicates.
56 */
57 public static Set<String> getLanguageCodes() {
58 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 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26