1 |
package skrueger.i8n; |
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Locale; |
5 |
|
6 |
/** |
7 |
*/ |
8 |
public class PropertiesLocale { |
9 |
|
10 |
/** |
11 |
* Language names => Translations |
12 |
*/ |
13 |
HashMap<String, String> displayLanguages = new HashMap<String, String>(); |
14 |
|
15 |
private final Locale locale; |
16 |
|
17 |
private final String nativeName; |
18 |
|
19 |
private final Locale parentLocale; |
20 |
|
21 |
public PropertiesLocale(Locale locale, Locale parentLocale, |
22 |
String nativeName) { |
23 |
if (I8NUtil.isValidISOLangCode(locale.getLanguage())) |
24 |
throw new IllegalArgumentException( |
25 |
locale.getLanguage() |
26 |
+ " can not be defined as a PropertiesLocale langauge, since it is an existing ISO language code."); |
27 |
|
28 |
this.parentLocale = parentLocale; |
29 |
this.locale = locale; |
30 |
this.nativeName = nativeName; |
31 |
} |
32 |
|
33 |
public String getDisplayLanguage(String langCode) { |
34 |
if (langCode == null || displayLanguages.containsKey(langCode)) |
35 |
return displayLanguages.get(langCode); |
36 |
else |
37 |
return nativeName; |
38 |
} |
39 |
|
40 |
public String getDisplayLanguage() { |
41 |
return getDisplayLanguage(Locale.getDefault().getLanguage()); |
42 |
} |
43 |
|
44 |
public void setDisplayLanguages(String langCode, String languageName) { |
45 |
displayLanguages.put(langCode, languageName); |
46 |
} |
47 |
|
48 |
public String getLanguage() { |
49 |
return locale.getLanguage(); |
50 |
} |
51 |
|
52 |
public String getCountry() { |
53 |
return locale.getCountry(); |
54 |
} |
55 |
|
56 |
public String getDisplayCountry() { |
57 |
return locale.getDisplayCountry(); |
58 |
} |
59 |
|
60 |
public Locale getParentLocale() { |
61 |
return parentLocale; |
62 |
} |
63 |
} |