Esempio n. 1
0
        public static async Task <ILocalizationDictionary> Create(string sourceName, string cultureCode, IIocManager iocManager)
        {
            var dictionary     = new DbLocalizationDictionary(sourceName, CultureInfo.GetCultureInfo(cultureCode));
            var dublicateNames = new List <string>();
            var providers      = iocManager.ResolveAll <ILocalizationProvider>();

            foreach (var provider in providers)
            {
                foreach (var item in await provider.getLocalizationDicionary(sourceName, cultureCode))
                {
                    if (string.IsNullOrEmpty(item.Key))
                    {
                        throw new LocalizationException(StringLocal.Format("The key is empty in given dictionary."));
                    }

                    if (dictionary.Contains(item.Key))
                    {
                        dublicateNames.Add(item.Key);
                    }

                    dictionary[item.Key] = item.Value.NormalizeLineEndings();
                }
            }

            if (dublicateNames.Count > 0)
            {
                throw new LocalizationException(
                          StringLocal.Format("A dictionary can not contain same key twice. There are some duplicated names: " +
                                             string.Join(", ", dublicateNames)));
            }

            return(dictionary);
        }
        public override async Task Initialize()
        {
            var cultrues = Culture.Culture.getCultures();

            foreach (var cultrueTask in cultrues.Select(c => new { localizationTask = DbLocalizationDictionary.Create(SourceName, c, iocManager), c }))
            {
                var localization = await cultrueTask.localizationTask;
                if (!Dictionaries.ContainsKey(cultrueTask.c))
                {
                    Dictionaries.Add(cultrueTask.c, localization);
                }
                Dictionaries[cultrueTask.c] = localization;
                DefaultDictionary           = localization;
            }
        }