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:de.viaboxx.nlstools.formats.BundleWriter.java
public static Properties createProperties(String locale, MBBundle bundle, boolean merged, boolean debugMode, Task task) {//from w w w. j av a 2 s . c om Iterator<MBEntry> entries = bundle.getEntries().iterator(); Properties p = new Properties(); while (entries.hasNext()) { MBEntry eachEntry = entries.next(); String key = eachEntry.getKey(); MBText langText = eachEntry.getText(locale); if (langText == null && merged && !StringUtils.isEmpty(locale)) { List<Locale> locales = LocaleUtils.localeLookupList(LocaleUtils.toLocale(locale)); // start with i=1 because locales.get(0) has already been tried - it is the 'locale' itself. for (int i = 1; i < locales.size(); i++) { // try to find from parent. begin with next specific Locale each = locales.get(i); langText = eachEntry.getText(each.toString()); if (langText != null) break; } if (langText == null) langText = eachEntry.getText(""); } if (langText != null) { String value; // in debug mode the keys are also displayed as labels if (!debugMode) { value = langText.getValue(); } else { value = key; } // Continue text at line breaks followed by whitespaces (indentations due to code formatter etc.) int indentIndex; while (value != null && (indentIndex = value.indexOf("\n ")) > -1) { int lastBlankIndex = indentIndex + 1; while (lastBlankIndex + 1 < value.length() && Character.isWhitespace(value.charAt(lastBlankIndex + 1))) { lastBlankIndex++; } value = value.substring(0, indentIndex) + ' ' + value.substring(lastBlankIndex + 1); } task.log("'" + key + "' ==> '" + value + "'", Project.MSG_DEBUG); if (key != null && value != null) { p.setProperty(key, value); } } } return p; }
From source file:org.ofbiz.common.JsLanguageFileMappingCreator.java
public static Map<String, Object> createJsLanguageFileMapping(DispatchContext ctx, Map<String, ?> context) { Map<String, Object> result = ServiceUtil.returnSuccess(); String encoding = (String) context.get("encoding"); // default value: UTF-8 List<Locale> localeList = UtilMisc.availableLocales(); Map<String, Object> jQueryLocaleFile = new LinkedHashMap<String, Object>(); Map<String, String> dateJsLocaleFile = new LinkedHashMap<String, String>(); Map<String, String> validationLocaleFile = new LinkedHashMap<String, String>(); Map<String, String> dateTimePickerLocaleFile = new LinkedHashMap<String, String>(); // setup some variables to locate the js files String componentRoot = "component://images/webapp"; String jqueryUiLocaleRelPath = "/images/jquery/ui/i18n/"; String dateJsLocaleRelPath = "/images/jquery/plugins/datejs/"; String validateRelPath = "/images/jquery/plugins/validate/localization/"; String dateTimePickerJsLocaleRelPath = "/images/jquery/plugins/datetimepicker/localization/"; String jsFilePostFix = ".js"; String dateJsLocalePrefix = "date-"; String validateLocalePrefix = "messages_"; //String validateMethLocalePrefix = "methods__"; String jqueryUiLocalePrefix = "jquery.ui.datepicker-"; String dateTimePickerPrefix = "jquery-ui-timepicker-"; String defaultLocaleDateJs = "en-US"; String defaultLocaleJquery = "en"; // Beware to keep the OFBiz specific jquery.ui.datepicker-en.js file when upgrading... for (Locale locale : localeList) { String displayCountry = locale.toString(); String modifiedDisplayCountry = null; String modifiedDisplayCountryForValidation = null; if (displayCountry.contains("_")) { modifiedDisplayCountry = displayCountry.replace("_", "-"); modifiedDisplayCountryForValidation = displayCountry; // messages*.js use "_" not "-" as others } else {//w w w .j av a2s .c o m modifiedDisplayCountry = displayCountry; } String strippedLocale = locale.getLanguage(); File file = null; String fileUrl = null; /* * Try to open the date-js language file */ String fileName = componentRoot + dateJsLocaleRelPath + dateJsLocalePrefix + modifiedDisplayCountry + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateJsLocaleRelPath + dateJsLocalePrefix + modifiedDisplayCountry + jsFilePostFix; } else { // Try to guess a language String tmpLocale = strippedLocale + "-" + strippedLocale.toUpperCase(); fileName = componentRoot + dateJsLocaleRelPath + dateJsLocalePrefix + tmpLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateJsLocaleRelPath + dateJsLocalePrefix + tmpLocale + jsFilePostFix; } else { // use language en-US as fallback fileUrl = dateJsLocaleRelPath + dateJsLocalePrefix + defaultLocaleDateJs + jsFilePostFix; } } dateJsLocaleFile.put(displayCountry, fileUrl); /* * Try to open the jquery validation language file */ if (modifiedDisplayCountryForValidation != null) { // Try 1st lang_country fileName = componentRoot + validateRelPath + validateLocalePrefix + modifiedDisplayCountryForValidation + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = validateRelPath + validateLocalePrefix + modifiedDisplayCountryForValidation + jsFilePostFix; } else { // lang only fileName = componentRoot + validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; } else { // use default language en as fallback fileUrl = validateRelPath + validateLocalePrefix + defaultLocaleJquery + jsFilePostFix; } } } else { // Then try lang only fileName = componentRoot + validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; } else { // use default language en as fallback fileUrl = validateRelPath + validateLocalePrefix + defaultLocaleJquery + jsFilePostFix; } } validationLocaleFile.put(displayCountry, fileUrl); /* * Try to open the jquery timepicker language file */ fileName = componentRoot + jqueryUiLocaleRelPath + jqueryUiLocalePrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = jqueryUiLocaleRelPath + jqueryUiLocalePrefix + strippedLocale + jsFilePostFix; } else { // Try to guess a language fileName = componentRoot + jqueryUiLocaleRelPath + jqueryUiLocalePrefix + modifiedDisplayCountry + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = jqueryUiLocaleRelPath + jqueryUiLocalePrefix + modifiedDisplayCountry + jsFilePostFix; } else { // use default language en as fallback fileUrl = jqueryUiLocaleRelPath + jqueryUiLocalePrefix + defaultLocaleJquery + jsFilePostFix; } } jQueryLocaleFile.put(displayCountry, fileUrl); /* * Try to open the datetimepicker language file */ fileName = componentRoot + dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + strippedLocale + jsFilePostFix; } else { // Try to guess a language fileName = componentRoot + dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + modifiedDisplayCountry + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + modifiedDisplayCountry + jsFilePostFix; } else { // use default language en as fallback fileUrl = dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + defaultLocaleJquery + jsFilePostFix; } } dateTimePickerLocaleFile.put(displayCountry, fileUrl); } // check the template file String template = "framework/common/template/JsLanguageFilesMapping.ftl"; String output = "framework/common/src/org/ofbiz/common/JsLanguageFilesMapping.java"; Map<String, Object> mapWrapper = new HashMap<String, Object>(); mapWrapper.put("datejs", dateJsLocaleFile); mapWrapper.put("jquery", jQueryLocaleFile); mapWrapper.put("validation", validationLocaleFile); mapWrapper.put("dateTime", dateTimePickerLocaleFile); // some magic to create a new java file: render it as FTL Writer writer = new StringWriter(); try { FreeMarkerWorker.renderTemplateAtLocation(template, mapWrapper, writer); // write it as a Java file File file = new File(output); FileUtils.writeStringToFile(file, writer.toString(), encoding); } catch (Exception e) { Debug.logError(e, module); return ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage()); } return result; }
From source file:org.apache.ofbiz.common.JsLanguageFileMappingCreator.java
public static Map<String, Object> createJsLanguageFileMapping(DispatchContext ctx, Map<String, ?> context) { Map<String, Object> result = ServiceUtil.returnSuccess(); String encoding = (String) context.get("encoding"); // default value: UTF-8 List<Locale> localeList = UtilMisc.availableLocales(); Map<String, Object> jQueryLocaleFile = new LinkedHashMap<String, Object>(); Map<String, String> dateJsLocaleFile = new LinkedHashMap<String, String>(); Map<String, String> validationLocaleFile = new LinkedHashMap<String, String>(); Map<String, String> dateTimePickerLocaleFile = new LinkedHashMap<String, String>(); // setup some variables to locate the js files String componentRoot = "component://images/webapp"; String jqueryUiLocaleRelPath = "/images/jquery/ui/i18n/"; String dateJsLocaleRelPath = "/images/jquery/plugins/datejs/"; String validateRelPath = "/images/jquery/plugins/validate/localization/"; String dateTimePickerJsLocaleRelPath = "/images/jquery/plugins/datetimepicker/localization/"; String jsFilePostFix = ".js"; String dateJsLocalePrefix = "date-"; String validateLocalePrefix = "messages_"; String jqueryUiLocalePrefix = "jquery.ui.datepicker-"; String dateTimePickerPrefix = "jquery-ui-timepicker-"; String defaultLocaleDateJs = "en-US"; String defaultLocaleJquery = "en"; // Beware to keep the OFBiz specific jquery.ui.datepicker-en.js file when upgrading... for (Locale locale : localeList) { String displayCountry = locale.toString(); String modifiedDisplayCountry = null; String modifiedDisplayCountryForValidation = null; if (displayCountry.contains("_")) { modifiedDisplayCountry = displayCountry.replace("_", "-"); modifiedDisplayCountryForValidation = displayCountry; // messages*.js use "_" not "-" as others } else {// w ww . ja v a2 s . c o m modifiedDisplayCountry = displayCountry; } String strippedLocale = locale.getLanguage(); File file = null; String fileUrl = null; /* * Try to open the date-js language file */ String fileName = componentRoot + dateJsLocaleRelPath + dateJsLocalePrefix + modifiedDisplayCountry + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateJsLocaleRelPath + dateJsLocalePrefix + modifiedDisplayCountry + jsFilePostFix; } else { // Try to guess a language String tmpLocale = strippedLocale + "-" + strippedLocale.toUpperCase(); fileName = componentRoot + dateJsLocaleRelPath + dateJsLocalePrefix + tmpLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateJsLocaleRelPath + dateJsLocalePrefix + tmpLocale + jsFilePostFix; } else { // use language en-US as fallback fileUrl = dateJsLocaleRelPath + dateJsLocalePrefix + defaultLocaleDateJs + jsFilePostFix; } } dateJsLocaleFile.put(displayCountry, fileUrl); /* * Try to open the jquery validation language file */ if (modifiedDisplayCountryForValidation != null) { // Try 1st lang_country fileName = componentRoot + validateRelPath + validateLocalePrefix + modifiedDisplayCountryForValidation + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = validateRelPath + validateLocalePrefix + modifiedDisplayCountryForValidation + jsFilePostFix; } else { // lang only fileName = componentRoot + validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; } else { // use default language en as fallback fileUrl = validateRelPath + validateLocalePrefix + defaultLocaleJquery + jsFilePostFix; } } } else { // Then try lang only fileName = componentRoot + validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = validateRelPath + validateLocalePrefix + strippedLocale + jsFilePostFix; } else { // use default language en as fallback fileUrl = validateRelPath + validateLocalePrefix + defaultLocaleJquery + jsFilePostFix; } } validationLocaleFile.put(displayCountry, fileUrl); /* * Try to open the jquery timepicker language file */ fileName = componentRoot + jqueryUiLocaleRelPath + jqueryUiLocalePrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = jqueryUiLocaleRelPath + jqueryUiLocalePrefix + strippedLocale + jsFilePostFix; } else { // Try to guess a language fileName = componentRoot + jqueryUiLocaleRelPath + jqueryUiLocalePrefix + modifiedDisplayCountry + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = jqueryUiLocaleRelPath + jqueryUiLocalePrefix + modifiedDisplayCountry + jsFilePostFix; } else { // use default language en as fallback fileUrl = jqueryUiLocaleRelPath + jqueryUiLocalePrefix + defaultLocaleJquery + jsFilePostFix; } } jQueryLocaleFile.put(displayCountry, fileUrl); /* * Try to open the datetimepicker language file */ fileName = componentRoot + dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + strippedLocale + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + strippedLocale + jsFilePostFix; } else { // Try to guess a language fileName = componentRoot + dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + modifiedDisplayCountry + jsFilePostFix; file = FileUtil.getFile(fileName); if (file.exists()) { fileUrl = dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + modifiedDisplayCountry + jsFilePostFix; } else { // use default language en as fallback fileUrl = dateTimePickerJsLocaleRelPath + dateTimePickerPrefix + defaultLocaleJquery + jsFilePostFix; } } dateTimePickerLocaleFile.put(displayCountry, fileUrl); } // check the template file String template = "framework/common/template/JsLanguageFilesMapping.ftl"; String output = "framework/common/src/org/apache/ofbiz/common/JsLanguageFilesMapping.java"; Map<String, Object> mapWrapper = new HashMap<String, Object>(); mapWrapper.put("datejs", dateJsLocaleFile); mapWrapper.put("jquery", jQueryLocaleFile); mapWrapper.put("validation", validationLocaleFile); mapWrapper.put("dateTime", dateTimePickerLocaleFile); // some magic to create a new java file: render it as FTL Writer writer = new StringWriter(); try { FreeMarkerWorker.renderTemplate(template, mapWrapper, writer); // write it as a Java file File file = new File(output); FileUtils.writeStringToFile(file, writer.toString(), encoding); } catch (Exception e) { Debug.logError(e, module); return ServiceUtil .returnError(UtilProperties.getMessage("CommonUiLabels", "CommonOutputFileCouldNotBeCreated", UtilMisc.toMap("errorString", e.getMessage()), (Locale) context.get("locale"))); } return result; }
From source file:org.apereo.portal.i18n.LocaleManager.java
/** * Constructs a comma-delimited list of locales * that could be parsed back into a Locale * array with parseLocales(String localeStringList). * @param locales the list of locales/*w ww . j av a2 s .c o m*/ * @return a string representing the list of locales */ public static String stringValueOf(Locale[] locales) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < locales.length; i++) { Locale locale = locales[i]; sb.append(locale.toString()); if (i < locales.length - 1) { sb.append(","); } } return sb.toString(); }
From source file:org.nuxeo.ecm.webapp.directory.VocabularyTreeNode.java
public static String computeLabel(Locale locale, DocumentModel entry, String schemaName) { if (entry == null) { return null; }// w w w .ja va2 s. co m String fieldName = LABEL_FIELD_PREFIX + locale.toString(); String label = null; try { label = (String) entry.getProperty(schemaName, fieldName); } catch (PropertyException e) { } if (label == null) { fieldName = LABEL_FIELD_PREFIX + locale.getLanguage(); try { label = (String) entry.getProperty(schemaName, fieldName); } catch (PropertyException e) { } } if (label == null) { fieldName = LABEL_FIELD_PREFIX + DEFAULT_LANGUAGE; try { label = (String) entry.getProperty(schemaName, fieldName); } catch (PropertyException e) { } } return label; }
From source file:password.pwm.ws.client.rest.RestClientHelper.java
public static String makeOutboundRestWSCall(final PwmApplication pwmApplication, final Locale locale, final String url, final String jsonRequestBody) throws PwmOperationalException, PwmUnrecoverableException { final HttpPost httpPost = new HttpPost(url); httpPost.setHeader("Accept", PwmConstants.AcceptValue.json.getHeaderValue()); if (locale != null) { httpPost.setHeader("Accept-Locale", locale.toString()); }//from ww w .j a v a 2s. co m httpPost.setHeader("Content-Type", PwmConstants.ContentTypeValue.json.getHeaderValue()); final HttpResponse httpResponse; try { final StringEntity stringEntity = new StringEntity(jsonRequestBody); stringEntity.setContentType(PwmConstants.AcceptValue.json.getHeaderValue()); httpPost.setEntity(stringEntity); LOGGER.debug("beginning external rest call to: " + httpPost.toString() + ", body: " + jsonRequestBody); httpResponse = PwmHttpClient.getHttpClient(pwmApplication.getConfig()).execute(httpPost); final String responseBody = EntityUtils.toString(httpResponse.getEntity()); LOGGER.trace("external rest call returned: " + httpResponse.getStatusLine().toString() + ", body: " + responseBody); if (httpResponse.getStatusLine().getStatusCode() != 200) { final String errorMsg = "received non-200 response code (" + httpResponse.getStatusLine().getStatusCode() + ") when executing web-service"; LOGGER.error(errorMsg); throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg)); } return responseBody; } catch (IOException e) { final String errorMsg = "http response error while executing external rest call, error: " + e.getMessage(); LOGGER.error(errorMsg); throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg), e); } }
From source file:net.ymate.platform.commons.i18n.I18N.java
/** * @param locale//from w w w . j a v a 2 s. c om * @param resourceName * @return ???? */ protected static List<String> resourceNames(Locale locale, String resourceName) { List<String> _names = new ArrayList<String>(); _names.add(resourceName + ".properties"); String _localeKey = (locale == null) ? "" : locale.toString(); if (_localeKey.length() > 0) { resourceName += ("_" + _localeKey); } _names.add(0, resourceName += ".properties"); return _names; }
From source file:NumberFormatDemo.java
static public void displayNumber(Locale currentLocale) { Integer quantity = new Integer(123456); Double amount = new Double(345987.246); NumberFormat numberFormatter; String quantityOut;/*w w w .ja v a2s .c o m*/ String amountOut; numberFormatter = NumberFormat.getNumberInstance(currentLocale); quantityOut = numberFormatter.format(quantity); amountOut = numberFormatter.format(amount); System.out.println(quantityOut + " " + currentLocale.toString()); System.out.println(amountOut + " " + currentLocale.toString()); }
From source file:marytts.server.MaryProperties.java
/** * Provide the config file prefix used for different locales in the * config files. Will return the string representation of the locale * as produced by locale.toString(), e.g. "en_GB"; * if locale is null, return null.//ww w .ja va 2 s. c o m * @param locale * @return */ public static String localePrefix(Locale locale) { if (locale == null) return null; return locale.toString(); }
From source file:org.jahia.utils.LanguageCodeConverters.java
public static List<String> localesToLanguageCodes(List<Locale> locales) { if (locales == null) { return null; }/*from w ww . j a v a2s . c om*/ if (locales.isEmpty()) { return new ArrayList<String>(); } List<String> languageCodes = new ArrayList<String>(locales.size()); for (Locale locale : locales) { languageCodes.add(locale.toString()); } return languageCodes; }