package de.ivu.elect.jee.faces;

import java.io.Serializable;
import java.util.Locale;

import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SessionScoped
public class UserLocaleStore implements Serializable {

  private static final Logger LOG = LoggerFactory.getLogger(UserLocaleStore.class);

  private Locale locale = null;

  public Locale getLocale() {
    if (locale == null) {
      try {
        locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
      } catch (Exception e){
        LOG.warn("Fehler beim Lesen des Locales: " +e.getMessage());
      }
    }

    if (locale == null) {
      locale = Locale.getDefault();  // fallback
    }

    return locale;
  }

  public void setLocale(Locale locale) {
    this.locale = locale;
  }
}
