Exemplo n.º 1
0
 /// <summary>
 /// Load the i-th bundle and implement wildcard resolution.
 /// </summary>
 ///
 private void Load(int i)
 {
     if (bundles[i] == null)
     {
         bool tryWildcard = false;
         try {
             bundles[i] = ResourceBundle.GetBundle(baseNames[i], locale);
             if (bundles[i].GetLocale().Equals(locale))
             {
                 return;
             }
             if (locale.GetCountry().Length != 0 &&
                 i != bundles.Length - 1)
             {
                 tryWildcard = true;
             }
         } catch (MissingManifestResourceException e) {
             if (i == bundles.Length - 1)
             {
                 throw e;
             }
             tryWildcard = true;
         }
         if (tryWildcard)
         {
             Locale wildcard = new Locale("xx", locale.GetCountry(),
                                          locale.GetLanguage());
             try {
                 bundles[i] = ResourceBundle.GetBundle(baseNames[i],
                                                       wildcard);
             } catch (MissingManifestResourceException e_0) {
                 if (bundles[i] == null)
                 {
                     throw e_0;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /*
         * Convenience method that calls canonicalLocaleString(String) with
         * locale.toString();
         */
        /*
         * public static String canonicalLocaleString(Locale locale) { return
         * canonicalLocaleString(locale.toString()); }
         */

        /*
         * You'd think that Locale canonicalizes, since it munges the renamed
         * languages, but it doesn't quite. It forces the region to be upper case
         * but doesn't do anything about the language or variant. Our canonical form
         * is 'lower_UPPER_UPPER'.
         */
        /*
         * public static String canonicalLocaleString(String id) { if (id != null) {
         * int x = id.indexOf("_"); if (x == -1) { id =
         * id.toLowerCase(Locale.ENGLISH); } else { StringBuffer buf = new
         * StringBuffer(); buf.append(id.substring(0,
         * x).toLowerCase(Locale.ENGLISH));
         * buf.append(id.substring(x).toUpperCase(Locale.ENGLISH));
         *
         * int len = buf.length(); int n = len; while (--n >= 0 && buf.charAt(n) ==
         * '_') { } if (++n != len) { buf.delete(n, len); } id = buf.toString(); } }
         * return id; }
         */

        /// <summary>
        /// Fallback from the given locale name by removing the rightmost _-delimited
        /// element. If there is none, return the root locale ("", "", ""). If this
        /// is the root locale, return null. NOTE: The string "root" is not
        /// recognized; do not use it.
        /// </summary>
        ///
        /// <returns>a new Locale that is a fallback from the given locale, or null.</returns>
        public static Locale Fallback(Locale loc)
        {
            // Split the locale into parts and remove the rightmost part
            String[] parts = new String[] { loc.GetLanguage(), loc.GetCountry(),
                     loc.GetVariant() };
            int i;

            for (i = 2; i >= 0; --i)
            {
                if (parts[i].Length != 0)
                {
                    parts[i] = "";
                    break;
                }
            }
            if (i < 0)
            {
                return(null);    // All parts were empty
            }
            return(new Locale(parts[0], parts[1], parts[2]));
        }