Example usage for java.util ResourceBundle getString

List of usage examples for java.util ResourceBundle getString

Introduction

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

Prototype

public final String getString(String key) 

Source Link

Document

Gets a string for the given key from this resource bundle or one of its parents.

Usage

From source file:PropertiesDemo.java

static void displayValue(Locale currentLocale, String key) {

    ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);
    String value = labels.getString(key);
    System.out.println(/*from  w ww.  jav a 2  s . c  om*/
            "Locale = " + currentLocale.toString() + ", " + "key = " + key + ", " + "value = " + value);

}

From source file:Main.java

static String localize(Locale locale, String baseName, String messageId, Object... parameters) {
    //Log.v(LOG_TAG, String.format("locale=%s, baseName=%s, messageId=%s, parameters=%s", locale, baseName, messageId, Arrays.asList(parameters)));
    if (locale == null) {
        locale = Locale.getDefault();
    }/*from  w  w  w .jav a  2 s .  c om*/
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
        String source = bundle.getString(messageId);
        return MessageFormat.format(source, parameters);
    } catch (MissingResourceException e) {
        return "message '" + messageId + "' could not be localized (" + e.getMessage() + ")";
    }
}

From source file:RBCPTest.java

private static void test(Locale locale) {
    ResourceBundle rb = ResourceBundle.getBundle("resources.RBControl", locale);
    System.out.println("locale: " + locale);
    System.out.println("    region: " + rb.getString("region"));
    System.out.println("    language: " + rb.getString("language"));
    System.out.println();//from  w w  w  .  j  a va 2 s .com
}

From source file:adalid.commons.bundles.Bundle.java

private static Locale getLocale(ResourceBundle rb) {
    try {/*from   w ww  .  j a v a  2 s . c  o  m*/
        String tag = rb.getString("locale.tag");
        return Locale.forLanguageTag(tag);
    } catch (MissingResourceException e) {
        return Locale.getDefault();
    }
}

From source file:adalid.commons.bundles.Bundle.java

private static Linguist getLinguist(ResourceBundle rb) {
    try {/*  ww  w.  j  ava 2  s  .c o  m*/
        String name = rb.getString(Linguist.class.getName());
        Class<?> clazz = Class.forName(name);
        return (Linguist) clazz.newInstance();
    } catch (MissingResourceException | ClassNotFoundException | InstantiationException
            | IllegalAccessException e) {
        return null;
    }
}

From source file:adalid.commons.bundles.Bundle.java

private static String getTrimmedToNullString(String key, ResourceBundle rb) {
    try {/*from   w  w  w .ja v  a 2  s. c  om*/
        String string = rb.getString(key);
        return StringUtils.trimToNull(string);
    } catch (MissingResourceException e) {
        return null;
    }
}

From source file:Main.java

/**
 * Gets a resource string from the resource bundle.<p> Resource bundle
 * represents the <i>property file</i>. For example, if property file
 * contains something like this:<BR><CENTER>menubar=file edit help</CENTER>
 * method call getLanguageDependentString("menubar") will give the string
 * <i>file edit help</i> as a result. <BR> This method reads information
 * from property file. If can't find desired resource, returns <b>null</b>.
 * @param nm name of the resource to fetch.
 * @return String value of named resource.
 *///from   www .j  a v  a 2 s.c o  m
public static String getLanguageDependentString(String nm) {
    String str;
    try {
        str = choosenResources.getString(nm);
    } catch (MissingResourceException mre) {
        try {
            str = defaultResources.getString(nm);
        } catch (MissingResourceException mre1) {
            str = null;
        } catch (NullPointerException npe) {
            str = null;
        }
    } catch (NullPointerException npe) {
        /*ResourceBundle orig=ResourceBundle.
         getBundle("org.enhydra.shark.xpdl.resources.SharkXPDL",new Locale(""));*/
        ResourceBundle orig = ResourceBundle.getBundle("org.enhydra.shark.xpdl.resources.SharkXPDL");
        try {
            str = orig.getString(nm);
        } catch (Exception ex) {
            str = null;
        }
    }
    return str;
}

From source file:br.com.webbudget.infraestructure.configuration.ApplicationUtils.java

/**
 * Busca no bundle de configuracoes da aplicacao uma determinada chave para
 * uma configuracao/*  w ww.  ja  va  2 s  . c o  m*/
 *
 * @param configurationKey a chave da qual queremos a configuracao
 * @return a configuracao para a chave informada
 */
public static String getConfiguration(String configurationKey) {

    final ResourceBundle bundle = ResourceBundle.getBundle("webbudget");

    return bundle.getString(configurationKey);
}

From source file:br.ufg.calendario.components.LocaleBean.java

public static String getMessage(String msg) {
    ResourceBundle messages = ResourceBundle.getBundle("br.ufg.calendario.locale.messages",
            new Locale(getInstance().getLocale()));
    return messages.getString(msg);
}

From source file:de.gmorling.methodvalidation.spring.SpringMethodValidationTest.java

@BeforeClass
public static void before() {
    ResourceBundle bundle = ResourceBundle.getBundle("org.hibernate.validator.ValidationMessages");
    nullValidationMessage = bundle.getString("javax.validation.constraints.NotNull.message");
}