Example usage for java.util ResourceBundle getBundle

List of usage examples for java.util ResourceBundle getBundle

Introduction

In this page you can find the example usage for java.util ResourceBundle getBundle.

Prototype

@CallerSensitive
public static ResourceBundle getBundle(String baseName, Module module) 

Source Link

Document

Gets a resource bundle using the specified base name and the default locale on behalf of the specified module.

Usage

From source file:net.naijatek.myalumni.util.date.DateConverterUtil.java

/**
 * Return default datePattern (MM/dd/yyyy)
 * @return a string representing the date pattern on the UI
 *///from   w  ww  .j  a v a2 s  . c o  m
public static synchronized String getDatePattern() {
    Locale locale = LocaleContextHolder.getLocale();
    try {
        defaultDatePattern = ResourceBundle.getBundle("", locale).getString("date.format");
    } catch (MissingResourceException mse) {
        //defaultDatePattern = "MM-dd-yyyy";
        defaultDatePattern = "yyyy-MM-dd";
    }
    log.info("### Default Date Pattern = " + defaultDatePattern);
    return defaultDatePattern;
}

From source file:fr.mycellar.interfaces.web.services.nav.NavigationWebService.java

@PostConstruct
public void build() {
    ResourceBundle resourceBundle = ResourceBundle.getBundle("Menu", Locale.FRENCH);
    List<IDescriptor> descriptors = descriptorServiceFacade.getDescriptors();

    SortedMap<Integer, NavDescriptor> menuPages = new TreeMap<Integer, NavDescriptor>();

    for (IDescriptor descriptor : descriptors) {
        if (descriptor instanceof IMenuDescriptor) {
            IMenuDescriptor menuDescriptor = ((IMenuDescriptor) descriptor);
            if (menuDescriptor.getParentKey() != null) {
                NavHeaderDescriptor header = getHeader(resourceBundle.getString(menuDescriptor.getParentKey()),
                        menuPages);/*from   ww  w.  j a va  2  s . c  o m*/
                if (header == null) {
                    header = new NavHeaderDescriptor(resourceBundle.getString(menuDescriptor.getParentKey()),
                            menuDescriptor.getIcon());
                    menuPages.put(menuDescriptor.getWeight(), header);
                }
                header.addPage(menuDescriptor.getWeight(), new NavPageDescriptor(menuDescriptor.getRoute(),
                        resourceBundle.getString(menuDescriptor.getTitleKey()), menuDescriptor.getIcon()));
            } else {
                menuPages.put(menuDescriptor.getWeight(), new NavPageDescriptor(menuDescriptor.getRoute(),
                        resourceBundle.getString(menuDescriptor.getTitleKey()), menuDescriptor.getIcon()));
            }
        }
    }

    menu = new ArrayList<NavDescriptor>(menuPages.values());
}

From source file:mb.MbAdministrator.java

public String logIn() {
    Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    Administrator a = getEjbAdministrator().logIn(administrator);
    if (a == null) {
        JsfUtil.addErrorMessage(ResourceBundle.getBundle("localization.messages", locale)
                .getString("LogInAdministratorMessage_failure"));
        return "index";
    }//from   www .  j  a va 2 s.  c  o m
    administrator = a;
    JsfUtil.addSuccessMessage(ResourceBundle.getBundle("localization.messages", locale)
            .getString("LogInAdministratorMessage_success"));
    return "admin?faces-redirect=true";
}

From source file:net.fenyo.gnetwatch.Config.java

/**
 * Constructor.//w  w w . j  a v  a 2s .c om
 * Reads the configuration properties from the initialization file.
 * main thread
 * @param none.
 * @throws IOException file not found.
 */
public Config() throws IOException {
    properties = new Properties();
    properties.loadFromXML(new FileInputStream("config.xml"));

    locale = new Locale(getProperty("language"), getProperty("country"));
    bundle = ResourceBundle.getBundle("i18n", locale);
}

From source file:com.zestedesavoir.zestwriter.utils.Configuration.java

/**
 * Class constructor/*from   ww  w  . j  ava 2s .  c  o  m*/
 * @param homeDir Absolute path of home directory
 */
