Java Code Examples for java.util.Locale.forLanguageTag()

The following are Jave code examples for showing how to use forLanguageTag() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: bskyblock   File: BSBLocale.java   View Source Code Vote up 6 votes
/**
 * Provides localization
 * Locale files are .yml and have the filename "bsb_[country and language tag].yml", e.g. bsb_en_GB.yml
 * @param plugin
 * @throws MalformedURLException
 */
public BSBLocale(Plugin plugin, String localeId) throws MalformedURLException {
    this.plugin = plugin;
    //this.localeId = localeId;
    // Check if the folder exists
    File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER);
    if (!localeDir.exists()) {
        localeDir.mkdirs();
    }
    // Check if this file does not exist
    File localeFile = new File(localeDir, localeId);
    if (!localeFile.exists()) {
        // Does not exist - look in JAR and save if possible
        plugin.saveResource(LOCALE_FOLDER + localeId, false);
    }
    languageTag = localeId.substring(4, localeId.length() - 4).replace('_', '-');
    URL[] urls = {localeDir.toURI().toURL()};
    ClassLoader loader = new URLClassLoader(urls);
    localeObject = Locale.forLanguageTag(languageTag);
    rb = ResourceBundle.getBundle("bsb", localeObject, loader, YamlResourceBundle.Control.INSTANCE);
}
 
