LocaleCodes.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.tools.ngl;
  16. import java.util.HashMap;
  17. import java.util.Locale;
  18. import java.util.Map;
  19. /**
  20. *
  21. * @author mrTJO
  22. */
  23. public class LocaleCodes
  24. {
  25. Map<String, Locale> _locales = new HashMap<String, Locale>();
  26. public static LocaleCodes getInstance()
  27. {
  28. return SingletonHolder._instance;
  29. }
  30. private LocaleCodes()
  31. {
  32. loadCodes();
  33. }
  34. private void loadCodes()
  35. {
  36. for (Locale locale : Locale.getAvailableLocales())
  37. {
  38. String language = locale.getLanguage();
  39. //String script = locale.getScript();
  40. String country = locale.getCountry();
  41. String variant = locale.getVariant();
  42. if (language == "" && country == "" && variant == "")
  43. {
  44. continue;
  45. }
  46. StringBuilder lang = new StringBuilder();
  47. lang.append(language);
  48. if (country != "")
  49. lang.append(country);
  50. if (variant != "")
  51. lang.append('_'+variant);
  52. /*if (script != "")
  53. lang.append('_'+script);*/
  54. _locales.put(lang.toString(), locale);
  55. }
  56. }
  57. public Locale getLanguage(String lang)
  58. {
  59. return _locales.get(lang);
  60. }
  61. @SuppressWarnings("synthetic-access")
  62. private static class SingletonHolder
  63. {
  64. protected static final LocaleCodes _instance = new LocaleCodes();
  65. }
  66. }