Example usage for java.util Locale forLanguageTag

List of usage examples for java.util Locale forLanguageTag

Introduction

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

Prototype

public static Locale forLanguageTag(String languageTag) 

Source Link

Document

Returns a locale for the specified IETF BCP 47 language tag string.

Usage

From source file:Test.java

public static void main(String[] args) {
    long SAMPLE_NUMBER = 123456789L;
    Date NOW = new Date();
    System.out.printf("Creating from BCP 47 language tags...\n\n");
    String[] bcp47LangTags = { "fr-FR", "ja-JP", "en-US" };
    Locale l = null;/*from  w ww .  ja  v  a 2 s .c  om*/
    for (String langTag : bcp47LangTags) {
        l = Locale.forLanguageTag(langTag);
        displayLocalizedData(l, SAMPLE_NUMBER, NOW);
    }
}

From source file:com.rover12421.shaka.cli.Main.java

public static void main(String[] args) throws Exception {
    boolean smali = false;
    boolean baksmali = false;

    String[] realyArgs = args;//from   w w w  . j  a  va 2  s . c o  m

    if (args.length > 0) {
        String cmd = args[0];
        if (cmd.equalsIgnoreCase("s") || cmd.equalsIgnoreCase("smali")) {
            smali = true;
        } else if (cmd.equalsIgnoreCase("bs") || cmd.equalsIgnoreCase("baksmali")) {
            baksmali = true;
        }

        if (smali || baksmali) {
            realyArgs = new String[args.length - 1];
            System.arraycopy(args, 1, realyArgs, 0, realyArgs.length);
        }
    }

    // cli parser
    CommandLineParser parser = new IgnoreUnkownArgsPosixParser();
    CommandLine commandLine;

    Option language = CommandLineArgEnum.LANGUAGE.getOption();

    Options options = new Options();
    options.addOption(language);

    try {
        commandLine = parser.parse(options, args, false);
        if (CommandLineArgEnum.LANGUAGE.hasMatch(commandLine)) {
            String lngStr = commandLine.getOptionValue(CommandLineArgEnum.LANGUAGE.getOpt());
            Locale locale = Locale.forLanguageTag(lngStr);
            if (locale.toString().isEmpty()) {
                lngStr = lngStr.replaceAll("_", "-");
                locale = Locale.forLanguageTag(lngStr);
            }
            MultiLanguageSupport.getInstance().setLang(locale);
        }
    } catch (Exception ex) {
    }

    if (smali) {
        smaliMainAj.setHookMain(ApktoolMainAj.getHookMain());
        org.jf.smali.main.main(realyArgs);
    } else if (baksmali) {
        baksmaliMainAj.setHookMain(ApktoolMainAj.getHookMain());
        org.jf.baksmali.main.main(realyArgs);
    } else {
        brut.apktool.Main.main(realyArgs);
    }
}

From source file:com.kaikoda.cah.CardGenerator.java

/**
 * Generates a printable deck of Cards Against Humanity.
 * //from   ww  w.  j a v a2 s  .  c o m
 * @param args where to find the data file and optionally the dictionary and
 *        target language if translation is required.
 * @throws CardGeneratorConfigurationException when it's not possible to
 *         construct a usable instance of CardGenerator.
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws ParseException if there are any problems encountered while
 *         parsing the command line tokens.
 */
public static void main(String[] args) throws CardGeneratorConfigurationException, ParseException, SAXException,
        IOException, ParserConfigurationException {

    ProgressReporterMode verbosity = ProgressReporterMode.NORMAL;

    CardGenerator generator = new CardGenerator();
    generator.setVerbosity(verbosity);

    // Configure valid options accepted from the command-line
    CardGeneratorOptions options = new CardGeneratorOptions();

    // Interpret the arguments supplied at runtime.
    TreeMap<String, String> params = options.parse(args);

    // Check whether a level of verbosity has been specified.
    if (params.containsKey("verbosity")) {
        verbosity = ProgressReporterMode.valueOf(params.get("verbosity").toUpperCase());
        generator.setVerbosity(verbosity);
    }

    // Check whether help has been requested.
    if (params.containsKey("help")) {

        if (verbosity.equals(ProgressReporterMode.NORMAL)) {

            // Print a list of the options that can be used with
            // CardGenerator.
            System.out.println("\n" + params.get("help"));

        }

    } else {

        File data = new File(params.remove("path-to-data"));

        CardGeneratorProduct product = CardGeneratorProduct.HTML;
        if (params.containsKey("product")) {
            product = CardGeneratorProduct.valueOf(params.remove("product").toUpperCase());
        }

        Locale targetLanguage = null;
        if (params.containsKey("output-language")) {
            targetLanguage = Locale.forLanguageTag(params.remove("output-language"));
        }

        File dictionary = null;
        if (params.containsKey("path-to-dictionary")) {
            dictionary = new File(params.remove("path-to-dictionary"));
        }

        generator.generate(data, targetLanguage, dictionary, product);

    }
}

From source file:at.porscheinformatik.common.spring.web.extended.util.LocaleUtils.java

public static Locale closestSupportedLocale(List<Locale> supportedLocales, String languageTag) {
    Locale locale = languageTag != null ? Locale.forLanguageTag(languageTag) : null;

    return closestSupportedLocale(supportedLocales, locale);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Locale getLocaleForLanguageTag(@Nullable String locale) {
    Locale parsedLocale = Locale.getDefault();
    if (!TextUtils.isEmpty(locale)) {
        try {/*w w w. ja  v  a  2 s . c o  m*/
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                parsedLocale = Locale.forLanguageTag(locale);
            } else {
                parsedLocale = new Locale(locale);
            }
        } catch (Exception e) {
            Log.d(TAG, "Failed to parse locale " + locale + ". Defaulting to " + parsedLocale);
        }
    }
    return parsedLocale;
}

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

private static Locale getLocale(ResourceBundle rb) {
    try {/*from  w  ww .  ja v a2 s . com*/
        String tag = rb.getString("locale.tag");
        return Locale.forLanguageTag(tag);
    } catch (MissingResourceException e) {
        return Locale.getDefault();
    }
}

From source file:nu.yona.server.batch.quartz.jobs.PinResetConfirmationCodeSenderQuartzJob.java

private static Locale getLocale(Map<String, Object> parameterMap) {
    return Locale.forLanguageTag((String) parameterMap.get(LOCALE_STRING_KEY));
}

From source file:org.mayocat.rest.jackson.LocaleBCP47LanguageTagDeserializer.java

@Override
public Locale deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    String str = jsonParser.getText().trim();
    if (Strings.isNullOrEmpty(str)) {
        return null;
    }// w w  w . ja  v  a  2 s  .  c o  m

    return Locale.forLanguageTag(str);
}

From source file:com.anysoftkeyboard.utils.CompatUtils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Locale getLocaleForLanguageTag(@Nullable String locale) {
    Locale parsedLocale = Locale.getDefault();
    if (!TextUtils.isEmpty(locale)) {
        try {/*from w ww .  jav  a2  s .co  m*/
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                parsedLocale = Locale.forLanguageTag(locale);
            } else {
                parsedLocale = new Locale(locale);
            }
        } catch (Exception e) {
            Log.d(TAG, "Failed to parse locale '%s'. Defaulting to %s", parsedLocale);
        }
    }
    return parsedLocale;
}

From source file:us.askplatyp.kb.lucene.model.LanguageTaggedString.java

@JsonCreator
public LanguageTaggedString(@JsonProperty("@value") String value,
        @JsonProperty("@language") String languageCode) {
    this.value = value;
    this.locale = Locale.forLanguageTag(languageCode);
}