Example 2
Project: Microservices-with-JHipster-and-Spring-Boot   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendCreationEmail(User user) {
    log.debug("Sending creation email to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("creationEmail", context);
    String subject = messageSource.getMessage("email.activation.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 3
Project: patient-portal   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process(templateName, context);
    String subject = messageSource.getMessage(titleKey, null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);

}
 
Example 4
Project: openjdk-jdk10   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testBug7023613() {
    String[][] testdata = {
        {"en-Latn", "en__#Latn"},
        {"en-u-ca-japanese", "en__#u-ca-japanese"},
    };

    for (String[] data : testdata) {
        String in = data[0];
        String expected = (data.length == 1) ? data[0] : data[1];

        Locale loc = Locale.forLanguageTag(in);
        String out = loc.toString();
        assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out);
    }
}
 
Example 5
Project: Code4Health-Platform   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendSocialRegistrationValidationEmail(User user, String provider) {
    log.debug("Sending social registration validation e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable("provider", StringUtils.capitalize(provider));
    String content = templateEngine.process("socialRegistrationValidationEmail", context);
    String subject = messageSource.getMessage("email.social.registration.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 6
Project: MTC_Labrat   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendActivationEmail(User user) {
    log.debug("Sending activation email to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("activationEmail", context);
    String subject = messageSource.getMessage("email.activation.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 7
Project: shoucang   File: MailService.java   View Source Code Vote up 5 votes
@Async
    public void sendActivationEmail(User user, String baseUrl) {
        log.debug("Sending activation e-mail to '{}'", user.getEmail());
        Locale locale = Locale.forLanguageTag(user.getLangKey());
        Context context = new Context(locale);
        context.setVariable("user", user);
        context.setVariable("baseUrl", baseUrl);
        String content = templateEngine.process("activationEmail", context);
        String subject = messageSource.getMessage("email.activation.title", null, locale);
//        sendEmail(user.getEmail(), subject, content, false, true);
        sendMailToQueue(user.getEmail(), subject, content, false, true);
    }
 
Example 8
Project: speakTogether   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendPasswordResetMail(User user) {
    log.debug("Sending password reset e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("passwordResetEmail", context);
    String subject = messageSource.getMessage("email.reset.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 9
Project: MTC_Labrat   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendSocialRegistrationValidationEmail(User user, String provider) {
    log.debug("Sending social registration validation email to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable("provider", StringUtils.capitalize(provider));
    String content = templateEngine.process("socialRegistrationValidationEmail", context);
    String subject = messageSource.getMessage("email.social.registration.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 10
Project: openjdk-jdk10   File: Main.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    int errors = 0;
    for (String loctag : args) {
        Locale locale = Locale.forLanguageTag(loctag);
        if (locale.equals(Locale.ROOT)) {
            continue;
        }
        ResourceBundle rb = ResourceBundle.getBundle("jdk.test.resources.MyResources",
                                                     locale);
        String tag = locale.toLanguageTag(); // normalized
        String value = rb.getString("key");
        System.out.println(rb.getBaseBundleName() + ": locale = " + tag + ", value = " + value);
        if (!value.startsWith(tag + ':')) {
            System.out.println("ERROR: " + value + " expected: " + tag);
            errors++;
        }

        // inaccessible bundles
        try {
            ResourceBundle.getBundle("jdk.test.internal.resources.Foo", locale);
            System.out.println("ERROR: jdk.test.internal.resources.Foo should not be accessible");
            errors++;
        } catch (MissingResourceException e) {
            e.printStackTrace();

            Throwable cause = e.getCause();
            System.out.println("Expected: " +
                (cause != null ? cause.getMessage() : e.getMessage()));
        }
    }
    if (errors > 0) {
        throw new RuntimeException(errors + " errors");
    }
}
 
Example 11
Project: Code4Health-Platform   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendPasswordResetMail(User user) {
    log.debug("Sending password reset e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("passwordResetEmail", context);
    String subject = messageSource.getMessage("email.reset.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 12
Project: OpenJSharp   File: CLDRLocaleProviderAdapter.java   View Source Code Vote up 5 votes
@Override
public Locale[] getAvailableLocales() {
    Set<String> all = createLanguageTagSet("All");
    Locale[] locs = new Locale[all.size()];
    int index = 0;
    for (String tag : all) {
        locs[index++] = Locale.forLanguageTag(tag);
    }
    return locs;
}
 
Example 13
Project: oscm   File: ImportUserHandler.java   View Source Code Vote up 5 votes
/**
 * Replace place-holders like {0} with parameters. Use key if no message is
 * available
 */
String formatMessage(String text, SaaSApplicationException e, String locale) {
    if (Strings.isEmpty(text)) {
        text = e.getMessageKey();
        logger.logWarn(Log4jLogger.SYSTEM_LOG, e,
                LogMessageIdentifier.ERROR_BULK_USER_IMPORT_FAILED,
                payload.getInfo());
    }
    MessageFormat mf = new MessageFormat(text,
            Locale.forLanguageTag(locale));
    String errorMessage = mf.format(e.getMessageParams(),
            new StringBuffer(), null).toString();
    return errorMessage;
}
 
Example 14
Project: openjdk-jdk10   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testPrivateUseExtension() {
    Locale locale = Locale.forLanguageTag("x-y-x-blork-");
    assertEquals("blork", "y-x-blork", locale.getExtension(Locale.PRIVATE_USE_EXTENSION));

    locale = Locale.forLanguageTag("und");
    assertEquals("no privateuse", null, locale.getExtension(Locale.PRIVATE_USE_EXTENSION));
}
 
Example 15
Project: FontProvider   File: FontPreviewActivity.java   View Source Code Vote up 5 votes
private void onLocaleChanged(int localeIndex) {
    mLocaleIndex = localeIndex;

    if (mFontInfo.getLanguage()[0] != null) {
        Locale locale = Locale.forLanguageTag(mFontInfo.getLanguage()[mLocaleIndex]);

        if (getActionBar() != null) {
            getActionBar().setSubtitle(locale.getDisplayName());
        }
    }

    mAdapter.setLocaleIndex(mLocaleIndex);
    mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount(), new Object());
}
 
Example 16
Project: jdk8u-jdk   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testGetDisplayScriptWithLocale() {
    Locale latnLocale = Locale.forLanguageTag("und-latn");
    Locale hansLocale = Locale.forLanguageTag("und-hans");

    assertEquals("latn US", "Latin", latnLocale.getDisplayScript(Locale.US));
    assertEquals("hans US", "Simplified Han", hansLocale.getDisplayScript(Locale.US));

    assertEquals("latn DE", "Lateinisch", latnLocale.getDisplayScript(Locale.GERMANY));
    assertEquals("hans DE", "Vereinfachte Chinesische Schrift", hansLocale.getDisplayScript(Locale.GERMANY));
}
 
Example 17
Project: speakTogether   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendActivationEmail(User user) {
    log.debug("Sending activation e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("activationEmail", context);
    String subject = messageSource.getMessage("email.activation.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 18
Project: devoxxus-jhipster-microservices-demo   File: MailService.java   View Source Code Vote up 5 votes
@Async
public void sendActivationEmail(User user) {
    log.debug("Sending activation e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("activationEmail", context);
    String subject = messageSource.getMessage("email.activation.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
 
Example 19
Project: minijax   File: MinijaxHttpHeaders.java   View Source Code Vote up 4 votes
@Override
public Locale getLanguage() {
    final String languageTag = getHeaderString("Content-Language");
    return languageTag == null ? null : Locale.forLanguageTag(languageTag);
}
 
Example 20
Project: daelic   File: TimeFormatExtractionFn.java   View Source Code Vote up 4 votes
public TimeFormatExtractionFnBuilder withLocale(String locale) {
    this.locale = Locale.forLanguageTag(locale);
    return this;
}