/// <summary> /// Returns the display name for the given currency in the given locale. For /// example, the display name for the USD currency object in the en_US locale /// is "$". /// </summary> /// /// <param name="locale">locale in which to display currency</param> /// <param name="nameStyle">selector for which kind of name to return</param> /// <param name="isChoiceFormat">fill-in; isChoiceFormat[0] is set to true if the returnedvalue is a ChoiceFormat pattern; otherwise it is set to false</param> /// <returns>display string for this currency. If the resource data contains /// no entry for this currency, then the ISO 4217 code is returned. /// If isChoiceFormat[0] is true, then the result is a ChoiceFormat /// pattern. Otherwise it is a static string.</returns> /// @stable ICU 3.2 public String GetName(ULocale locale, int nameStyle, bool[] isChoiceFormat) { // Look up the Currencies resource for the given locale. The // Currencies locale data looks like this: // |en { // | Currencies { // | USD { "US$", "US Dollar" } // | CHF { "Sw F", "Swiss Franc" } // | INR { "=0#Rs|1#Re|1<Rs", "=0#Rupees|1#Rupee|1<Rupees" } // | //... // | } // |} if (nameStyle < 0 || nameStyle > 1) { throw new ArgumentException(); } String s = null; try { UResourceBundle rb = IBM.ICU.Util.UResourceBundle.GetBundleInstance( IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale); ICUResourceBundle currencies = (ICUResourceBundle)rb .Get("Currencies"); // Fetch resource with multi-level resource inheritance fallback s = currencies.GetWithFallback(isoCode).GetString(nameStyle); } catch (MissingManifestResourceException e) { // TODO what should be done here? } // Determine if this is a ChoiceFormat pattern. One leading mark // indicates a ChoiceFormat. Two indicates a static string that // starts with a mark. In either case, the first mark is ignored, // if present. Marks in the rest of the string have no special // meaning. isChoiceFormat[0] = false; if (s != null) { int i = 0; while (i < s.Length && s[i] == '=' && i < 2) { ++i; } isChoiceFormat[0] = (i == 1); if (i != 0) { // Skip over first mark s = s.Substring(1); } return(s); } // If we fail to find a match, use the ISO 4217 code return(isoCode); }
/// <summary> /// Retrieves a delimiter string from the locale data. /// </summary> /// <param name="type"> /// The type of delimiter string desired. Currently, /// the valid choices are <see cref="DelimiterType.QuotationStart"/>, <see cref="DelimiterType.QuotationEnd"/>, /// <see cref="DelimiterType.AlternateQuotationStart"/>, or <see cref="DelimiterType.AlternateQuotationEnd"/>. /// </param> /// <returns>The desired delimiter string.</returns> /// <stable>ICU 3.4</stable> public string GetDelimiter(DelimiterType type) { ICUResourceBundle delimitersBundle = (ICUResourceBundle)bundle.Get("delimiters"); // Only some of the quotation marks may be here. So we make sure that we do a multilevel fallback. ICUResourceBundle stringBundle = delimitersBundle.GetWithFallback(DELIMITER_TYPES[(int)type]); if (noSubstitute && !bundle.IsRoot && stringBundle.IsRoot) { return(null); } return(stringBundle.GetString()); }
internal String GetZoneString(ULocale locale, String olsonID, int item) { IDictionary data = (IDictionary)ILOG.J2CsMapping.Collections.Collections.Get(zoneData, locale); if (data == null) { data = new Hashtable(); if (SHOW_ALL) { System.Console.Out.WriteLine(); } if (SHOW_ALL) { System.Console.Out.WriteLine("zones for " + locale); } ICUResourceBundle bundle = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle .GetBundleInstance(locale); ICUResourceBundle table = bundle.GetWithFallback("zoneStrings"); for (int i = 0; i < table.GetSize(); ++i) { UResourceBundle stringSet = table.Get(i); // ICUResourceBundle stringSet = // table.getWithFallback(String.valueOf(i)); String key = stringSet.GetString(0); if (SHOW_ALL) { System.Console.Out.WriteLine("key: " + key); } ArrayList list = new ArrayList(); for (int j = 1; j < stringSet.GetSize(); ++j) { String entry = stringSet.GetString(j); if (SHOW_ALL) { System.Console.Out.WriteLine(" entry: " + entry); } ILOG.J2CsMapping.Collections.Generics.Collections.Add(list, entry); } ILOG.J2CsMapping.Collections.Collections.Put(data, key, ILOG.J2CsMapping.Collections.Generics.Collections.ToArray(list, new String[list.Count])); } ILOG.J2CsMapping.Collections.Collections.Put(zoneData, locale, data); } String[] strings = (String[])ILOG.J2CsMapping.Collections.Collections.Get(data, olsonID); if (strings == null || item >= strings.Length) { return(olsonID); } return(strings[item]); }
/// <summary> /// Hack to get code list /// </summary> /// /// <returns></returns> private static String[] GetCodes(ULocale locale, String tableName) { // TODO remove Ugly Hack // get stuff ICUResourceBundle bundle = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle .GetBundleInstance(locale); ICUResourceBundle table = bundle.GetWithFallback(tableName); // copy into array ArrayList stuff = new ArrayList(); for (IIterator keys = table.GetKeys(); keys.HasNext();) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(stuff, keys.Next()); } String[] result = new String[stuff.Count]; return((String[])ILOG.J2CsMapping.Collections.Generics.Collections.ToArray(stuff, result)); // return new String[] {"Latn", "Cyrl"}; }
/// <summary> /// Initializes the symbols from the LocaleElements resource bundle. Note: /// The organization of LocaleElements badly needs to be cleaned up. /// </summary> /// private void Initialize(ULocale locale) { this.requestedLocale = locale.ToLocale(); this.ulocale = locale; /* try the cache first */ String[][] data = (String[][])cachedLocaleData[locale]; String[] numberElements; if (data == null) /* cache miss */ { data = new String[1][]; ICUResourceBundle rb = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale); data[0] = rb.GetStringArray("NumberElements"); /* update cache */ ILOG.J2CsMapping.Collections.Collections.Put(cachedLocaleData, locale, data); } numberElements = data[0]; ICUResourceBundle r = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale); // TODO: Determine actual and valid locale correctly. ULocale uloc = r.GetULocale(); SetLocale(uloc, uloc); // {dlf} clean up below now that we have our own resource data decimalSeparator = numberElements[0][0]; groupingSeparator = numberElements[1][0]; // Temporary hack to support old JDK 1.1 resources // patternSeparator = numberElements[2].length() > 0 ? // numberElements[2].charAt(0) : ';'; patternSeparator = numberElements[2][0]; percent = numberElements[3][0]; zeroDigit = numberElements[4][0]; // different for Arabic,etc. digit = numberElements[5][0]; minusSign = numberElements[6][0]; // Temporary hack to support JDK versions before 1.1.6 (?) // exponentSeparator = numberElements.length >= 9 ? // numberElements[7] : DecimalFormat.PATTERN_EXPONENT; // perMill = numberElements.length >= 9 ? // numberElements[8].charAt(0) : '\u2030'; // infinity = numberElements.length >= 10 ? // numberElements[9] : "\u221e"; // NaN = numberElements.length >= 11 ? // numberElements[10] : "\ufffd"; exponentSeparator = numberElements[7]; perMill = numberElements[8][0]; infinity = numberElements[9]; NaN = numberElements[10]; plusSign = numberElements[11][0]; padEscape = IBM.ICU.Text.DecimalFormat.PATTERN_PAD_ESCAPE; sigDigit = IBM.ICU.Text.DecimalFormat.PATTERN_SIGNIFICANT_DIGIT; // Obtain currency data from the currency API. This is strictly // for backward compatibility; we don't use DecimalFormatSymbols // for currency data anymore. String currname = null; currency = IBM.ICU.Util.Currency.GetInstance(locale); if (currency != null) { intlCurrencySymbol = currency.GetCurrencyCode(); bool[] isChoiceFormat = new bool[1]; currname = currency.GetName(locale, IBM.ICU.Util.Currency.SYMBOL_NAME, isChoiceFormat); // If this is a ChoiceFormat currency, then format an // arbitrary value; pick something != 1; more common. currencySymbol = (isChoiceFormat[0]) ? new ChoiceFormat(currname) .Format(2.0d) : currname; } else { intlCurrencySymbol = "XXX"; currencySymbol = "\u00A4"; // 'OX' currency symbol } // If there is a currency decimal, use it. monetarySeparator = decimalSeparator; monetaryGroupingSeparator = groupingSeparator; Currency curr = IBM.ICU.Util.Currency.GetInstance(locale); if (curr != null) { String currencyCode = curr.GetCurrencyCode(); if (currencyCode != null) { /* An explicit currency was requested */ ICUResourceBundle resource = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale); ICUResourceBundle currencyRes = resource .GetWithFallback("Currencies"); try { currencyRes = currencyRes.GetWithFallback(currencyCode); if (currencyRes.GetSize() > 2) { currencyRes = (ICUResourceBundle)currencyRes.Get(2); currencyPattern = currencyRes.GetString(0); monetarySeparator = currencyRes.GetString(1)[0]; monetaryGroupingSeparator = currencyRes.GetString(2)[0]; } } catch (MissingManifestResourceException ex) { /* * else An explicit currency was requested and is unknown or * locale data is malformed. */ /* decimal format API will get the correct value later on. */ } } /* else no currency keyword used. */ } // monetarySeparator = numberElements[11].charAt(0); }