I18n.java 834 Bytes
package fi.insomnia.bortal;

import java.util.ResourceBundle;

import javax.faces.application.Application;
import javax.faces.context.FacesContext;

/***
 * Access i18n localisations from Java code. Feel free to make up a better way.
 * Note! works only when invoked from inside Faces context...
 * 
 * @author jkj
 * 
 */
public class I18n {

    public static ResourceBundle GetResourceBundle() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application app = facesContext.getApplication();
        ResourceBundle bundle = app.getResourceBundle(facesContext, "i18n");
        return bundle;
    }

    public static String Get(String key) {
        String value = GetResourceBundle().getString(key);
        if (key == null) {
            return "########";
        }
        return value;
    }
}