Java Code Examples for com.ibm.icu.util.ULocale#getBaseName()

The following examples show how to use com.ibm.icu.util.ULocale#getBaseName() . 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: ICUResourceBundle.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
public static ICUResourceBundle getBundleInstance(String baseName, String localeID,
        ClassLoader root, OpenType openType) {
    if (baseName == null) {
        baseName = ICUData.ICU_BASE_NAME;
    }
    localeID = ULocale.getBaseName(localeID);
    ICUResourceBundle b;
    if (openType == OpenType.LOCALE_DEFAULT_ROOT) {
        b = instantiateBundle(baseName, localeID, ULocale.getDefault().getBaseName(),
                root, openType);
    } else {
        b = instantiateBundle(baseName, localeID, null, root, openType);
    }
    if(b==null){
        throw new MissingResourceException(
                "Could not find the bundle "+ baseName+"/"+ localeID+".res","","");
    }
    return b;
}
 
Example 2
Source File: ICUResourceBundle.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
public static ICUResourceBundle getBundleInstance(String baseName, String localeID,
        ClassLoader root, OpenType openType) {
    if (baseName == null) {
        baseName = ICUData.ICU_BASE_NAME;
    }
    localeID = ULocale.getBaseName(localeID);
    ICUResourceBundle b;
    if (openType == OpenType.LOCALE_DEFAULT_ROOT) {
        b = instantiateBundle(baseName, localeID, ULocale.getDefault().getBaseName(),
                root, openType);
    } else {
        b = instantiateBundle(baseName, localeID, null, root, openType);
    }
    if(b==null){
        throw new MissingResourceException(
                "Could not find the bundle "+ baseName+"/"+ localeID+".res","","");
    }
    return b;
}
 
Example 3
Source File: NumberingSystem.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default numbering system for the specified ULocale.
 * @stable ICU 4.2
 */
public static NumberingSystem getInstance(ULocale locale) {
    // Check for @numbers
    boolean nsResolved = true;
    String numbersKeyword = locale.getKeywordValue("numbers");
    if (numbersKeyword != null ) {
        for ( String keyword : OTHER_NS_KEYWORDS ) {
            if ( numbersKeyword.equals(keyword)) {
                nsResolved = false;
                break;
            }
        }
    } else {
        numbersKeyword = "default";
        nsResolved = false;
    }

    if (nsResolved) {
        NumberingSystem ns = getInstanceByName(numbersKeyword);
        if (ns != null) {
            return ns;
        }
        // If the @numbers keyword points to a bogus numbering system name,
        // we return the default for the locale.
        numbersKeyword = "default";
    }

    // Attempt to get the numbering system from the cache
    String baseName = locale.getBaseName();
    // TODO: Caching by locale+numbersKeyword could yield a large cache.
    // Try to load for each locale the mappings from OTHER_NS_KEYWORDS and default
    // to real numbering system names; can we get those from supplemental data?
    // Then look up those mappings for the locale and resolve the keyword.
    String key = baseName+"@numbers="+numbersKeyword;
    LocaleLookupData localeLookupData = new LocaleLookupData(locale, numbersKeyword);
    return cachedLocaleData.getInstance(key, localeLookupData);
}
 
Example 4
Source File: RuleBasedNumberFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private String[] getNameListForLocale(ULocale loc) {
    if (loc != null && ruleSetDisplayNames != null) {
        String[] localeNames = { loc.getBaseName(), ULocale.getDefault(Category.DISPLAY).getBaseName() };
        for (String lname : localeNames) {
            while (lname.length() > 0) {
                String[] names = ruleSetDisplayNames.get(lname);
                if (names != null) {
                    return names;
                }
                lname = ULocale.getFallback(lname);
            }
        }
    }
    return null;
}
 
Example 5
Source File: DateFormatSymbols.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes format symbols for the locale and calendar type
 * @param desiredLocale The locale whose symbols are desired.
 * @param type          The calendar type whose date format symbols are desired.
 * @stable ICU 3.0
 */
//TODO: This protected seems to be marked as @stable accidentally.
// We may need to deescalate this API to @internal.
protected void initializeData(ULocale desiredLocale, String type)
{
    String key = desiredLocale.getBaseName() + '+' + type;
    String ns = desiredLocale.getKeywordValue("numbers");
    if (ns != null && ns.length() > 0) {
        key += '+' + ns;
    }
    DateFormatSymbols dfs = DFSCACHE.getInstance(key, desiredLocale);
    initializeData(dfs);
}
 
