/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/i8n/I8NUtil.java
ViewVC logotype

Annotation of /branches/1.0-gt2-2.6/src/skrueger/i8n/I8NUtil.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (hide annotations)
Mon Apr 6 19:54:46 2009 UTC (15 years, 10 months ago) by alfonx
Original Path: trunk/src/skrueger/i8n/I8NUtil.java
File size: 1964 byte(s)
* Some corrections in I8N withthe ISO vs. Locale language codes
1 mojays 2 package skrueger.i8n;
2    
3 alfonx 39 import java.util.Locale;
4 alfonx 38 import java.util.Set;
5     import java.util.TreeSet;
6 mojays 2
7     public class I8NUtil {
8 alfonx 39
9 alfonx 38 private static Set<String> languageCodes = new TreeSet<String>();
10 mojays 2 static {
11 alfonx 39 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 mojays 2 /**
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 alfonx 38 return getLanguageCodes().contains(code);
51 mojays 2 }
52 alfonx 38
53     /**
54 alfonx 39 * @return All language codes available in
55     * java.util.Locale.getISOLanguages() without duplicates.
56 alfonx 38 */
57     public static Set<String> getLanguageCodes() {
58     return languageCodes;
59     }
60 alfonx 39
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 alfonx 41 // System.out.println(l.getLanguage()+" not = "+code);
70 alfonx 39 if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) {
71     return l;
72     }
73     }
74     return null;
75     }
76 mojays 2 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26