public Configuration(String homeDir) {
    String appName = "zestwriter";
    String confDirPath = homeDir + File.separator + "." + appName;
    File confDir = new File(confDirPath);
    if (!confDir.exists()) {
        if (!confDir.mkdir()) {
            log.error("Le rpertoire de configuration n'a pas pu tre cre");
        } else {
            log.info("Le rpertoire de configuration a t cre avec succs");
        }
    }

    initConf(confDirPath);
    initActions();
    try {
        bundle = ResourceBundle.getBundle("locales/ui", Lang.getLangFromCode(getDisplayLang()).getLocale());
    } catch (Exception e) {
        bundle = ResourceBundle.getBundle("locales/ui", Locale.FRANCE);
        log.error("Impossible de charger la langue " + getDisplayLang(), e);
    }
}

From source file:io.github.xxyy.simplegiveall.SimpleGiveallMain.java

@Override
public final void onEnable() {
    initialiseConfig();/*  ww w  . j  a va2  s. co  m*/

    Locale locale = Locale.forLanguageTag(this.getConfig().getString("locale"));

    bundle = ResourceBundle.getBundle("io/github/xxyy/simplegiveall/simplegiveall", locale);

    this.getCommand(bundle.getString("GIVEALL")).setExecutor(this);

    System.out.println(LICENSE_HEADER);
}

From source file:com.gisgraphy.domain.valueobject.FeatureCodeTest.java

@Test
public void testGetLocalizedDescriptionShouldReturnLocalizedDescription() {

    assertEquals("The bundle should ignore the country if a bundle with only the language exists",
            ResourceBundle.getBundle(Constants.FEATURECODE_BUNDLE_KEY, localeaa).getString(
                    FeatureCode.P_PPL.toString()),
            FeatureCode.P_PPL.getLocalizedDescription(localeaacc));

    assertEquals("The bundle should take the country and language if a bundle with both exists", ResourceBundle
            .getBundle(Constants.FEATURECODE_BUNDLE_KEY, localebbdd).getString(FeatureCode.P_PPL.toString()),
            FeatureCode.P_PPL.getLocalizedDescription(localebbdd));

    assertEquals("The bundle should be able to only take the language into account",
            ResourceBundle.getBundle(Constants.FEATURECODE_BUNDLE_KEY, localeaa).getString("P_PPL"),
            FeatureCode.P_PPL.getLocalizedDescription(localeaa));

    // null//from w  ww. j  a  va  2 s. c o m
    Locale savedcontext = LocaleContextHolder.getLocale();
    LocaleContextHolder.setLocale(localeaa);// force an existing
    // translation bundle
    assertEquals("if the locale is null, the LocaleContextHolder one should be used",
            FeatureCode.P_PPL.getLocalizedDescription(LocaleContextHolder.getLocale()),
            FeatureCode.P_PPL.getLocalizedDescription(null));
    LocaleContextHolder.setLocale(savedcontext);

    // no bundle for the specified Locale
    LocaleContextHolder.setLocale(localeaa);// force an existing
    // translation bundle
    assertEquals("If no bundle for the specified locale exists the thread one should be used",
            FeatureCode.P_PPL.getLocalizedDescription(LocaleContextHolder.getLocale()),
            FeatureCode.P_PPL.getLocalizedDescription(localeWithOutBundle));
    LocaleContextHolder.setLocale(savedcontext);

    // no bundle exists for the thread locale

    LocaleContextHolder.setLocale(localeWithOutBundle);
    assertEquals("If no bundle for the specified locale exists and the default"
            + " thread one does not exists, the locale.getDefault should be used : " + Locale.getDefault(),
            FeatureCode.P_PPL.getLocalizedDescription(Locale.getDefault()),
            FeatureCode.P_PPL.getLocalizedDescription(localeWithOutBundle));
    // restore
    LocaleContextHolder.setLocale(savedcontext);

    // no bundle exists for the thread locale and default one,
    Locale savedDefault = Locale.getDefault();
    LocaleContextHolder.setLocale(localeWithOutBundle);
    Locale.setDefault(localeWithOutBundle);
    assertEquals(
            "If no bundle for the specified locale exists and no bundle for the default "
                    + "thread one exists and no bundle for the default one exists,"
                    + " the DEFAULT_FALLBACK_LOCALE should be used : " + FeatureCode.DEFAULT_FALLBACK_LOCALE,
            FeatureCode.P_PPL.getLocalizedDescription(localeWithOutBundle),
            FeatureCode.P_PPL.getLocalizedDescription(null));
    // restore
    Locale.setDefault(savedDefault);
    LocaleContextHolder.setLocale(savedcontext);

    // existing locale and non existing translation
    assertEquals(
            "if no translation for the locale is found," + " default translation should be used : "
                    + FeatureCode.DEFAULT_TRANSLATION,
            FeatureCode.DEFAULT_TRANSLATION, FeatureCode.UNKNOW.getLocalizedDescription(localeaa));//

}

