@Override protected String toInternalCode (LocaleId locale) { // Reduce the locale code to its base language part return locale.getLanguage(); }
/** * Checks whether the specified locale has characters as numeral separators. * * @param localeId The locale to check against * * @return {@code true} - if the specified locale has characters as numeral separators * {@code false} - otherwise */ public static boolean hasCharactersAsNumeralSeparators(LocaleId localeId) { return HEBREW.getLanguage().equals(localeId.getLanguage()); }
/** * Indicates if the language of a given LocaleId is the same as the one of this LocaleId. * For example: "en" and "en-us" returns true, "es-es" and "ca-es" return false. * @param other the LocaleId object to compare. * @return true if the languages of two given LocaleIds are the same. */ public boolean sameLanguageAs(LocaleId other) { if (other == null) { return false; // locId is not null } return this.getLanguage().equals(other.getLanguage()); }
/** * Indicates if a given string has the same language as the one of this LocaleId. * For example: "en" and "en-us" returns true, "es-es" and "ca-es" return false. * @param langCode the string to compare. * @return true if the languages of both objects are the same. */ public boolean sameLanguageAs(String langCode) { return this.getLanguage().equals(ULocale.getLanguage(langCode)); }
@Override protected String toInternalCode (LocaleId standardCode) { String lang = standardCode.getLanguage(); String reg = standardCode.getRegion(); if ( reg != null ) { // Temporary fix for the Aranese case (until we get real LocaleID) if ( reg.equals("aran") ) lang += "_aran"; // Temporary fix for the Brazilian Portuguese case (until we get real LocaleID) if ( reg.equals("br") ) lang += "_BR"; } return lang; }
@Override protected String toInternalCode (LocaleId locale) { String code = locale.toBCP47().toLowerCase(); if ( code.equals("zh-tw") || code.startsWith("zh-hant") || code.equals("zh-cht") || code.equals("zh-hk")) { code = "zh-CHT"; } else if ( code.startsWith("zh") ) { // zh-cn, zh-hans, zh-chs.. code = "zh-CHS"; } else if ( code.startsWith("sr-cyrl") ) { // Preserve script for Serbian in Cyrillic // Latin script is the default ; } else if ( code.startsWith("pt") || code.equals("es-419") ) { ; // Preserve region variants for some locales } else if (locale.getLanguage().equals("in")) { // Java uses 'in' to represent the Indonesian locale, while // Microsoft expects 'id'. ICU and Locale#toLanguageTag // both produce 'id', but our LocaleIds aren't always // coming from those sources. return "id"; } else { // Use just the language otherwise code = locale.getLanguage(); } return code; }
public WordCounter (LocaleId locId) { breaker = BreakIterator.getWordInstance(locId.toJavaLocale()); String lng = locId.getLanguage(); replaceApos = ( lng.equals("fr") || lng.equals("it") ); }
@Override protected String toInternalCode (LocaleId locale) { // The expected language code is language-Region with region mandatory String lang = locale.getLanguage(); String reg = locale.getRegion(); //TODO: Use a lookup table and a more complete one if ( lang.equals("en") ) reg = "us"; else if ( lang.equals("pt") ) reg = "br"; else if ( lang.equals("el") ) reg = "gr"; else if ( lang.equals("he") ) reg = "il"; else if ( lang.equals("ja") ) reg = "jp"; else if ( lang.equals("ko") ) reg = "kr"; else if ( lang.equals("ms") ) reg = "my"; else if ( lang.equals("sl") ) reg = "si"; else if ( lang.equals("sq") ) reg = "al"; else if ( lang.equals("sv") ) reg = "se"; else if ( lang.equals("vi") ) reg = "vn"; else if ( lang.equals("zh") ) { if ( reg != null ) reg = "cn"; } else { reg = lang; } return lang+"-"+reg; }
/** * Gets a POSIX locale identifier for this LocaleId. * For example: "af-za" returns "af_ZA". * @return the corresponding POSIX locale identifier for this LocaleId. */ public String toPOSIXLocaleId() { //TODO: Make it simpler, and complete it String tmp = getLanguage(); if (getRegion() != null) { tmp += ("_" + getRegion().toUpperCase()); } return tmp; }
@Override protected String toInternalCode (LocaleId locale) { String code = locale.toBCP47(); String lang = locale.getLanguage(); if ( locale.getRegion() == null ) { // TDA langs have all a region code: Try to add it here. boolean found = false; for ( int i=0; i<LANGSMAP.length; i++ ) { if ( lang.equals(LANGSMAP[i][0]) ) { code = LANGSMAP[i][1]; found = true; break; } } if ( !found ) { // Default: region code is same as lang code: fr-fr code = lang+"-"+lang; } } return code; }
/** * Splits a given locale tag (e.g. "fr-ca") into its components. * Use this method when working directly with an {@link LocaleId} object is not desirable. * This method supports only simple ISO codes (not complex BCP-47 tags). * @param locId the locale code to process. * @return an array of two strings: 0=language, 1=region/country (or empty) * @deprecated don't use this. It only "understands" language + region, * but that is just a small part of what BCP 47 supports. */ @Deprecated public static String[] splitLanguageCode(String locId) { final String[] parts = {"", ""}; if ((locId == null) || (locId.length() == 0)) { return parts; } final LocaleId loc = LocaleId.fromString(locId); final String language = loc.getLanguage(); final String region = loc.getRegion(); if (language != null) parts[0] = language; if (region != null) parts[1] = region; return parts; }
/** * Helper method. */ private void processExcludes(StringBuilder sb) { if (sb == null) return; for (LocaleId localeId : ListUtil.invert(excludes)) { sb.append("!"); sb.append(localeId.getLanguage()); if (!Util.isEmpty(localeId.getRegion())) { sb.append("-"); sb.append(localeId.getRegion()); if (!Util.isEmpty(localeId.getUserPart())) { sb.append("-"); sb.append(localeId.getUserPart()); } } sb.append(" "); } }
for ( String key : paramList.keySet() ) { value = paramList.get(key).replace(VAR_SRCLANG, input1.getSourceLocale().getLanguage()); if ( value.indexOf(VAR_TRGLANG) > -1 ) { value = value.replace(VAR_TRGLANG, input1.getTargetLocale().getLanguage());
/** * Helper method. */ private void processIncludes(StringBuilder sb) { if (sb == null) return; for (LocaleId localeId : ListUtil.invert(includes)) { sb.append(localeId.getLanguage()); if (!Util.isEmpty(localeId.getRegion())) { sb.append("-"); sb.append(localeId.getRegion()); if (!Util.isEmpty(localeId.getUserPart())) { sb.append("-"); sb.append(localeId.getUserPart()); } } sb.append(" "); } }