1 3 package jodd.util; 4 5 import java.util.Locale ; 6 import java.util.ResourceBundle ; 7 8 public class LocaleUtil { 9 10 private static Locale lastDefaultLocale; 11 private static ResourceBundle localeElements; 13 public static final String LOCALE_ELEMENTS_BUNDLE_NAME = "sun.text.resources.LocaleElements"; 14 15 16 private static void checkBundles() { 17 Locale locale = Locale.getDefault(); 18 if (locale != lastDefaultLocale) { lastDefaultLocale = locale; 20 localeElements = ResourceBundle.getBundle(LOCALE_ELEMENTS_BUNDLE_NAME, lastDefaultLocale); 21 } 22 } 23 24 27 public static ResourceBundle getLocaleElementsBundle(Locale locale) { 28 return ResourceBundle.getBundle(LOCALE_ELEMENTS_BUNDLE_NAME, locale); 29 } 30 31 34 public static ResourceBundle getLocaleElementsBundle() { 35 checkBundles(); 36 return localeElements; 37 } 38 39 40 42 public static String [] getMonthNames() { 43 checkBundles(); 44 return (String []) localeElements.getObject("MonthNames"); 45 } 46 47 public static String [] getMonthNames(Locale locale) { 48 if (locale == lastDefaultLocale) { 49 return getMonthNames(); 50 } 51 return (String []) getLocaleElementsBundle(locale).getObject("MonthNames"); 52 } 53 54 public static String [] getMonthAbbreviations() { 55 checkBundles(); 56 return (String []) localeElements.getObject("MonthAbbreviations"); 57 } 58 59 public static String [] getMonthAbbreviations(Locale locale) { 60 if (locale == lastDefaultLocale) { 61 return getMonthAbbreviations(); 62 } 63 return (String []) getLocaleElementsBundle(locale).getObject("MonthAbbreviations"); 64 } 65 66 public static String [] getDayNames() { 67 checkBundles(); 68 return (String []) localeElements.getObject("DayNames"); 69 } 70 71 public static String [] getDayNames(Locale locale) { 72 if (locale == lastDefaultLocale) { 73 return getDayNames(); 74 } 75 return (String []) getLocaleElementsBundle(locale).getObject("DayNames"); 76 } 77 78 public static String [] getDayAbbreviations() { 79 checkBundles(); 80 return (String []) localeElements.getObject("DayAbbreviations"); 81 } 82 83 public static String [] getDayAbbreviations(Locale locale) { 84 if (locale == lastDefaultLocale) { 85 return getDayAbbreviations(); 86 } 87 return (String []) getLocaleElementsBundle(locale).getObject("DayAbbreviations"); 88 } 89 90 91 92 93 } 94 | Popular Tags |