Java Code Examples for com.ibm.icu.util.ULocale#getLanguage()
The following examples show how to use
com.ibm.icu.util.ULocale#getLanguage() .
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: UScript.java From fitnotifications with Apache License 2.0 | 6 votes |
private static int[] getCodesFromLocale(ULocale locale) { // Multi-script languages, equivalent to the LocaleScript data // that we used to load from locale resource bundles. String lang = locale.getLanguage(); if(lang.equals("ja")) { return new int[] { UScript.KATAKANA, UScript.HIRAGANA, UScript.HAN }; } if(lang.equals("ko")) { return new int[] { UScript.HANGUL, UScript.HAN }; } String script = locale.getScript(); if(lang.equals("zh") && script.equals("Hant")) { return new int[] { UScript.HAN, UScript.BOPOMOFO }; } // Explicit script code. if(script.length() != 0) { int scriptCode = UScript.getCodeFromName(script); if(scriptCode != UScript.INVALID_CODE) { if(scriptCode == UScript.SIMPLIFIED_HAN || scriptCode == UScript.TRADITIONAL_HAN) { scriptCode = UScript.HAN; } return new int[] { scriptCode }; } } return null; }
Example 2
Source File: UCaseProps.java From fitnotifications with Apache License 2.0 | 6 votes |
static final int getCaseLocale(ULocale locale, int[] locCache) { int result; if(locCache!=null && (result=locCache[0])!=LOC_UNKNOWN) { return result; } result=LOC_ROOT; String language=locale.getLanguage(); if(language.equals("tr") || language.equals("tur") || language.equals("az") || language.equals("aze")) { result=LOC_TURKISH; } else if(language.equals("el") || language.equals("ell")) { result=LOC_GREEK; } else if(language.equals("lt") || language.equals("lit")) { result=LOC_LITHUANIAN; } if(locCache!=null) { locCache[0]=result; } return result; }
Example 3
Source File: UScript.java From trekarta with GNU General Public License v3.0 | 6 votes |
private static int[] getCodesFromLocale(ULocale locale) { // Multi-script languages, equivalent to the LocaleScript data // that we used to load from locale resource bundles. String lang = locale.getLanguage(); if(lang.equals("ja")) { return new int[] { UScript.KATAKANA, UScript.HIRAGANA, UScript.HAN }; } if(lang.equals("ko")) { return new int[] { UScript.HANGUL, UScript.HAN }; } String script = locale.getScript(); if(lang.equals("zh") && script.equals("Hant")) { return new int[] { UScript.HAN, UScript.BOPOMOFO }; } // Explicit script code. if(script.length() != 0) { int scriptCode = UScript.getCodeFromName(script); if(scriptCode != UScript.INVALID_CODE) { if(scriptCode == UScript.SIMPLIFIED_HAN || scriptCode == UScript.TRADITIONAL_HAN) { scriptCode = UScript.HAN; } return new int[] { scriptCode }; } } return null; }
Example 4
Source File: DateTimeUtil.java From birt with Eclipse Public License 1.0 | 6 votes |
public static String formatDateTime( String format, ULocale locale ) { // for milliseconds, the xls uses the format ".000" instead of ".SSS". if ( format.endsWith( ".SSS" ) ) { format = format.replace( ".SSS", ".000" ); } String code = locale2Code.get( locale ); if ( code == null ) { String language = locale.getLanguage( ); code = locale2Code.get( new ULocale( language, "" ) ); } if ( code == null ) { return format; } return code + format; }
Example 5
Source File: ChartUtil.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Returns if specified locale uses right-to-left direction. See ISO codes * at http://www.unicode.org/unicode/onlinedat/languages.html RTL languages * are Hebrew, Arabic, Urdu, Farsi (Persian), Yiddish * * @param lcl * locale to check direction * @return if specified locale uses right-to-left direction * @since 2.2 */ public static boolean isRightToLeftLocale( ULocale lcl ) { if ( lcl != null ) { String language = lcl.getLanguage( ); if ( language.equals( "he" ) || //$NON-NLS-1$ language.equals( "iw" ) || //$NON-NLS-1$ language.equals( "ar" ) || //$NON-NLS-1$ language.equals( "fa" ) || //$NON-NLS-1$ language.equals( "ur" ) || //$NON-NLS-1$ language.equals( "yi" ) || //$NON-NLS-1$ language.equals( "ji" ) ) //$NON-NLS-1$ { return true; } } return false; }
Example 6
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 7
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 8
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 9
Source File: DateTimeUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
public static String formatDateTime( String format, ULocale locale ) { String code = locale2Code.get( locale ); if ( code == null ) { String language = locale.getLanguage( ); code = locale2Code.get( new ULocale( language, "" ) ); } if ( code == null ) { return format; } return code + format; }
Example 10
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 11
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 12
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 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, 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 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, 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 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: 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 19
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; }