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) 

Source Link

Document

Construct a locale from a language code.

Usage

From source file:Main.java

/**
 *
 * @param input Date for format//from w w  w.  j ava 2s .com
 * @param pattern date pattern e.g. "yyyy.MM.dd"
 * @return
 */
public static String formateDate(Date input, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern, new Locale("hu"));
    sdf.applyPattern(pattern);
    return sdf.format(input);
}

From source file:Main.java

/**
 * Change the default locale of the application for this activity
 *
 * @param locale To set in the configuration
 *///from ww  w .j  av  a 2 s .c om
public static void setDefaultLocale(Context context, String locale) {
    Locale locJa = new Locale(locale);
    Locale.setDefault(locJa);

    Configuration config = new Configuration();
    config.locale = locJa;

    if (context != null) {
        context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    }
}

From source file:Main.java

/**
 * Set default language//ww  w  .ja v a2 s  .  c  om
 * 
 * @param act
 * @param defLanguage
 */
public static void setDefaultLanguage(Activity act, String defLanguage) {
    if (defLanguage != null) {
        // Change locale settings in the app.
        Resources res = act.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        conf.locale = new Locale(defLanguage);
        res.updateConfiguration(conf, dm);
    }
}

From source file:Main.java

/**
 * Prepares the locale. The language can be overridden with the specified environment variable. Set it to "de" to
 * enforce German language for example. The default is the system locale.
 *
 * @param overrideEnvVar/*  w w  w.ja va  2  s.co m*/
 *            The environment variable to check for override value. Must not be null.
 */

public static void prepareLocale(final String overrideEnvVar) {
    final String language = System.getenv().get(overrideEnvVar);
    if (language != null) {
        Locale.setDefault(new Locale(language));
    }
}

From source file:cz.afrosoft.whattoeat.core.gui.I18n.java

public static void init(final String language) {
    Locale locale = new Locale(language);
    I18n.resourceBundle = ResourceBundle.getBundle(TEXTS_BUNDLE_NAME, locale);
    I18n.collator = Collator.getInstance(locale);
}

From source file:Main.java

public static void reloadLocale(Context context) {
    SharedPreferences sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(context.getApplicationContext());
    String lang = sharedPrefs.getString(PREF_APP_LANGUAGE, Locale.getDefault().getLanguage());
    if (sharedPrefs.getString(PREF_APP_LANGUAGE, "").equalsIgnoreCase("")) {
        sharedPrefs.edit().putString(PREF_APP_LANGUAGE, lang).commit();
    }/*from   w ww .  j av a 2s.  co m*/
    Configuration newConfig = context.getResources().getConfiguration();

    if (!newConfig.locale.getLanguage().equals(lang)) {
        locale = new Locale(lang);
    }

    if (locale != null) {
        Locale.setDefault(locale);
        newConfig.locale = locale;
        context.getResources().updateConfiguration(newConfig, context.getResources().getDisplayMetrics());
    }
}

From source file:Main.java

public static Locale getLocale(String locale) {
    if (locale == null)
        return Locale.getDefault();

    StringTokenizer localeTokenizer = new StringTokenizer(locale, "_");
    if (localeTokenizer.countTokens() == 1) {
        return new Locale(locale);
    } else {// ww w. j ava2s  .co m
        return new Locale(localeTokenizer.nextToken(), localeTokenizer.nextToken());
    }
}

From source file:io.bibleget.BibleGetI18N.java

/**
 *
 * @param s/*  ww  w . ja va  2  s.  com*/
 * @return
 */
public static String __(String s) {
    lcl = BibleGetIO.getLocale();
    Locale myLocale;
    myLocale = new Locale(lcl);
    try {
        myResource = ResourceBundle.getBundle("io.bibleget.resources.messages", myLocale);
    } catch (MissingResourceException ex) {
        myResource = ResourceBundle.getBundle("io.bibleget.resources.messages");
    }

    if (myResource.containsKey(s)) {
        try {
            String val = myResource.getString(s);
            return new String(val.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(BibleGetI18N.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        return s;
    }
    return null;
}

From source file:com.github.vatbub.tictactoe.view.Main.java

public static void main(String[] args) {
    Common.getInstance().setAppName("tictactoev2");
    FOKLogger.enableLoggingOfUncaughtExceptions();

    try {/* w  w w  .  j av a 2  s. c  om*/
        applicationConfiguration = new Config(new URL(
                "https://raw.githubusercontent.com/vatbub/tictactoe/master/remoteconfig/client.properties"),
                Main.class.getResource("fallbackConfig.properties"), true,
                "tictactoeClientConfigCache.properties", true);
    } catch (IOException e) {
        FOKLogger.log(Main.class.getName(), Level.SEVERE, "Could not read the remote config", e);
    }

    for (String arg : args) {
        if (arg.toLowerCase().matches("mockappversion=.*")) {
            // Set the mock version
            String version = arg.substring(arg.toLowerCase().indexOf('=') + 1);
            Common.getInstance().setMockAppVersion(version);
        } else if (arg.toLowerCase().matches("mockbuildnumber=.*")) {
            // Set the mock build number
            String buildnumber = arg.substring(arg.toLowerCase().indexOf('=') + 1);
            Common.getInstance().setMockBuildNumber(buildnumber);
        } else if (arg.toLowerCase().matches("mockpackaging=.*")) {
            // Set the mock packaging
            String packaging = arg.substring(arg.toLowerCase().indexOf('=') + 1);
            Common.getInstance().setMockPackaging(packaging);
        } else if (arg.toLowerCase().matches("locale=.*")) {
            // set the gui language
            String guiLanguageCode = arg.substring(arg.toLowerCase().indexOf('=') + 1);
            FOKLogger.info(Main.class.getName(), "Setting language: " + guiLanguageCode);
            Locale.setDefault(new Locale(guiLanguageCode));
        }
    }

    launch(args);
}

From source file:com.ijuru.kumva.util.Utils.java

/**
 * Converts a ISO-639 language code to a language name
 * @param code the code//from   w  w w. j  ava  2s .c  o  m
 * @return the name
 */
public static String getLanguageName(String code) {
    return new Locale(code).getDisplayLanguage();
}