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: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:PropertiesDemo.java

static void iterateKeys(Locale currentLocale) {

    ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);

    Enumeration bundleKeys = labels.getKeys();

    while (bundleKeys.hasMoreElements()) {
        String key = (String) bundleKeys.nextElement();
        String value = labels.getString(key);
        System.out.println("key = " + key + ", " + "value = " + value);
    }/*from   w  w  w.  j a v  a 2s . c  o  m*/

}

From source file:io.github.medinam.jcheesum.util.VersionChecker.java

public static void showDownloadLatestAlert() {
    Alert alert = new Alert(Alert.AlertType.INFORMATION);

    ResourceBundle resources = ResourceBundle.getBundle("i18n/Bundle", Locale.getDefault());

    alert.setTitle(resources.getString("newVersion"));
    alert.setHeaderText(resources.getString("newVersionLooksLike"));
    alert.setContentText(resources.getString("youHave") + App.class.getPackage().getImplementationVersion()
            + " " + resources.getString("latestVersionIs") + getLatestStable() + "\n\n"
            + resources.getString("wannaDownload"));

    ButtonType yesBtn = new ButtonType(resources.getString("yes"));
    ButtonType noBtn = new ButtonType(resources.getString("no"), ButtonBar.ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(yesBtn, noBtn);

    Optional<ButtonType> o = alert.showAndWait();

    if (o.get() == yesBtn) {
        General.openLink(getLatestStableDownloadURL());
    } else if (o.get() == noBtn) {
        alert.close();/* w  w  w .j  a  v a  2  s  . c  o m*/
    }
}

From source file:WelcomeServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();

    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);

    String welcome = bundle.getString("Welcome");

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();

    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + welcome + "</h2>");

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("</body></html>");
    out.close();/*  w  w w. jav  a2  s  . co  m*/

}

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();
    }/*  w  w  w . j a  va  2 s  .  c  o  m*/
    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:CurrLocaleServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);
    String welcome = bundle.getString("Welcome");

    NumberFormat nft = NumberFormat.getCurrencyInstance(locale);
    String formatted = nft.format(1000000);

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>");

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("<br /><br />");
    out.println(formatted);/*ww  w  . j  av a 2  s.co m*/

    out.println("</body></html>");
    out.close();

}

From source file:com.taobao.itest.util.DateConverter.java

public static synchronized String getDatePattern() {
    Locale locale = LocaleContextHolder.getLocale();
    try {/*from  ww w .  j  a v a 2  s  .  co m*/
        defaultDatePattern = ResourceBundle.getBundle(resource, locale).getString("datePattern");
    } catch (MissingResourceException mse) {
        defaultDatePattern = "yyyy-MM-dd";
    }

    return defaultDatePattern;
}

From source file:DateLocaleServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);
    String welcome = bundle.getString("Welcome");
    String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date());

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>");

    out.println(date + "<br /><br />");

    java.util.Enumeration e = bundle.getKeys();
    while (e.hasMoreElements()) {

        out.println((String) e.nextElement());
        out.println("<br /><br />");

    }/*from w w  w . j a  va  2  s . c om*/

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("</body></html>");

}

From source file:org.openlmis.fulfillment.web.util.ReportUtils.java

/**
 * Set parameters of rendered pdf report.
 *///from   w w  w .  j  a  v a 2 s  .  com
public static Map<String, Object> createParametersMap() {
    Map<String, Object> params = new HashMap<>();
    params.put("format", "pdf");

    Locale currentLocale = LocaleContextHolder.getLocale();
    params.put(REPORT_LOCALE, currentLocale);

    ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", currentLocale);
    params.put(REPORT_RESOURCE_BUNDLE, resourceBundle);

    params.put("subreport_dir", "reports/");
    params.put("image_dir", "images/");

    return params;
}

From source file:com.marand.thinkmed.medications.MedicationsTestDictionary.java

private static ResourceBundle getBundle(final Locale locale) {
    return ResourceBundle.getBundle(BUNDLE_BASE_NAME, locale);
}