> For the complete documentation index, see [llms.txt](https://avbravo-2.gitbook.io/jee7/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://avbravo-2.gitbook.io/jee7/capitulo-2-proyecto-web/capitulo-3-introduccion/capitulo-4.-controller/util.md).

# paquete util

Este paquete contendrá la clase para el soporte de idiomas, y el manejo del archivo properties.

![](/files/-Lc1WmtA6psmhSizz_TA)

clic derecho New-> New Package

![](/files/-Lc1WmtC5U5Ft3DFzmZ3)

## Crear el paquete idiomas

```
import java.io.Serializable;
import java.util.Locale;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @authoravbravo
 */
@Named
@SessionScoped
public class Idiomas implements Serializable {

    private static final long serialVersionUID = 1L;
    @Inject
    ResourcesFiles rf;
    private String locale = Locale.getDefault().getDisplayLanguage();

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

    public synchronized String getLocale() {
        return locale;
    }

    public synchronized String changeLanguage() {
        return "changed";
    }

    public Idiomas() {
    }

    public String englishAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        context.getViewRoot().setLocale(Locale.ENGLISH);
        this.locale = "en";
        rf.saveLocale();
        return null;
    }

    public String spanishAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        context.getViewRoot().setLocale(new Locale("es"));
        this.locale = "es";
        rf.saveLocale();
        return null;
    }




}
```

## Clase ResourcesFiles.java

Especificamos el paquete donde esta ubicado el archivo message

```
mrb = ResourceBundle.getBundle("com.javscaz.tallerjsd.properties.messages",
```

**Codigo completo**

```
@Named
@SessionScoped
public class ResourcesFiles implements Serializable {

    private static final long serialVersionUID = 1L;
    Locale currentLocale;

    ResourceBundle mrb; //for messages atributos


    public ResourcesFiles() {
    }

    @PostConstruct
    public void init() {
        saveLocale();
    }

    public void saveLocale() {
        currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

        mrb = ResourceBundle.getBundle("com.javscaz.tallerjsd.properties.messages",
                currentLocale);

    }

    public Locale getCurrentLocale() {
        return currentLocale;
    }

    public void setCurrentLocale(Locale currentLocale) {
        this.currentLocale = currentLocale;
    }

    public ResourceBundle getMrb() {
        return mrb;
    }

    public void setMrb(ResourceBundle mrb) {
        this.mrb = mrb;
    }


    /*
     *Devuelve el mensaje Mrb
     */

    public String getMensaje(String mensaje) {
        return mrb.getString(mensaje);
    }


}
```
