2
0

LocaleCodes.java 2.0 KB

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