package de.gurkenlabs.litiengine;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Logger;

public final class Resources {
  public static final String LOCALIZATION_RESOURCE_FOLDER = "localization/";
  public static final String DEFAULT_BUNDLE = "strings";
  private static final Logger log = Logger.getLogger(Resources.class.getName());
  static {
    Locale.setDefault(new Locale("en", "US"));
  }

  private Resources() {
  }

  public static String get(final String key) {
    if (key == null) {
      return null;
    }
    return get(DEFAULT_BUNDLE, key);
  }

  public static String get(final String bundleName, final String key) {
    if (key == bundleName) {
      return null;
    }
    try {
      final ResourceBundle defaultBundle = ResourceBundle.getBundle(LOCALIZATION_RESOURCE_FOLDER + bundleName, Game.getConfiguration().client().getLocale());
      return defaultBundle.getString(key);
    } catch (final MissingResourceException me) {
      final StringWriter sw = new StringWriter();
      me.printStackTrace(new PrintWriter(sw));
      final String stacktrace = sw.toString();
      log.severe(stacktrace);
    }

    return key;
  }
}

@@ -77,32 +77,77 @@
 o.StringWriter;%0A
+import java.io.UnsupportedEncodingException;%0A
 import java.util
@@ -437,172 +437,585 @@
 %0A  p
-rivate static final Logger log = Logger.getLogger(Resources.class.getName());%0A  static %7B%0A    Locale.setDefault(new Locale(%22en%22, %22US%22));%0A  %7D%0A%0A  private Resources() %7B
+ublic static final String ENCODING_ISO_8859_1 = %22ISO-8859-1%22;%0A  public static final String ENCODING_UTF_8 = %22UTF-8%22;%0A%0A  private static String encoding = ENCODING_ISO_8859_1;%0A  private static final Logger log = Logger.getLogger(Resources.class.getName());%0A  static %7B%0A    Locale.setDefault(new Locale(%22en%22, %22US%22));%0A  %7D%0A%0A  private Resources() %7B%0A  %7D%0A%0A  public static void setEncoding(String newEncoding) %7B%0A    if (newEncoding == null %7C%7C newEncoding.isEmpty()) %7B%0A      throw new IllegalArgumentException(%22The encoding must not be null or empty.%22);%0A    %7D%0A%0A    encoding = newEncoding;
 %0A  %7D
@@ -1447,28 +1447,37 @@
 ale());%0A
+%0A
       
-return
+String value =
  default
@@ -1498,16 +1498,136 @@
 ng(key);
+%0A%0A      return encoding.equals(ENCODING_ISO_8859_1) ? value : new String(value.getBytes(ENCODING_ISO_8859_1), encoding);
 %0A    %7D c
@@ -1663,16 +1663,47 @@
 ception 
+%7C UnsupportedEncodingException 
 me) %7B%0A  

Extend the string resource to support language files that are encoded with UTF-8.