本文整理汇总了Java中java.util.Locale.forLanguageTag方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.forLanguageTag方法的具体用法?Java Locale.forLanguageTag怎么用?Java Locale.forLanguageTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.forLanguageTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BSBLocale
import java.util.Locale; //导入方法依赖的package包/类
/**
* 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);
}
示例2: getAvailableLocales
import java.util.Locale; //导入方法依赖的package包/类
@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;
}
示例3: sendCreationEmail
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例4: sendEmailFromTemplate
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例5: testBug7023613
import java.util.Locale; //导入方法依赖的package包/类
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);
}
}
示例6: sendSocialRegistrationValidationEmail
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例7: sendActivationEmail
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例8: sendActivationEmail
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例9: sendPasswordResetMail
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例10: sendSocialRegistrationValidationEmail
import java.util.Locale; //导入方法依赖的package包/类
@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);
}
示例11: main
import java.util.Locale; //导入方法依赖的package包/类
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");
}
}
示例12: formatMessage
import java.util.Locale; //导入方法依赖的package包/类
/**
* 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;
}
示例13: testPrivateUseExtension
import java.util.Locale; //导入方法依赖的package包/类
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));
}
示例14: onLocaleChanged
import java.util.Locale; //导入方法依赖的package包/类
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());
}
示例15: testGetDisplayScriptWithLocale
import java.util.Locale; //导入方法依赖的package包/类
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));
}