Java Code Examples for com.ibm.icu.util.ULocale#getCountry()
The following examples show how to use
com.ibm.icu.util.ULocale#getCountry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocaleValidityChecker.java From trekarta with GNU General Public License v3.0 | 6 votes |
/** * @param locale * @param subtag * @return */ private boolean isSubdivision(ULocale locale, String subtag) { // First check if the subtag is valid if (subtag.length() < 3) { return false; } String region = subtag.substring(0, subtag.charAt(0) <= '9' ? 3 : 2); String subdivision = subtag.substring(region.length()); if (ValidIdentifiers.isValid(Datatype.subdivision, datasubtypes, region, subdivision) == null) { return false; } // Then check for consistency with the locale's region String localeRegion = locale.getCountry(); if (localeRegion.isEmpty()) { ULocale max = ULocale.addLikelySubtags(locale); localeRegion = max.getCountry(); } if (!region.equalsIgnoreCase(localeRegion)) { return false; } return true; }
Example 2
Source File: LocaleValidityChecker.java From fitnotifications with Apache License 2.0 | 6 votes |
/** * @param locale * @param subtag * @return */ private boolean isSubdivision(ULocale locale, String subtag) { // First check if the subtag is valid if (subtag.length() < 3) { return false; } String region = subtag.substring(0, subtag.charAt(0) <= '9' ? 3 : 2); String subdivision = subtag.substring(region.length()); if (ValidIdentifiers.isValid(Datatype.subdivision, datasubtypes, region, subdivision) == null) { return false; } // Then check for consistency with the locale's region String localeRegion = locale.getCountry(); if (localeRegion.isEmpty()) { ULocale max = ULocale.addLikelySubtags(locale); localeRegion = max.getCountry(); } if (!region.equalsIgnoreCase(localeRegion)) { return false; } return true; }
Example 3
Source File: LanguageData.java From es6draft with MIT License | 5 votes |
private static Set<String> addDerivedLanguages(List<String> available) { HashSet<String> availableSet = new HashSet<>(available); HashSet<String> derivedSet = new HashSet<>(available); for (ULocale locale : ULocale.getAvailableLocales()) { String languageTag = locale.toLanguageTag(); if (derivedSet.contains(languageTag)) { continue; } if (!(locale.getVariant().isEmpty() && locale.getUnicodeLocaleKeys().isEmpty())) { // Ignore locales with variants or unicode extension sequences. continue; } String language = locale.getLanguage(); if (availableSet.contains(language)) { derivedSet.add(languageTag); continue; } String script = locale.getScript(); if (!script.isEmpty()) { String languageScript = language + "-" + script; if (availableSet.contains(languageScript)) { derivedSet.add(languageTag); continue; } } String country = locale.getCountry(); if (!country.isEmpty()) { String languageCountry = language + "-" + country; if (availableSet.contains(languageCountry)) { derivedSet.add(languageTag); continue; } } } return derivedSet; }
Example 4
Source File: DateTimePatternGenerator.java From fitnotifications with Apache License 2.0 | 5 votes |
private void getAllowedHourFormats(ULocale uLocale) { // key can be either region or locale (lang_region) // ZW{ // allowed{ // "h", // "H", // } // preferred{"h"} // } // af_ZA{ // allowed{ // "h", // "H", // "hB", // "hb", // } // preferred{"h"} // } ULocale max = ULocale.addLikelySubtags(uLocale); String country = max.getCountry(); if (country.isEmpty()) { country = "001"; } String langCountry = max.getLanguage() + "_" + country; String[] list = LOCALE_TO_ALLOWED_HOUR.get(langCountry); if (list == null) { list = LOCALE_TO_ALLOWED_HOUR.get(country); if (list == null) { list = LAST_RESORT_ALLOWED_HOUR_FORMAT; } } allowedHourFormats = list; }
Example 5
Source File: IntlAbstractOperations.java From es6draft with MIT License | 5 votes |
private static ULocale addLikelySubtagsWithDefaults(ULocale locale) { ULocale maximized = ULocale.addLikelySubtags(locale); if (maximized == locale) { // If already in maximal form or no data available for maximization, make sure // language, script and region are not undefined (ICU4J expects all are defined). String language = locale.getLanguage(); String script = locale.getScript(); String region = locale.getCountry(); if (language.isEmpty() || script.isEmpty() || region.isEmpty()) { return new ULocale(toLocaleId(language, script, region)); } } return maximized; }
Example 6
Source File: XLikelySubtags.java From trekarta with GNU General Public License v3.0 | 5 votes |
/** * Implementation of LocaleMatcher.canonicalize(ULocale). */ public ULocale canonicalize(ULocale locale) { String lang = locale.getLanguage(); String lang2 = languageAliases.get(lang); String region = locale.getCountry(); String region2 = regionAliases.get(region); if (lang2 != null || region2 != null) { return new ULocale( lang2 == null ? lang : lang2, locale.getScript(), region2 == null ? region : region2); } return locale; }
Example 7
Source File: LocaleTableGenerator.java From javaide with GNU General Public License v3.0 | 5 votes |
private void importFromIcu4j() { for (ULocale locale : ULocale.getAvailableLocales()) { String language2 = locale.getLanguage(); String language3 = locale.getISO3Language(); if (language3.isEmpty()) { // suspicious; skip this one. Misconfigured ICU? continue; } if (!language2.equals(language3)) { mLanguage2to3.put(language2, language3); } mLanguageName.put(language3, locale.getDisplayLanguage()); String region3 = locale.getISO3Country(); if (region3 != null && !region3.isEmpty()) { mRegionName.put(region3, locale.getDisplayCountry()); String region2 = locale.getCountry(); if (!region3.equals(region2)) { mRegion2to3.put(region2, region3); } if (!mAssociatedRegions.containsEntry(language3, region3)) { mAssociatedRegions.put(language3, region3); } } if (locale.getFallback() != null && !locale.getFallback().toString().isEmpty() && !locale.toString().startsWith(locale.getFallback().toString())) { System.out.println("Fallback for " + locale + " is " + locale.getFallback()); } // TODO: Include this //locale.isRightToLeft() //System.out.println("Locale " + locale.toString() + "; " + locale.getISO3Language() + " : " + locale.getISO3Country() + " : " + locale.getDisplayLanguage() + ", " + locale.getDisplayCountry()); } }
Example 8
Source File: TimeZoneGenericNames.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Private method returning the target region. The target regions is determined by * the locale of this instance. When a generic name is coming from * a meta zone, this region is used for checking if the time zone * is a reference zone of the meta zone. * * @return the target region */ private synchronized String getTargetRegion() { if (_region == null) { _region = _locale.getCountry(); if (_region.length() == 0) { ULocale tmp = ULocale.addLikelySubtags(_locale); _region = tmp.getCountry(); if (_region.length() == 0) { _region = "001"; } } } return _region; }
Example 9
Source File: TZDBTimeZoneNames.java From fitnotifications with Apache License 2.0 | 5 votes |
private String getTargetRegion() { if (_region == null) { String region = _locale.getCountry(); if (region.length() == 0) { ULocale tmp = ULocale.addLikelySubtags(_locale); region = tmp.getCountry(); if (region.length() == 0) { region = "001"; } } _region = region; } return _region; }
Example 10
Source File: TimeZoneFormat.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Private method returning the target region. The target regions is determined by * the locale of this instance. When a generic name is coming from * a meta zone, this region is used for checking if the time zone * is a reference zone of the meta zone. * * @return the target region */ private synchronized String getTargetRegion() { if (_region == null) { _region = _locale.getCountry(); if (_region.length() == 0) { ULocale tmp = ULocale.addLikelySubtags(_locale); _region = tmp.getCountry(); if (_region.length() == 0) { _region = "001"; } } } return _region; }
Example 11
Source File: LocaleValidityChecker.java From trekarta with GNU General Public License v3.0 | 4 votes |
public boolean isValid(ULocale locale, Where where) { where.set(null, null); final String language = locale.getLanguage(); final String script = locale.getScript(); final String region = locale.getCountry(); final String variantString = locale.getVariant(); final Set<Character> extensionKeys = locale.getExtensionKeys(); // if (language.isEmpty()) { // // the only case where this is valid is if there is only an 'x' extension string // if (!script.isEmpty() || !region.isEmpty() || variantString.isEmpty() // || extensionKeys.size() != 1 || !extensionKeys.contains('x')) { // return where.set(Datatype.x, "Null language only with x-..."); // } // return true; // for x string, wellformedness = valid // } if (!isValid(Datatype.language, language, where)) { // special case x if (language.equals("x")) { where.set(null, null); // for x, well-formed == valid return true; } return false; } if (!isValid(Datatype.script, script, where)) return false; if (!isValid(Datatype.region, region, where)) return false; if (!variantString.isEmpty()) { for (String variant : SEPARATOR.split(variantString)) { if (!isValid(Datatype.variant, variant, where)) return false; } } for (Character c : extensionKeys) { try { Datatype datatype = Datatype.valueOf(c+""); switch (datatype) { case x: return true; // if it is syntactic (checked by ULocale) it is valid case t: case u: if (!isValidU(locale, datatype, locale.getExtension(c), where)) return false; break; default: break; } } catch (Exception e) { return where.set(Datatype.illegal, c+""); } } return true; }
Example 12
Source File: LocaleValidityChecker.java From fitnotifications with Apache License 2.0 | 4 votes |
public boolean isValid(ULocale locale, Where where) { where.set(null, null); final String language = locale.getLanguage(); final String script = locale.getScript(); final String region = locale.getCountry(); final String variantString = locale.getVariant(); final Set<Character> extensionKeys = locale.getExtensionKeys(); // if (language.isEmpty()) { // // the only case where this is valid is if there is only an 'x' extension string // if (!script.isEmpty() || !region.isEmpty() || variantString.isEmpty() // || extensionKeys.size() != 1 || !extensionKeys.contains('x')) { // return where.set(Datatype.x, "Null language only with x-..."); // } // return true; // for x string, wellformedness = valid // } if (!isValid(Datatype.language, language, where)) { // special case x if (language.equals("x")) { where.set(null, null); // for x, well-formed == valid return true; } return false; } if (!isValid(Datatype.script, script, where)) return false; if (!isValid(Datatype.region, region, where)) return false; if (!variantString.isEmpty()) { for (String variant : SEPARATOR.split(variantString)) { if (!isValid(Datatype.variant, variant, where)) return false; } } for (Character c : extensionKeys) { try { Datatype datatype = Datatype.valueOf(c+""); switch (datatype) { case x: return true; // if it is syntactic (checked by ULocale) it is valid case t: case u: if (!isValidU(locale, datatype, locale.getExtension(c), where)) return false; break; } } catch (Exception e) { return where.set(Datatype.illegal, c+""); } } return true; }
Example 13
Source File: Messages.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resource bundle which is most match to specified locale. * <p> * As expected, if specified locale hasn't defined valid resource file, we * want to load English(default) resource file instead of the resource file * of default locale. * * @param locale * specified locale. * @param baseName * the path of resource. * @param clazz * the class whose class loader will be used by loading resource * bundle. * @return instance of resource bundle. */ @SuppressWarnings("rawtypes") private static ResourceBundle getMatchedResourceBundle( ULocale locale, String baseName, Class clazz ) { ResourceBundle bundle; bundle = UResourceBundle.getBundleInstance( baseName, locale, clazz.getClassLoader( ) ); if ( bundle != null ) { // Bundle could be in default locale instead of English // if resource for the locale cannot be found. String language = locale.getLanguage( ); String country = locale.getCountry( ); boolean useDefaultResource = true; if ( language.length( ) == 0 && country.length( ) == 0 ) { // it is definitely the match, no need to get the // default resource file again. useDefaultResource = false; } else { Locale bundleLocale = bundle.getLocale( ); if ( bundleLocale.getLanguage( ).length( ) == 0 && bundleLocale.getCountry( ).length( ) == 0 ) { // it is the match, no need to get the default // resource file again. useDefaultResource = false; } else if ( language.equals( bundleLocale.getLanguage( ) ) ) { // Language matched String bundleCountry = bundleLocale.getCountry( ); if ( country.equals( bundleCountry ) || bundleCountry.length( ) == 0 ) { // Country matched or Bundle has no Country // specified. useDefaultResource = false; } } } if ( useDefaultResource ) { bundle = ResourceBundle.getBundle( baseName, new Locale( "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } return bundle; }
Example 14
Source File: Messages.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resource bundle which is most match to specified locale. * <p> * As expected, if specified locale hasn't defined valid resource file, we * want to load English(default) resource file instead of the resource file * of default locale. * * @param locale * specified locale. * @param baseName * the path of resource. * @param clazz * the class whose class loader will be used by loading resource * bundle. * @return instance of resource bundle. */ @SuppressWarnings("rawtypes") private static ResourceBundle getMatchedResourceBundle( ULocale locale, String baseName, Class clazz ) { ResourceBundle bundle; bundle = UResourceBundle.getBundleInstance( baseName, locale, SecurityUtil.getClassLoader( clazz ) ); if ( bundle != null ) { // Bundle could be in default locale instead of English // if resource for the locale cannot be found. String language = locale.getLanguage( ); String country = locale.getCountry( ); boolean useDefaultResource = true; if ( language.length( ) == 0 && country.length( ) == 0 ) { // it is definitely the match, no need to get the // default resource file again. useDefaultResource = false; } else { Locale bundleLocale = bundle.getLocale( ); if ( bundleLocale.getLanguage( ).length( ) == 0 && bundleLocale.getCountry( ).length( ) == 0 ) { // it is the match, no need to get the default // resource file again. useDefaultResource = false; } else if ( language.equals( bundleLocale.getLanguage( ) ) ) { // Language matched String bundleCountry = bundleLocale.getCountry( ); if ( country.equals( bundleCountry ) || bundleCountry.length( ) == 0 ) { // Country matched or Bundle has no Country // specified. useDefaultResource = false; } } } if ( useDefaultResource ) { bundle = ResourceBundle.getBundle( baseName, new Locale( "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } return bundle; }
Example 15
Source File: Messages.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resource bundle which is most match to specified locale. * <p> * As expected, if specified locale hasn't defined valid resource file, we * want to load English(default) resource file instead of the resource file * of default locale. * * @param locale * specified locale. * @param baseName * the path of resource. * @param clazz * the class whose class loader will be used by loading resource * bundle. * @return instance of resource bundle. */ @SuppressWarnings("rawtypes") private static ResourceBundle getMatchedResourceBundle( ULocale locale, String baseName, Class clazz ) { ResourceBundle bundle; bundle = UResourceBundle.getBundleInstance( baseName, locale, SecurityUtil.getClassLoader( clazz ) ); if ( bundle != null ) { // Bundle could be in default locale instead of English // if resource for the locale cannot be found. String language = locale.getLanguage( ); String country = locale.getCountry( ); boolean useDefaultResource = true; if ( language.length( ) == 0 && country.length( ) == 0 ) { // it is definitely the match, no need to get the // default resource file again. useDefaultResource = false; } else { Locale bundleLocale = bundle.getLocale( ); if ( bundleLocale.getLanguage( ).length( ) == 0 && bundleLocale.getCountry( ).length( ) == 0 ) { // it is the match, no need to get the default // resource file again. useDefaultResource = false; } else if ( language.equals( bundleLocale.getLanguage( ) ) ) { // Language matched String bundleCountry = bundleLocale.getCountry( ); if ( country.equals( bundleCountry ) || bundleCountry.length( ) == 0 ) { // Country matched or Bundle has no Country // specified. useDefaultResource = false; } } } if ( useDefaultResource ) { bundle = ResourceBundle.getBundle( baseName, new Locale( "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } return bundle; }
Example 16
Source File: Messages.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resource bundle which is most match to specified locale. * <p> * As expected, if specified locale hasn't defined valid resource file, we * want to load English(default) resource file instead of the resource file * of default locale. * * @param locale * specified locale. * @param baseName * the path of resource. * @param clazz * the class whose class loader will be used by loading resource * bundle. * @return instance of resource bundle. */ @SuppressWarnings("rawtypes") private static ResourceBundle getMatchedResourceBundle( ULocale locale, String baseName, Class clazz ) { ResourceBundle bundle; bundle = UResourceBundle.getBundleInstance( baseName, locale, SecurityUtil.getClassLoader( clazz ) ); if ( bundle != null ) { // Bundle could be in default locale instead of English // if resource for the locale cannot be found. String language = locale.getLanguage( ); String country = locale.getCountry( ); boolean useDefaultResource = true; if ( language.length( ) == 0 && country.length( ) == 0 ) { // it is definitely the match, no need to get the // default resource file again. useDefaultResource = false; } else { Locale bundleLocale = bundle.getLocale( ); if ( bundleLocale.getLanguage( ).length( ) == 0 && bundleLocale.getCountry( ).length( ) == 0 ) { // it is the match, no need to get the default // resource file again. useDefaultResource = false; } else if ( language.equals( bundleLocale.getLanguage( ) ) ) { // Language matched String bundleCountry = bundleLocale.getCountry( ); if ( country.equals( bundleCountry ) || bundleCountry.length( ) == 0 ) { // Country matched or Bundle has no Country // specified. useDefaultResource = false; } } } if ( useDefaultResource ) { bundle = ResourceBundle.getBundle( baseName, new Locale( "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } return bundle; }
Example 17
Source File: Messages.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resource bundle which is most match to specified locale. * <p> * As expected, if specified locale hasn't defined valid resource file, we * want to load English(default) resource file instead of the resource file * of default locale. * * @param locale * specified locale. * @param baseName * the path of resource. * @param clazz * the class whose class loader will be used by loading resource * bundle. * @return instance of resource bundle. */ @SuppressWarnings("rawtypes") private static ResourceBundle getMatchedResourceBundle( ULocale locale, String baseName, Class clazz ) { ResourceBundle bundle; bundle = UResourceBundle.getBundleInstance( baseName, locale, SecurityUtil.getClassLoader( clazz ) ); if ( bundle != null ) { // Bundle could be in default locale instead of English // if resource for the locale cannot be found. String language = locale.getLanguage( ); String country = locale.getCountry( ); boolean useDefaultResource = true; if ( language.length( ) == 0 && country.length( ) == 0 ) { // it is definitely the match, no need to get the // default resource file again. useDefaultResource = false; } else { Locale bundleLocale = bundle.getLocale( ); if ( bundleLocale.getLanguage( ).length( ) == 0 && bundleLocale.getCountry( ).length( ) == 0 ) { // it is the match, no need to get the default // resource file again. useDefaultResource = false; } else if ( language.equals( bundleLocale.getLanguage( ) ) ) { // Language matched String bundleCountry = bundleLocale.getCountry( ); if ( country.equals( bundleCountry ) || bundleCountry.length( ) == 0 ) { // Country matched or Bundle has no Country // specified. useDefaultResource = false; } } } if ( useDefaultResource ) { bundle = ResourceBundle.getBundle( baseName, new Locale( "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } return bundle; }
Example 18
Source File: Messages.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resource bundle which is most match to specified locale. * <p> * As expected, if specified locale hasn't defined valid resource file, we * want to load English(default) resource file instead of the resource file * of default locale. * * @param locale * specified locale. * @param baseName * the path of resource. * @param clazz * the class whose class loader will be used by loading resource * bundle. * @return instance of resource bundle. */ @SuppressWarnings("rawtypes") private static ResourceBundle getMatchedResourceBundle( ULocale locale, String baseName, Class clazz ) { ResourceBundle bundle; bundle = UResourceBundle.getBundleInstance( baseName, locale, SecurityUtil.getClassLoader( clazz ) ); if ( bundle != null ) { // Bundle could be in default locale instead of English // if resource for the locale cannot be found. String language = locale.getLanguage( ); String country = locale.getCountry( ); boolean useDefaultResource = true; if ( language.length( ) == 0 && country.length( ) == 0 ) { // it is definitely the match, no need to get the // default resource file again. useDefaultResource = false; } else { Locale bundleLocale = bundle.getLocale( ); if ( bundleLocale.getLanguage( ).length( ) == 0 && bundleLocale.getCountry( ).length( ) == 0 ) { // it is the match, no need to get the default // resource file again. useDefaultResource = false; } else if ( language.equals( bundleLocale.getLanguage( ) ) ) { // Language matched String bundleCountry = bundleLocale.getCountry( ); if ( country.equals( bundleCountry ) || bundleCountry.length( ) == 0 ) { // Country matched or Bundle has no Country // specified. useDefaultResource = false; } } } if ( useDefaultResource ) { bundle = ResourceBundle.getBundle( baseName, new Locale( "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } return bundle; }