From source file:com.exxeta.iss.sonar.esql.test.CheckListTest.java

/**
 * Enforces that each check has test, name and description.
 *///  w  w w . ja v  a  2  s.  com
@Test
public void test() {
    List<Class> checks = CheckList.getChecks();
    for (Class cls : checks) {
        String testName = '/' + cls.getName().replace('.', '/') + "Test.class";
        assertThat(getClass().getResource(testName))
                .overridingErrorMessage("No test for " + cls.getSimpleName()).isNotNull();
    }
    ResourceBundle resourceBundle = ResourceBundle.getBundle("org.sonar.l10n.esql", Locale.ENGLISH);
    Set<String> keys = Sets.newHashSet();
    ActiveRules activeRules = (new ActiveRulesBuilder()).build();
    CheckFactory checkFactory = new CheckFactory(activeRules);
    Collection<Rule> rules = checkFactory.<Rule>create("repositoryKey")
            .addAnnotatedChecks(CheckList.getChecks()).all();
    for (Rule rule : rules) {
        assertThat(keys).as("Duplicate key " + rule.getKey()).excludes(rule.getKey());
        keys.add(rule.getKey());
        resourceBundle.getString("rule." + CheckList.REPOSITORY_KEY + "." + rule.getKey() + ".name");
        assertThat(getClass().getResource("/org/sonar/l10n/esql/rules/esql/" + rule.getKey() + ".html"))
                .overridingErrorMessage("No description for " + rule.getKey()).isNotNull();
        assertThat(rule.getDescription())
                .overridingErrorMessage("Description of " + rule.getKey() + " should be in separate file")
                .isNull();
        for (RuleParam param : rule.getParams()) {
            resourceBundle.getString(
                    "rule." + CheckList.REPOSITORY_KEY + "." + rule.getKey() + ".param." + param.getKey());
            assertThat(param.getDescription()).overridingErrorMessage("Description for param " + param.getKey()
                    + " of " + rule.getKey() + " should be in separate file").isEmpty();
        }
    }
}

From source file:com.cyclopsgroup.waterview.core.ResourceBundleI18NService.java

/**
 * Overwrite or implement method translate()
 *
 * @see com.cyclopsgroup.waterview.spi.I18NService#translate(java.lang.String, java.util.Locale)
 *//*  www.  j  av a 2s .c om*/
public String translate(String key, Locale locale) throws Exception {
    for (Iterator i = resourceKeys.iterator(); i.hasNext();) {
        String resourceKey = (String) i.next();
        try {
            ResourceBundle rb = ResourceBundle.getBundle(resourceKey, locale);
            String s = rb.getString(key);
            if (StringUtils.isNotEmpty(s)) {
                return s;
            }
            continue;
        } catch (Exception e) {
            continue;
        }
    }
    return "%" + key;
}

From source file:com.feilong.core.util.ResourceBundleUtilTest.java

/**
 * TestResourceBundleUtilTest./*from   w w  w.j a va2  s .c  o m*/
 */
@Test
public void testResourceBundleUtilTest() {
    Control control = Control.getControl(Control.FORMAT_PROPERTIES);
    //control.needsReload(baseName, locale, format, loader, bundle, loadTime)     ;
    ResourceBundle bundle = ResourceBundle.getBundle(BASE_NAME, control);
    LOGGER.debug(JsonUtil.format(toMap(bundle)));
}