Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

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

Prototype

public Locale(String language, String country, String variant) 

Source Link

Document

Construct a locale from language, country and variant.

Usage

From source file:Main.java

public static void main(String[] args) {

    Locale locale1 = new Locale("en", "US", "WIN");

    System.out.println("Locale:" + locale1);

    // print the locale as a string
    System.out.println("Locale:" + locale1.toString());

    Locale locale2 = new Locale("fr", "FRANCE", "WIN");

    System.out.println("Locale2:" + locale2);

    // print the locale as a string
    System.out.println("Locale2:" + locale2.toString());

}

From source file:JapaneseCalendar.java

public static void main(String args[]) {
    Locale locale = new Locale("ja", "JP", "JP");
    Calendar now = Calendar.getInstance(locale);

    Map<String, Integer> names = now.getDisplayNames(Calendar.ERA, Calendar.LONG, locale);
    System.out.printf("%s%n", names);
    System.out.printf("It is year %tY of the current era%n", now);
    System.out.printf("The calendar class is: %s%n", now.getClass().getName());
}

From source file:Main.java

public static void main(String[] args) {
    double value = 1234567.89;

    System.out.println("Unformatted: " + value + "\n");

    Locale locales[] = { Locale.US, Locale.FRANCE, Locale.GERMANY, Locale.JAPAN, new Locale("fr", "FR", "EURO"),
            new Locale("de", "DE", "EURO") };

    for (int i = 0; i < locales.length; i++) {
        NumberFormat nf = NumberFormat.getCurrencyInstance(locales[i]);

        System.out.println("Formatted for " + locales[i] + ": " + nf.format(value));
    }/*from ww  w  . j  ava  2  s  .c  o  m*/
}

From source file:DisplayVariantOutput.java

public static void main(String[] argv) {

    Locale defaultLocale = Locale.getDefault();
    System.out.println(defaultLocale.getDisplayVariant());
    System.out.println(defaultLocale.getDisplayVariant(Locale.US));
    System.out.println((new Locale("en", "US", "WIN_TX_Austin")).getDisplayVariant());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Locale defaultLocale = Locale.getDefault();
    System.out.println(defaultLocale.getDisplayVariant());
    System.out.println(defaultLocale.getDisplayVariant(Locale.US));
    System.out.println((new Locale("en", "US", "WIN_TX_Austin")).getDisplayVariant());
}

From source file:JapaneseCalendar.java

public static void main(String[] args) {
    Locale japanese = new Locale("ja", "JP", "JP");

    Calendar cal = Calendar.getInstance(japanese);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, japanese);
    String str = df.format(cal.getTime());

    JOptionPane.showMessageDialog(null, str);
}

From source file:Deet.java

public static void main(String... args) {
    if (args.length != 4) {
        err.format("Usage: java Deet <classname> <langauge> <country> <variant>%n");
        return;/*w w  w.j a v  a2 s .c o  m*/
    }

    try {
        Class<?> c = Class.forName(args[0]);
        Object t = c.newInstance();

        Method[] allMethods = c.getDeclaredMethods();
        for (Method m : allMethods) {
            String mname = m.getName();
            if (!mname.startsWith("test") || (m.getGenericReturnType() != boolean.class)) {
                continue;
            }
            Type[] pType = m.getGenericParameterTypes();
            if ((pType.length != 1) || Locale.class.isAssignableFrom(pType[0].getClass())) {
                continue;
            }

            out.format("invoking %s()%n", mname);
            try {
                m.setAccessible(true);
                Object o = m.invoke(t, new Locale(args[1], args[2], args[3]));
                out.format("%s() returned %b%n", mname, (Boolean) o);

                // Handle any exceptions thrown by method to be invoked.
            } catch (InvocationTargetException x) {
                Throwable cause = x.getCause();
                err.format("invocation of %s failed: %s%n", mname, cause.getMessage());
            }
        }

        // production code should handle these exceptions more gracefully
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    } catch (InstantiationException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    }
}

From source file:es.tunelator.Start.java

/**
 * Bootstraps the application, creates and shows the user interface
 * @param args//from   w ww.ja va 2 s. c  o  m
 */
