35 public class LocaleNameProviderImpl extends LocaleNameProvider { |
35 public class LocaleNameProviderImpl extends LocaleNameProvider { |
36 static Locale[] avail = {Locale.JAPANESE, |
36 static Locale[] avail = {Locale.JAPANESE, |
37 Locale.JAPAN, |
37 Locale.JAPAN, |
38 new Locale("ja", "JP", "osaka"), |
38 new Locale("ja", "JP", "osaka"), |
39 new Locale("ja", "JP", "kyoto"), |
39 new Locale("ja", "JP", "kyoto"), |
40 new Locale("xx")}; |
40 new Locale("xx"), |
|
41 new Locale("yy", "YY", "YYYY")}; |
41 static List<Locale> availList = Arrays.asList(avail); |
42 static List<Locale> availList = Arrays.asList(avail); |
42 public Locale[] getAvailableLocales() { |
43 public Locale[] getAvailableLocales() { |
43 return avail; |
44 return avail; |
44 } |
45 } |
45 |
46 |
|
47 @Override |
46 public String getDisplayLanguage(String lang, Locale target) { |
48 public String getDisplayLanguage(String lang, Locale target) { |
|
49 return getDisplayString(lang, target); |
|
50 } |
|
51 |
|
52 @Override |
|
53 public String getDisplayCountry(String ctry, Locale target) { |
|
54 return getDisplayString(ctry, target); |
|
55 } |
|
56 |
|
57 @Override |
|
58 public String getDisplayVariant(String vrnt, Locale target) { |
|
59 return getDisplayString(vrnt, target); |
|
60 } |
|
61 |
|
62 private String getDisplayString(String key, Locale target) { |
47 if (!Utils.supportsLocale(availList, target)) { |
63 if (!Utils.supportsLocale(availList, target)) { |
48 throw new IllegalArgumentException("locale is not supported: "+target); |
64 throw new IllegalArgumentException("locale is not supported: "+target); |
49 } |
65 } |
50 |
66 |
51 String ret = null; |
67 String ret = null; |
52 |
68 |
|
69 if (target.getLanguage().equals("yy") && |
|
70 target.getCountry().equals("YY")) { |
|
71 String vrnt = target.getVariant(); |
|
72 if (vrnt.startsWith("YYYY")) { |
|
73 switch (key) { |
|
74 case "yy": |
|
75 case "YY": |
|
76 ret = "waiwai"; |
|
77 break; |
|
78 |
|
79 case "YYYY": |
|
80 if (vrnt.equals("YYYY_suffix")) { |
|
81 // for LocaleNameProviderTest.variantFallbackTest() |
|
82 throw new RuntimeException(vrnt); |
|
83 } else { |
|
84 ret = "waiwai"; |
|
85 } |
|
86 break; |
|
87 } |
|
88 } |
|
89 } else { |
|
90 // resource bundle based (allows fallback) |
53 try { |
91 try { |
54 ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target); |
92 ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target); |
55 ret = rb.getString(lang); |
93 ret = rb.getString(key); |
56 } catch (MissingResourceException mre) { |
94 } catch (MissingResourceException mre) { |
|
95 } |
57 } |
96 } |
58 |
97 |
59 return ret; |
98 return ret; |
60 } |
99 } |
61 |
|
62 public String getDisplayCountry(String ctry, Locale target) { |
|
63 if (!Utils.supportsLocale(availList, target)) { |
|
64 throw new IllegalArgumentException("locale is not supported: "+target); |
|
65 } |
100 } |
66 |
|
67 String ret = null; |
|
68 |
|
69 try { |
|
70 ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target); |
|
71 ret = rb.getString(ctry); |
|
72 } catch (MissingResourceException mre) { |
|
73 } |
|
74 |
|
75 return ret; |
|
76 } |
|
77 |
|
78 public String getDisplayVariant(String vrnt, Locale target) { |
|
79 if (!Utils.supportsLocale(availList, target)) { |
|
80 throw new IllegalArgumentException("locale is not supported: "+target); |
|
81 } |
|
82 |
|
83 String ret = null; |
|
84 |
|
85 try { |
|
86 ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target); |
|
87 ret = rb.getString(vrnt); |
|
88 } catch (MissingResourceException mre) { |
|
89 } |
|
90 |
|
91 return ret; |
|
92 } |
|
93 } |
|