Esempio n. 1
0
        /// <exclude />
        public static List <KeyValuePair> GetLocalization(string providerName)
        {
            Verify.ArgumentNotNullOrEmpty(providerName, "providerName");
            Verify.ArgumentCondition(!providerName.Contains(','), "providerName", "providerName may not contain ','");

            if (providerName == "XmlStringResourceProvider")
            {
                providerName = "Composite.Management";
            }

            IDictionary <string, string> translations = ResourceProviderPluginFacade.GetAllStrings(providerName);


            if (translations == null)
            {
                Log.LogVerbose(LogTitle, "Missing localization section: '{0}'".FormatWith(providerName));
                return(new List <KeyValuePair>());
            }

            List <KeyValuePair> result = new List <KeyValuePair>();

            foreach (KeyValuePair <string, string> pair in translations)
            {
                result.Add(new KeyValuePair(pair.Key, pair.Value));
            }

            return(result);
        }
Esempio n. 2
0
        /// <exclude />
        public static string GetString(string section, string stringName, bool throwOnError)
        {
            Verify.ArgumentNotNullOrEmpty(section, "section");
            Verify.ArgumentNotNullOrEmpty(stringName, "stringName");

            var culture = Thread.CurrentThread.CurrentUICulture;

            string cacheKey = culture.Name + section + stringName;
            ExtendedNullable <string> cachedValue = _resourceCache.Get(cacheKey);

            if (cachedValue != null)
            {
                return(cachedValue.Value);
            }

            if (throwOnError)
            {
                Verify.ArgumentCondition(!section.Contains(','), "section", "providerName may not contain ',' symbol");
                Verify.ArgumentCondition(!stringName.Contains(','), "stringName", "stringName may not contain ',' symbol");
            }


            string result = ResourceProviderPluginFacade.GetStringValue(section, stringName, culture);

            if (result != null)
            {
                _resourceCache.Add(cacheKey, new ExtendedNullable <string> {
                    Value = result
                });
                return(result);
            }

            if (!throwOnError)
            {
                return(null);
            }

            if (!ResourceProviderPluginFacade.LocalizationSectionDefined(section))
            {
                Log.LogVerbose(LogTitle, "Localization section not defined '{0}:{1}'".FormatWith(section, stringName));

                return(Error_SectionNotDefined);
            }


            Log.LogVerbose(LogTitle, "Localization string not defined '{0}:{1}'".FormatWith(section, stringName));

            return(Error_StringNotDefined);
        }
Esempio n. 3
0
            public static void Initialize(Resources resources)
            {
                resources.StringResourceProviders = new List <string>();
                resources.LocalizationProviders   = new List <string>();

                var configurationSource = ConfigurationServices.ConfigurationSource;

                if (configurationSource == null)
                {
                    return;
                }

                var section = configurationSource.GetSection(ResourceProviderSettings.SectionName);

                if (section == null)
                {
                    return;
                }

                var configuration = (ResourceProviderSettings)section;

                foreach (ResourceProviderData data in configuration.ResourceProviderPlugins)
                {
                    Type type = ResourceProviderPluginFacade.GetProviderType(data.Name);

                    if (typeof(IStringResourceProvider).IsAssignableFrom(type))
                    {
                        Log.LogVerbose(LogTitle, ("String resource provider '{0}' definition ignored." +
                                                  "\nEither remove it from Composite.config, or move the provider definition under a provider of type '{1}' ")
                                       .FormatWith(data.Name, typeof(AggregationLocalizationProvider).FullName));

                        resources.StringResourceProviders.Add(data.Name);
                    }
                    else if (typeof(ILocalizationProvider).IsAssignableFrom(type))
                    {
                        resources.LocalizationProviders.Add(data.Name);
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("Unknown resource provider type '{0}'", type));
                    }
                }
            }
Esempio n. 4
0
 /// <summary>
 /// Returns a list of all defined localization sections
 /// </summary>
 /// <exclude />
 public static IEnumerable <string> GetLocalizationSectionNames()
 {
     return(ResourceProviderPluginFacade.GetLocalizationSectionNames());
 }
Esempio n. 5
0
 /// <exclude />
 public static IEnumerable <CultureInfo> GetSupportedCultures()
 {
     return(ResourceProviderPluginFacade.GetSupportedStringCultures());
 }