List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:br.msf.commons.util.LocaleUtils.java
/** * Returns the given locale, or the system defaults if the given one is null. * * @param preferredLocale/*from w ww . j a v a2s .c o m*/ * @return The given locale, or the system defaults if the given one is null. */ public static Locale getNullSafeLocale(final Locale preferredLocale) { //return preferredLocale == null ? PT_BR_LOCALE : preferredLocale; return preferredLocale == null ? Locale.getDefault() : preferredLocale; }
From source file:adalid.commons.bundles.Bundle.java
private static Locale getLocale(ResourceBundle rb) { try {//from w w w. j a v a2 s . c o m String tag = rb.getString("locale.tag"); return Locale.forLanguageTag(tag); } catch (MissingResourceException e) { return Locale.getDefault(); } }
From source file:Main.java
public synchronized static ResourceBundle loadBundle(String resource) { if (sRefMap == null) { sRefMap = new HashMap<String, SoftReference<ResourceBundle>>(); }//from ww w . ja va2 s.c o m SoftReference<ResourceBundle> bundleRef = sRefMap.get(resource); if (bundleRef == null || bundleRef.get() == null) { // Attempt to load the messages. try { ResourceBundle bundle = setLocale(Locale.getDefault(), resource); bundleRef = new SoftReference<ResourceBundle>(bundle); sRefMap.put(resource, bundleRef); return bundle; } catch (Throwable e) { //Logger.global.warning("Got Throwable " + e + " loading messages"); return null; } } else { return bundleRef.get(); } }
From source file:kaleidoscope.util.HttpUtils.java
public static Locale getLocale(String acceptLanguage) { Locale locale = null;//from w ww .j a va 2 s . c o m if (StringUtils.isEmpty(acceptLanguage) != true) { StringTokenizer langToken = new StringTokenizer(acceptLanguage, ",; "); String language = langToken.nextToken().replace('-', '_'); StringTokenizer localeToken = new StringTokenizer(language, "_"); switch (localeToken.countTokens()) { case 1: locale = new Locale(localeToken.nextToken()); break; case 2: locale = new Locale(localeToken.nextToken(), localeToken.nextToken()); break; case 3: locale = new Locale(localeToken.nextToken(), localeToken.nextToken(), localeToken.nextToken()); break; } } if (locale == null) { locale = Locale.getDefault(); } return locale; }
From source file:com.atlassian.jira.license.LicenseRoleIdTest.java
@Before public void before() { oldDefault = Locale.getDefault(); //Set a Turkish locale. In Turkish "I".toLowerCase(TURKEY) != "i" but rather U+0131 (Latin small letter //dotless i)/*from w w w .j a va 2 s .c o m*/ Locale.setDefault(TURKEY); }
From source file:I18nUtils.java
/** * Convert a string based locale into a Locale Object. * Assumes the string has form "{language}_{country}_{variant}". * Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr_MAC" * /*from w ww . ja v a2 s . c o m*/ * @param localeString The String * @return the Locale */ public static Locale getLocaleFromString(String localeString) { if (localeString == null) { return null; } localeString = localeString.trim(); if (localeString.toLowerCase().equals("default")) { return Locale.getDefault(); } // Extract language int languageIndex = localeString.indexOf('_'); String language = null; if (languageIndex == -1) { // No further "_" so is "{language}" only return new Locale(localeString, ""); } else { language = localeString.substring(0, languageIndex); } // Extract country int countryIndex = localeString.indexOf('_', languageIndex + 1); String country = null; if (countryIndex == -1) { // No further "_" so is "{language}_{country}" country = localeString.substring(languageIndex + 1); return new Locale(language, country); } else { // Assume all remaining is the variant so is "{language}_{country}_{variant}" country = localeString.substring(languageIndex + 1, countryIndex); String variant = localeString.substring(countryIndex + 1); return new Locale(language, country, variant); } }
From source file:Main.java
/** * Returns a formatted string representation of time in <code>milliseconds</code> * @param milliseconds Long value representing the time to be formatted * @return Formatted string representation of time in <code>milliseconds</code> *//*from w w w . j a va2 s. c o m*/ public static String getOfxFormattedTime(long milliseconds) { Date date = new Date(milliseconds); String dateString = OFX_DATE_FORMATTER.format(date); TimeZone tz = Calendar.getInstance().getTimeZone(); int offset = tz.getRawOffset(); int hours = (int) ((offset / (1000 * 60 * 60)) % 24); String sign = offset > 0 ? "+" : ""; return dateString + "[" + sign + hours + ":" + tz.getDisplayName(false, TimeZone.SHORT, Locale.getDefault()) + "]"; }
From source file:com.github.pjungermann.config.validation.ConfigValidationException.java
public static String toMessage(@NotNull final MessageSource messageSource, @NotNull final Collection<ConfigError> errors) { final StringBuilder builder = new StringBuilder("Validation errors:"); for (final ConfigError error : errors) { final String errorMessage = error.toMessage(messageSource, Locale.getDefault()); builder.append("\n- ").append(errorMessage); }/*from w w w . j ava 2 s. co m*/ return builder.toString(); }
From source file:com.fmguler.ven.LiquibaseUtil.java
/** * Build the test database/*from ww w .j a v a 2s .com*/ */ public static void buildDatabase() { try { Locale currLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(getDataSource().getConnection()); Liquibase liquibase = new Liquibase("etc/test-db/test-db-changelog.xml", new FileSystemFileOpener(), database); liquibase.update(""); Locale.setDefault(currLocale); } catch (SQLException ex) { ex.printStackTrace(); } catch (JDBCException ex) { ex.printStackTrace(); } catch (LiquibaseException ex) { ex.printStackTrace(); } }
From source file:com.tonbeller.wcf.format.FormatterFactory.java
private static void fillFormatter(Formatter formatter, Locale locale, URL configXml) { if (locale == null) locale = Locale.getDefault(); URL rulesXml = Formatter.class.getResource("rules.xml"); Digester digester = DigesterLoader.createDigester(rulesXml); digester.setValidating(false);//w ww .j a v a2s . c o m digester.push(formatter); try { digester.parse(new InputSource(configXml.toExternalForm())); } catch (IOException e) { logger.error("exception caught", e); throw new SoftException(e); } catch (SAXException e) { logger.error("exception caught", e); throw new SoftException(e); } formatter.setLocale(locale); }