List of usage examples for java.util Locale toString
@Override public final String toString()
Locale
object, consisting of language, country, variant, script, and extensions as below: language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensionsLanguage is always lower case, country is always upper case, script is always title case, and extensions are always lower case.
From source file:org.echocat.jomon.runtime.i18n.ResourceBundles.java
@Nonnull private static String asString(@Nullable Locale locale) { return locale != null ? locale.toString() : ""; }
From source file:org.opendatakit.common.android.utilities.ODKDataUtils.java
@SuppressWarnings("unchecked") public static String getLocalizedDisplayName(String displayName) { Locale locale = Locale.getDefault(); String full_locale = locale.toString(); int underscore = full_locale.indexOf('_'); String lang_only_locale = (underscore == -1) ? full_locale : full_locale.substring(0, underscore); if (displayName.startsWith("\"") && displayName.endsWith("\"")) { return displayName.substring(1, displayName.length() - 1); } else if (displayName.startsWith("{") && displayName.endsWith("}")) { try {//from w w w . java 2 s .c o m Map<String, Object> localeMap = ODKFileUtils.mapper.readValue(displayName, Map.class); String candidate = (String) localeMap.get(full_locale); if (candidate != null) { return candidate; } candidate = (String) localeMap.get(lang_only_locale); if (candidate != null) { return candidate; } candidate = (String) localeMap.get("default"); if (candidate != null) { return candidate; } return null; } catch (JsonParseException e) { e.printStackTrace(); throw new IllegalStateException("bad displayName: " + displayName); } catch (JsonMappingException e) { e.printStackTrace(); throw new IllegalStateException("bad displayName: " + displayName); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException("bad displayName: " + displayName); } } else { throw new IllegalStateException("bad displayName: " + displayName); } }
From source file:org.eclipse.wb.internal.core.nls.ui.FlagImagesRepository.java
private static void init() { if (m_locales == null) { // prepare sorted Locale's {/* w w w . ja va2 s. c om*/ List<Locale> locales = Lists.newArrayList(); Collections.addAll(locales, Locale.getAvailableLocales()); Collections.sort(locales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.toString().compareTo(o2.toString()); } }); m_locales = locales.toArray(new Locale[locales.size()]); } } }
From source file:Main.java
/** * get a descriptions of all the languages available as determined by * {@link TextToSpeech#isLanguageAvailable(Locale)} *//*from w ww . java 2 s .c om*/ public static String getLanguageAvailableDescription(TextToSpeech tts) { StringBuilder sb = new StringBuilder(); for (Locale loc : Locale.getAvailableLocales()) { int availableCheck = tts.isLanguageAvailable(loc); sb.append(loc.toString()).append(" "); switch (availableCheck) { case TextToSpeech.LANG_AVAILABLE: break; case TextToSpeech.LANG_COUNTRY_AVAILABLE: sb.append("COUNTRY_AVAILABLE"); break; case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: sb.append("COUNTRY_VAR_AVAILABLE"); break; case TextToSpeech.LANG_MISSING_DATA: sb.append("MISSING_DATA"); break; case TextToSpeech.LANG_NOT_SUPPORTED: sb.append("NOT_SUPPORTED"); break; } sb.append(NEW_LINE); } return sb.toString(); }
From source file:edu.jhuapl.openessence.i18n.SupportedLocale.java
/** * @param messageSource to translate displayLanguage *//* ww w. j a v a 2 s . c o m*/ public static SupportedLocale fromLocale(Locale locale, MessageSource messageSource) { SupportedLocale sl = new SupportedLocale(); sl.setCode(locale.toString()); // display language in target locale, i.e. "espaol" instead of "Spanish" String defaultDisplayLanguage = locale.getDisplayLanguage(locale); // Java doesn't have every language display name in every language // (e.g. doesn't have "Khmer" in Khmer), so use message bundle as fallback String lang = messageSource.getMessage("language." + locale.getLanguage(), null, defaultDisplayLanguage, locale); sl.setDisplayLanguage(lang); return sl; }
From source file:com.esofthead.mycollab.i18n.LocalizationHelper.java
public static String templatePath(String fileTemplatePath, Locale locale) { String key = (locale != null) ? (fileTemplatePath + locale.toString()) : (fileTemplatePath + Locale.US.toString()); String filePath = cacheFile.get(key); if (filePath != null) { return filePath; } else {//from ww w. ja va 2s . c o m int index = fileTemplatePath.indexOf("mt"); if (index == -1) { throw new MyCollabException("File type is not supported " + fileTemplatePath); } filePath = fileTemplatePath.substring(0, index - 1); filePath = String.format("%s_%s.mt", filePath, locale); cacheFile.put(key, filePath); return filePath; } }
From source file:net.ymate.platform.mvc.web.WebMVC.java
/** * ?WebMVC?// ww w . j a va2 s . co m * * @param config */ public static void initialize(IWebMvcConfig config) { __doInitialize(config, new WebRequestProcessor()); if (config.isI18n()) { final String _localKey = StringUtils .defaultIfEmpty(config.getExtendParams().get(Optional.I18N_LANGUAGE_KEY), "lang"); I18N.setEventHandler(new II18NEventHandler() { public Locale loadCurrentLocale() { // ??URL??? String _langStr = (String) WebContext.getContext().get(_localKey); if (_langStr == null) { // ???? _langStr = WebContext.getRequest().getParameter(_localKey); if (_langStr == null) { // ???Cookies BlurObject _langCookie = CookieHelper.create().getCookie(_localKey); if (_langCookie != null) { _langStr = _langCookie.toStringValue(); } } } return MVC.localeFromStr(_langStr, MVC.getConfig().getLocale()); } public void onLocaleChanged(Locale locale) { CookieHelper.create().setCookie(_localKey, locale.toString()); } public InputStream onLoadProperties(String resourceName) throws IOException { if (Cfgs.isInited()) { File _resourcefile = Cfgs.search("i18n/" + resourceName); if (_resourcefile != null) { return new FileInputStream(_resourcefile); } } return null; } }); } }
From source file:org.gatein.api.Util.java
public static String fromLocale(Locale locale) { return locale.toString(); }
From source file:PropertiesDemo.java
static void displayValue(Locale currentLocale, String key) { ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale); String value = labels.getString(key); System.out.println(//ww w . j a v a 2s .c o m "Locale = " + currentLocale.toString() + ", " + "key = " + key + ", " + "value = " + value); }
From source file:jp.co.conit.sss.sn.ex2.util.SNApiUtil.java
/** * SamuraiNotification?messagesAPI???????<br> * ??????????????/* w w w .j a va 2 s .c o m*/ * * @param tag * @return */ public static SNServerResult messages(String tag) { SNServerResult result = new SNServerResult(); StringBuilder sb = new StringBuilder(); sb.append(SN_DOMAIN); sb.append(SN_MESSAGES); sb.append("?token="); sb.append(SN_TOKEN); sb.append("&lang="); Locale locale = Locale.getDefault(); sb.append(locale.toString()); if (!StringUtil.isEmpty(tag)) { sb.append("&tags="); sb.append(tag); } return get(sb.toString(), result); }