Example 6
Source File: Collator.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Return the name of the collator for the objectLocale, localized for the displayLocale.
 * If objectLocale is not visible or not defined by the factory, return null.
 * @param objectLocale the locale identifying the collator
 * @param displayLocale the locale for which the display name of the collator should be localized
 * @return the display name
 * @stable ICU 3.2
 */
public String getDisplayName(ULocale objectLocale, ULocale displayLocale) {
    if (visible()) {
        Set<String> supported = getSupportedLocaleIDs();
        String name = objectLocale.getBaseName();
        if (supported.contains(name)) {
            return objectLocale.getDisplayName(displayLocale);
        }
    }
    return null;
}
 
Example 7
Source File: ICULocaleService.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
public SimpleLocaleKeyFactory(Object obj, ULocale locale, int kind, boolean visible, String name) {
    super(visible, name);

    this.obj = obj;
    this.id = locale.getBaseName();
    this.kind = kind;
}
 
Example 8
Source File: ICULocaleService.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Return the name of the current fallback locale.  If it has changed since this was
 * last accessed, the service cache is cleared.
 */
public String validateFallbackLocale() {
    ULocale loc = ULocale.getDefault();
    if (loc != fallbackLocale) {
        synchronized (this) {
            if (loc != fallbackLocale) {
                fallbackLocale = loc;
                fallbackLocaleName = loc.getBaseName();
                clearServiceCache();
            }
        }
    }
    return fallbackLocaleName;
}
 
Example 9
Source File: SimpleDateFormat.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
private void processOverrideString(ULocale loc, String str) {

        if ( str == null || str.length() == 0 )
            return;

        int start = 0;
        int end;
        String nsName;
        Character ovrField;
        boolean moreToProcess = true;
        boolean fullOverride;

        while (moreToProcess) {
            int delimiterPosition = str.indexOf(";",start);
            if (delimiterPosition == -1) {
                moreToProcess = false;
                end = str.length();
            } else {
                end = delimiterPosition;
            }

            String currentString = str.substring(start,end);
            int equalSignPosition = currentString.indexOf("=");
            if (equalSignPosition == -1) { // Simple override string such as "hebrew"
               nsName = currentString;
               fullOverride = true;
            } else { // Field specific override string such as "y=hebrew"
               nsName = currentString.substring(equalSignPosition+1);
               ovrField = Character.valueOf(currentString.charAt(0));
               overrideMap.put(ovrField,nsName);
               fullOverride = false;
            }

            ULocale ovrLoc = new ULocale(loc.getBaseName()+"@numbers="+nsName);
            NumberFormat nf = NumberFormat.createInstance(ovrLoc,NumberFormat.NUMBERSTYLE);
            nf.setGroupingUsed(false);

            if (fullOverride) {
                setNumberFormat(nf);
            } else {
                // Since one or more of the override number formatters might be complex,
                // we can't rely on the fast numfmt where we have a partial field override.
                useLocalZeroPaddingNumberFormat = false;
            }

            if (!fullOverride && !numberFormatters.containsKey(nsName)) {
                  numberFormatters.put(nsName,nf);
            }

            start = delimiterPosition + 1;
        }
    }
 
Example 10
Source File: TimeZoneNames.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an instance of <code>TimeZoneNames</code> for the specified locale.
 * 
 * @param locale
 *            The locale.
 * @return An instance of <code>TimeZoneNames</code>
 * @stable ICU 49
 */
public static TimeZoneNames getInstance(ULocale locale) {
    String key = locale.getBaseName();
    return TZNAMES_CACHE.getInstance(key, locale);
}
 
Example 11
Source File: TimeZoneGenericNames.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * The factory method of <code>TimeZoneGenericNames</code>. This static method
 * returns a frozen instance of cached <code>TimeZoneGenericNames</code>.
 * @param locale the locale
 * @return A frozen <code>TimeZoneGenericNames</code>.
 */
public static TimeZoneGenericNames getInstance(ULocale locale) {
    String key = locale.getBaseName();
    return GENERIC_NAMES_CACHE.getInstance(key, locale);
}