示例#1
0
 private static RootType GetRootType(string baseName, Assembly root)
 {
     return(ROOT_CACHE.GetOrAdd(baseName, (key) =>
     {
         string rootLocale = (baseName.IndexOf('.') == -1) ? "root" : "";
         try
         {
             ICUResourceBundle.GetBundleInstance(baseName, rootLocale, root, true);
             return RootType.ICU;
         }
         catch (MissingManifestResourceException)
         {
             try
             {
                 ResourceBundleWrapper.GetBundleInstance(baseName, rootLocale, root, true);
                 return RootType.DotNet;
             }
             catch (MissingManifestResourceException)
             {
                 //throw away the exception
                 return RootType.Missing;
             }
         }
     }));
 }
示例#2
0
        /// <summary>
        /// <icu/> Loads a new resource bundle for the given base name, locale and assembly.
        /// Optionally will disable loading of fallback bundles.
        /// </summary>
        /// <param name="baseName">String containing the name of the data package.
        /// If null the default ICU package name is used.</param>
        /// <param name="localeName">The locale for which a resource bundle is desired.</param>
        /// <param name="root">The class object from which to load the resource bundle.</param>
        /// <param name="disableFallback">Disables loading of fallback lookup chain.</param>
        /// <exception cref="MissingManifestResourceException">If no resource bundle for the specified base name can be found.</exception>
        /// <returns>A resource bundle for the given base name and locale.</returns>
        /// <stable>ICU 3.0</stable>
        protected static UResourceBundle InstantiateBundle(string baseName, string localeName,
                                                           Assembly root, bool disableFallback)
        {
            RootType rootType = GetRootType(baseName, root);

            switch (rootType)
            {
            case RootType.ICU:
                return(ICUResourceBundle.GetBundleInstance(baseName, localeName, root, disableFallback));

            case RootType.DotNet:
                return(ResourceBundleWrapper.GetBundleInstance(baseName, localeName, root,
                                                               disableFallback));

            case RootType.Missing:
            default:
                UResourceBundle b;
                try
                {
                    b = ICUResourceBundle.GetBundleInstance(baseName, localeName, root,
                                                            disableFallback);
                    SetRootType(baseName, RootType.ICU);
                }
                catch (MissingManifestResourceException)
                {
                    b = ResourceBundleWrapper.GetBundleInstance(baseName, localeName, root,
                                                                disableFallback);
                    SetRootType(baseName, RootType.DotNet);
                }
                return(b);
            }
        }
示例#3
0
        private static RootType GetRootType(string baseName, Assembly root)
        {
            RootType rootType;

            if (!ROOT_CACHE.TryGetValue(baseName, out rootType))
            {
                string rootLocale = (baseName.IndexOf('.') == -1) ? "root" : "";
                try
                {
                    ICUResourceBundle.GetBundleInstance(baseName, rootLocale, root, true);
                    rootType = RootType.ICU;
                }
                catch (MissingManifestResourceException ex)
                {
                    try
                    {
                        ResourceBundleWrapper.GetBundleInstance(baseName, rootLocale, root, true);
                        rootType = RootType.JAVA;
                    }
                    catch (MissingManifestResourceException e)
                    {
                        //throw away the exception
                        rootType = RootType.MISSING;
                    }
                }

                ROOT_CACHE[baseName] = rootType;
            }

            return(rootType);
        }