LanguageControl.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.i18n;
  16. import java.io.BufferedInputStream;
  17. import java.io.FileInputStream;
  18. import java.io.IOException;
  19. import java.util.Locale;
  20. import java.util.PropertyResourceBundle;
  21. import java.util.ResourceBundle;
  22. import java.util.ResourceBundle.Control;
  23. /**
  24. *
  25. * @author KenM
  26. */
  27. public class LanguageControl extends Control
  28. {
  29. public static final String LANGUAGES_DIRECTORY = "../languages/";
  30. public static final LanguageControl INSTANCE = new LanguageControl();
  31. /**
  32. * prevent instancing, allows sub-classing
  33. */
  34. protected LanguageControl()
  35. {
  36. }
  37. @Override
  38. public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException
  39. {
  40. if (baseName == null || locale == null || format == null || loader == null)
  41. {
  42. throw new NullPointerException();
  43. }
  44. ResourceBundle bundle = null;
  45. if (format.equals("java.properties"))
  46. {
  47. format = "properties";
  48. String bundleName = toBundleName(baseName, locale);
  49. String resourceName = LANGUAGES_DIRECTORY + toResourceName(bundleName, format);
  50. try (FileInputStream fis = new FileInputStream(resourceName);
  51. BufferedInputStream bis = new BufferedInputStream(fis))
  52. {
  53. bundle = new PropertyResourceBundle(bis);
  54. }
  55. }
  56. return bundle;
  57. }
  58. }