public static void main(String[] args) {
    MainFrame frame = null;
    try {

        //            LogFactory.getFactory().setAttribute(LogFactoryImpl.LOG_PROPERTY,
        //                    Log4JLogger.class.getName());
        //            PropertyConfigurator.configure(Start.class.getClassLoader().
        //                    getResource("log4j.properties"));
        // Set log level as configured at the application parameters            
        Logger.setLogThreshold(AppParameters.getParams().getProperty("log.threshold", AppParameters.LOG_ERROR));
        //        If the language of the default locale is not supported revert to english
        if (!isLocaleSupported()) {
            Locale.setDefault(new Locale("en", "", ""));
        } else {
            Locale.setDefault(new Locale(Locale.getDefault().getLanguage(), "", ""));
        }
        // Log application startup          
        Logger.logInfo(Start.class, Resourcer.getString(null, "log.info.startup"));
        // To set up the Look and Feel
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows." + "WindowsLookAndFeel");
        frame = new MainFrame();
        frame.setVisible(true);
        frame.correctTabStatus();
        // To change the Look and Feel. To be included as an option some day...
        //          UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk."+
        //          "GTKLookAndFeel");
        //          SwingUtilities.updateComponentTreeUI(frame);
        //          frame.pack();
    } catch (Exception e) {
        Logger.logFatal(Start.class, e);
        if (frame != null) {
            frame.showErrorMessage(Resourcer.getString(null, "error.internal"));
            frame.dispose();
        } else {
            try {
                JOptionPane.showMessageDialog(null, Resourcer.getString(Start.class, "error.internal"),
                        Resourcer.getString(Start.class, "error.title"), JOptionPane.ERROR_MESSAGE);
            } catch (Exception e2) {
                String message = "";
                // This is the last resort to give a localized message
                // As I'm spanish :-), we give a spanish message if it's
                // the default language, and an english one otherwise.
                if (Locale.getDefault().getLanguage().equals(new Locale("es", "", "").getLanguage())) {
                    message = message_es;
                } else {
                    message = message_en;
                }
                JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
            }
        }
        System.exit(1);
    } catch (InternalError e) {
        Logger.logFatal(Start.class, e);
        if (frame != null) {
            frame.showErrorMessage(Resourcer.getString(null, "error.internal"));
            frame.dispose();
        } else {
            try {
                JOptionPane.showMessageDialog(null, Resourcer.getString(Start.class, "error.internal"),
                        Resourcer.getString(Start.class, "error.title"), JOptionPane.ERROR_MESSAGE);
            } catch (Exception e2) {
                String message = "";
                // This is the last resort to give a localized message
                // As I'm spanish :-), we give a spanish message if it's
                // the default language, and an english one otherwise.
                if (Locale.getDefault().getLanguage().equals(new Locale("es", "", "").getLanguage())) {
                    message = message_es;
                } else {
                    message = message_en;
                }
                JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
            }
        }
        System.exit(1);
    }
}

From source file:Main.java

public static Locale stringToLocale(String locString) {

    locString = locString != null ? locString.trim() : "";
    if (locString.equals(""))
        return new Locale("", "", "");
    int pos = locString.indexOf(95);
    if (pos == -1)
        return new Locale(locString, "", "");
    String language = locString.substring(0, pos);
    locString = locString.substring(pos + 1);
    pos = locString.indexOf(95);//w  w w . j  a  v  a  2s . co m
    if (pos == -1) {
        return new Locale(language, locString, "");
    } else {
        String country = locString.substring(0, pos);
        locString = locString.substring(pos + 1);
        return new Locale(language, country, locString);
    }
}

From source file:com.enonic.cms.business.localization.resource.LocalizationResourceBundleUtils.java

public static Locale parseLocaleString(String localeAsString) {
    localeAsString = localeAsString.replace('-', '_');

    Matcher matcher = RegexpUtil.match(localeAsString, LOCALE_PATTERN, Pattern.CASE_INSENSITIVE);

    String language = "";
    String country = "";
    String variant = "";

    if (matcher.matches()) {
        language = getLanguageFromMatcher(matcher);
        country = getCountryFromMatcher(matcher);
        variant = getVariantFromMatcher(matcher);
    } else {/*from  w  w  w .  jav  a 2 s  . c o  m*/
        throw new LocaleParsingException(
                "Could not parse locale string: " + localeAsString + " to valid locale");
    }

    return new Locale(language, country == null ? "" : country, variant == null ? "" : variant);
}