LanguageControl.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.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. BufferedInputStream bis = null;
  51. try
  52. {
  53. bis = new BufferedInputStream(new FileInputStream(resourceName));
  54. bundle = new PropertyResourceBundle(bis);
  55. }
  56. finally
  57. {
  58. bis.close();
  59. }
  60. }
  61. return bundle;
  62. }
  63. }