content:  package com.github.adminfaces.template.i18n;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.net.URL;
  import java.net.URLConnection;
  import java.util.Enumeration;
  import java.util.Locale;
  import java.util.PropertyResourceBundle;
  import java.util.ResourceBundle;
  
  import jakarta.faces.context.FacesContext;
  
  /**
   * Adds support for UTF-8 based bundles for admin i18n messages
   * 
   * Taken from: https://stackoverflow.com/a/3646601/1260910
   *
   * @author rafael-pestano
   */
  public class AdminUTF8Bundle extends ResourceBundle {
  
      protected static final String BUNDLE_NAME = "admin";
      protected static final String BUNDLE_EXTENSION = "properties";
      protected static final String CHARSET = "UTF-8";
      protected static final Control UTF8_CONTROL = new UTF8Control();
  
      public AdminUTF8Bundle() {
          Locale locale = Locale.getDefault();
          if (FacesContext.getCurrentInstance() != null && FacesContext.getCurrentInstance().getViewRoot() != null) {
              locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
          }
          setParent(ResourceBundle.getBundle(BUNDLE_NAME, locale, UTF8_CONTROL));
      }
  
      @Override
      protected Object handleGetObject(String key) {
          return parent.getObject(key);
      }
  
      @Override
      public Enumeration<String> getKeys() {
          return parent.getKeys();
      }
  
      protected static class UTF8Control extends Control {
  
          public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
                  throws IllegalAccessException, InstantiationException, IOException {
              String bundleName = toBundleName(baseName, locale);
              String resourceName = toResourceName(bundleName, BUNDLE_EXTENSION);
              ResourceBundle bundle = null;
              InputStream stream = null;
              if (reload) {
                  URL url = loader.getResource(resourceName);
                  if (url != null) {
                      URLConnection connection = url.openConnection();
                      if (connection != null) {
                          connection.setUseCaches(false);
                          stream = connection.getInputStream();
                      }
                  }
              } else {
                  stream = loader.getResourceAsStream(resourceName);
              }
              if (stream != null) {
                  try {
                      bundle = new PropertyResourceBundle(new InputStreamReader(stream, CHARSET));
                  } finally {
                      stream.close();
                  }
              }
              return bundle;
          }
      }
  }
  