public override void Initialize(string sourceName)
        {
            var fileNames = Directory.GetFiles(directoryPath, "*.json", SearchOption.TopDirectoryOnly);

            foreach (var fileName in fileNames)
            {
                var dictionary = CreateJsonLocalizationDictionary(fileName);
                if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                {
                    throw new StudioXInitializationException(sourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.Name);
                }

                Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                if (fileName.EndsWith(sourceName + ".json"))
                {
                    if (DefaultDictionary != null)
                    {
                        throw new StudioXInitializationException("Only one default localization dictionary can be for source: " + sourceName);
                    }

                    DefaultDictionary = dictionary;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceName"></param>
        public override void Initialize(string sourceName)
        {
            var resourceNames = _assembly.GetManifestResourceNames();

            foreach (var resourceName in resourceNames)
            {
                if (resourceName.StartsWith(_rootNamespace))
                {
                    using (var stream = _assembly.GetManifestResourceStream(resourceName))
                    {
                        var bytes     = stream.GetAllBytes();
                        var xmlString = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3); //Skipping byte order mark

                        var dictionary = CreateXmlLocalizationDictionary(xmlString);
                        if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                        {
                            throw new AbpInitializationException(sourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.Name);
                        }

                        Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                        if (resourceName.EndsWith(sourceName + ".xml"))
                        {
                            if (DefaultDictionary != null)
                            {
                                throw new AbpInitializationException("Only one default localization dictionary can be for source: " + sourceName);
                            }

                            DefaultDictionary = dictionary;
                        }
                    }
                }
            }
        }
        public override Task Initialize()
        {
            var resourceNames = _assembly.GetManifestResourceNames();

            foreach (var resourceName in resourceNames)
            {
                if (resourceName.StartsWith(_rootNamespace))
                {
                    using (var stream = _assembly.GetManifestResourceStream(resourceName))
                    {
                        var xmlString = Abp.Localization.Dictionaries.Utf8Helper.ReadStringFromStream(stream);

                        var dictionary = CreateXmlLocalizationDictionary(xmlString);
                        if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                        {
                            throw new AbpInitializationException(SourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.Name);
                        }

                        Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                        if (resourceName.EndsWith(SourceName + ".xml"))
                        {
                            if (DefaultDictionary != null)
                            {
                                throw new AbpInitializationException("Only one default localization dictionary can be for source: " + SourceName);
                            }

                            DefaultDictionary = dictionary;
                        }
                    }
                }
            }

            return(Task.FromResult(true));
        }
Beispiel #4
0
        public override void Initialize(string sourceName)
        {
            var resourceNames = assembly.GetManifestResourceNames();

            foreach (var resourceName in resourceNames)
            {
                if (resourceName.StartsWith(rootNamespace))
                {
                    using (var stream = assembly.GetManifestResourceStream(resourceName))
                    {
                        var jsonString = Utf8Helper.ReadStringFromStream(stream);

                        var dictionary = CreateJsonLocalizationDictionary(jsonString);
                        if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                        {
                            throw new StudioXInitializationException(sourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.Name);
                        }

                        Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                        if (resourceName.EndsWith(sourceName + ".json"))
                        {
                            if (DefaultDictionary != null)
                            {
                                throw new StudioXInitializationException("Only one default localization dictionary can be for source: " + sourceName);
                            }

                            DefaultDictionary = dictionary;
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public override Task Initialize()
        {
            var fileNames = Directory.GetFiles(_directoryPath, "*.json", SearchOption.TopDirectoryOnly);


            foreach (var fileName in fileNames)
            {
                var dictionary = CreateJsonLocalizationDictionary(fileName);
                if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                {
                    throw new AbpInitializationException(SourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.Name);
                }

                Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                if (fileName.EndsWith(SourceName + ".json"))
                {
                    if (DefaultDictionary != null)
                    {
                        throw new AbpInitializationException("Only one default localization dictionary can be for source: " + SourceName);
                    }

                    DefaultDictionary = dictionary;
                }
            }

            return(Task.FromResult(true));
        }
        public override void Initialize(string sourceName)
        {
            var fileNames = Directory.GetFiles(_directoryPath, "*.json", SearchOption.TopDirectoryOnly);

            foreach (var fileName in fileNames)
            {
                var dictionary = CreateJsonLocalizationDictionary(fileName);
                if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                {
                    throw new SharePlatformInitializationException(sourceName + " 源包含多个区域性字典: " + dictionary.CultureInfo.Name);
                }

                Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                if (fileName.EndsWith(sourceName + ".json"))
                {
                    if (DefaultDictionary != null)
                    {
                        throw new SharePlatformInitializationException("源只能有一个默认本地化词典: " + sourceName);
                    }

                    DefaultDictionary = dictionary;
                }
            }
        }
        public override void Initialize(string sourceName, ILocalizationConfiguration localizationConfiguration)
        {
            CultureInfo[] allCultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures);
            List<string> resourceNames = _assembly.GetManifestResourceNames().Where(resourceName =>
                allCultureInfos.Any(culture => resourceName.EndsWith($"{sourceName}.json", true, null) ||
                                               resourceName.EndsWith($"{sourceName}-{culture.Name}.json", true,
                                                   null))).ToList();
            foreach (string resourceName in resourceNames)
            {
                if (!resourceName.StartsWith(_rootNamespace)) continue;
                using (Stream stream = _assembly.GetManifestResourceStream(resourceName))
                {
                    string jsonString = Utf8Helper.ReadStringFromStream(stream);

                    JsonLocalizationDictionary dictionary = CreateJsonLocalizationDictionary(jsonString);
                    string dicCultureInfoName = dictionary.CultureInfo.Name;
                    if (Dictionaries.ContainsKey(dicCultureInfoName))
                    {
                        throw new Exception(sourceName + " source contains more than one dictionary for the culture: " + dicCultureInfoName);
                    }
                    Dictionaries[dicCultureInfoName] = dictionary;
                    LanguageIcon languageIcon = LocalizationConsts.LanguageIcons.Where(p => dicCultureInfoName.StartsWith(p.CountryName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    localizationConfiguration.Languages.Add(
                        new LanguageInfo(dicCultureInfoName, dictionary.CultureInfo.NativeName, icon: languageIcon?.Icon, isDefault: CultureInfo.CurrentUICulture.Name.Equals(dicCultureInfoName)));

                    if (!resourceName.EndsWith(sourceName + ".json")) continue;
                    if (DefaultDictionary != null)
                    {
                        throw new Exception("Only one default localization dictionary can be for source: " + sourceName);
                    }

                    DefaultDictionary = dictionary;
                }
            }
        }
Beispiel #8
0
        public override void Initialize(string sourceName, ILocalizationConfiguration localizationConfiguration)
        {
            string[] fileNames = Directory.GetFiles(_directoryPath, "*.json", SearchOption.TopDirectoryOnly);

            foreach (string fileName in fileNames)
            {
                JsonLocalizationDictionary dictionary = CreateJsonLocalizationDictionary(fileName);
                string dicCultureInfoName             = dictionary.CultureInfo.Name;
                if (Dictionaries.ContainsKey(dicCultureInfoName))
                {
                    throw new Exception(sourceName + " source contains more than one dictionary for the culture: " + dicCultureInfoName);
                }

                Dictionaries[dicCultureInfoName] = dictionary;
                LanguageIcon languageIcon = LocalizationConsts.LanguageIcons.Where(p => dicCultureInfoName.StartsWith(p.CountryName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                localizationConfiguration.Languages.Add(
                    new LanguageInfo(dicCultureInfoName, dictionary.CultureInfo.NativeName, icon: languageIcon?.Icon, isDefault: CultureInfo.CurrentUICulture.Name.Equals(dicCultureInfoName)));

                if (!fileName.EndsWith(sourceName + ".json"))
                {
                    continue;
                }
                if (DefaultDictionary != null)
                {
                    throw new Exception("Only one default localization dictionary can be for source: " + sourceName);
                }

                DefaultDictionary = dictionary;
            }
        }
Beispiel #9
0
    public override void Initialize(string sourceName)
    {
        var fileNames = Directory.GetFiles(_directoryPath, "*.xml", SearchOption.TopDirectoryOnly);

        foreach (var fileName in fileNames)
        {
            var dictionary = CreateXmlLocalizationDictionary(fileName);
            var nodeDic    = new List <KeyValuePair <string, Translator.Language.XmlLocalizationDictionary> >()
            {
                new KeyValuePair <string, Translator.Language.XmlLocalizationDictionary>("", CreateXmlLocalizationDictionary(fileName))
            };
            if (Dictionaries.ContainsKey(dictionary.CultureInfo.ToString() /*.Name*/))
            {
                throw new Exception(sourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.ToString() /*.Name*/);
            }

            Dictionaries[dictionary.CultureInfo.ToString() /*.Name*/]     = (Translator.Language.XmlLocalizationDictionary)dictionary;
            NodeDictionaries[dictionary.CultureInfo.ToString() /*.Name*/] = nodeDic;

            if (fileName.EndsWith(sourceName + ".xml"))
            {
                if (DefaultDictionary != null)
                {
                    throw new Exception("Only one default localization dictionary can be for source: " + sourceName);
                }

                DefaultDictionary     = (Translator.Language.XmlLocalizationDictionary)dictionary;
                DefaultNodeDictionary = nodeDic;
            }
        }
    }
Beispiel #10
0
        public static ApiResult SetupDictionaries()
        {
            if (Dictionaries != null && Dictionaries.Count == DictionaryFiles.Count * 2)
            {
                Debug("Dictionaries already setup. Not running dictionary setup again.");
                return(ApiResult.Success);
            }
            else if (Dictionaries == null)
            {
                Dictionaries = new Dictionary <string, HashSet <string> >(DictionaryFiles.Count * 2);
            }

            int setup = 0;

            using (var op = Begin("Setting up dictionaries"))
            {
                foreach (var df in DictionaryFiles)
                {
                    var dfpath = GetDataDirectoryPathTo("dictionaries", df.Value);
                    if (Dictionaries.ContainsKey(df.Key))
                    {
                        Debug("Not updating existing dictionary {0}.", df.Key);
                        continue;
                    }
                    else if (!File.Exists(dfpath))
                    {
                        Error("The dictionary file {0} for dictionary {1} could not be found.", dfpath, df.Key);
                        continue;
                    }
                    else
                    {
                        try
                        {
                            using (FileStream fs = File.OpenRead(dfpath))
                                using (Stream s = df.Value.EndsWith(".gz") || df.Value.EndsWith(".GZ") ?
                                                  new GZipStream(fs, CompressionMode.Decompress) : (Stream)fs)
                                {
                                    var data = ReadAllLines(() => s, Encoding.UTF8).ToArray();
                                    Dictionaries.Add(df.Key, new HashSet <string>(data));
                                    Debug("Read {0} entries from file.", data.Length, dfpath);
                                    Info("Dictionary {0} has {1} entries from file: {2}.", df.Key, Dictionaries[df.Key].Count, dfpath);
                                    Dictionaries.Add(df.Key + "_3grams", new HashSet <string>(data.Where(w => w.Length <= 3)));
                                    Info("Dictionary {0} has {1} entries from file: {2}.", df.Key + "_3grams",
                                         Dictionaries[df.Key + "_3grams"].Count, dfpath);
                                    setup++;
                                }
                        }
                        catch (Exception e)
                        {
                            Error(e, "An error occurred reading dictionary file {0}.", dfpath);
                            continue;
                        }
                    }
                }
                op.Complete();
            }
            return(setup > 0 ? ApiResult.Success : ApiResult.Failure);
        }
Beispiel #11
0
 public Dictionary <int, Brush> Dictionary(string category)
 {
     if (category == null)
     {
         return(null);
     }
     if (Dictionaries.ContainsKey(category) == false)
     {
         return(null);
     }
     return(Dictionaries[category]);
 }
        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;
            }
        }
        private void CreateDictionaries(IFileProvider fileProvider)
        {
            Dictionaries.Clear();

            foreach (var file in fileProvider.GetDirectoryContents(_virtualPath))
            {
                if (file.IsDirectory || !CanParseFile(file))
                {
                    continue;
                }

                var dictionary = CreateDictionaryFromFile(file);
                if (Dictionaries.ContainsKey(dictionary.CultureName))
                {
                    throw new AbpException($"{file.PhysicalPath} dictionary has a culture name '{dictionary.CultureName}' which is already defined!");
                }

                Dictionaries[dictionary.CultureName] = dictionary;
            }
        }
Beispiel #14
0
        public override void Initialize(string sourceName)
        {
            var allCultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures);

            var resourceNames = _assembly.GetManifestResourceNames().ToList();

            //var resourceNames = _assembly.GetManifestResourceNames().Where(resouceName =>
            //    allCultureInfos.Any(culture => resouceName.EndsWith($"{sourceName}.xml", true, null) ||
            //                                   resouceName.EndsWith($"{sourceName}-{culture.Name}.xml", true,
            //                                       null))).ToList();
            foreach (var resourceName in resourceNames)
            {
                if (resourceName.StartsWith(_rootNamespace))
                {
                    using (var stream = _assembly.GetManifestResourceStream(resourceName))
                    {
                        var xmlString = Utf8Helper.ReadStringFromStream(stream);

                        var dictionary = CreateXmlLocalizationDictionary(xmlString);
                        if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                        {
                            throw new Exception(sourceName + " source contains more than one dictionary for the culture: " + dictionary.CultureInfo.Name);
                        }

                        Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                        if (resourceName.EndsWith(sourceName + ".xml"))
                        {
                            if (DefaultDictionary != null)
                            {
                                throw new Exception("Only one default localization dictionary can be for source: " + sourceName);
                            }

                            DefaultDictionary = dictionary;
                        }
                    }
                }
            }
        }
Beispiel #15
0
        public override void Initialize(string sourceName)
        {
            var allCultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures);
            var resourceNames   = _assembly.GetManifestResourceNames().Where(resouceName =>
                                                                             allCultureInfos.Any(culture => resouceName.EndsWith($"{sourceName}.xml", true, null) ||
                                                                                                 resouceName.EndsWith($"{sourceName}-{culture.Name}.xml", true,
                                                                                                                      null))).ToList();

            foreach (var resourceName in resourceNames)
            {
                if (resourceName.StartsWith(_rootNamespace))
                {
                    using (var stream = _assembly.GetManifestResourceStream(resourceName))
                    {
                        var xmlString = Utf8Helper.ReadStringFromStream(stream);

                        var dictionary = CreateXmlLocalizationDictionary(xmlString);
                        if (Dictionaries.ContainsKey(dictionary.CultureInfo.Name))
                        {
                            throw new SharePlatformInitializationException(sourceName + " 源包含多个区域性字典: " + dictionary.CultureInfo.Name);
                        }

                        Dictionaries[dictionary.CultureInfo.Name] = dictionary;

                        if (resourceName.EndsWith(sourceName + ".xml"))
                        {
                            if (DefaultDictionary != null)
                            {
                                throw new SharePlatformInitializationException("源只能有一个默认本地化词典: " + sourceName);
                            }

                            DefaultDictionary = dictionary;
                        }
                    }
                }
            }
        }