Пример #1
0
        /// <summary>
        /// This remove a resource from memory, more for developper when update or change the module
        /// or the default value to re create the resource (files mode)
        /// </summary>
        /// <param name="ietfCode"></param>
        /// <param name="modul"></param>
        /// <param name="resource"></param>
        public override void DeleteResource(string ietfCode, string modul, object resource)
        {
            LocalizationItem       item = resource as LocalizationItem;
            LocalizationDictionary dico = GetLocalizationDictionary(ietfCode, modul);

            dico.LocalizationItems.Remove(item);
        }
Пример #2
0
        /// <summary>
        /// return the UNDEFINED modul dictionnary
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        protected LocalizationDictionary GetUndefined(string code)
        {
            try
            {
                LocalizationDictionary dict = GetLocalizationDictionary(code, "UNDEFINED");
                if (dict == null)
                {
                    LocalizationFile fileLoc = GetLocalizationFileFromCode(code);
                    if (fileLoc != null)
                    {
                        dict = new LocalizationDictionary()
                        {
                            Module            = "UNDEFINED",
                            IetfLanguageTag   = code,
                            FileName          = string.Format("{0}.{1}.{2}", "UNDEFINED", code, FileExtension),
                            LocalizationItems = new List <LocalizationItem>()
                        };

                        fileLoc.Dictionnaries.Add(dict);
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(dict);
            }
            catch { return(null); }
        }
Пример #3
0
        /// <summary>
        /// Load a given file
        /// </summary>
        /// <param name="file"></param>
        private void LoadDictionnary(string file)
        {
            try
            {
                LocalizationDictionary dict = (LocalizationDictionary)XmlHelper.Deserialize(file, typeof(LocalizationDictionary));
                dict.FileName = Path.GetFileName(file);

                //controlling, reject
                if (string.IsNullOrEmpty(dict.IetfLanguageTag))
                {
                    return;
                }
                if (string.IsNullOrEmpty(dict.Module))
                {
                    return;
                }
                if (string.IsNullOrEmpty(dict.FileName))
                {
                    return;
                }

                LocalizationFile loc_file = GetLocalizationFileFromCode(dict.IetfLanguageTag);
                if (loc_file == null)
                {
                    loc_file = new LocalizationFile(dict.IetfLanguageTag);
                    _localizationFileList.Add(loc_file);
                }

                loc_file.Dictionnaries.Add(dict);
            }
            catch (Exception err)
            {
                //no log because of vs designer
            }
        }
Пример #4
0
        /// <summary>
        /// Clone allow to duplicate a existing resource when create a new culture
        /// </summary>
        /// <param name="newIetfCode"></param>
        /// <returns></returns>
        public LocalizationDictionary Clone(string newIetfCode, string fileExt)
        {
            LocalizationDictionary result = new LocalizationDictionary()
            {
                Module          = this.Module,
                IetfLanguageTag = newIetfCode,
                FileName        = string.Format("{0}.{1}.{2}", Module, newIetfCode, fileExt)
            };

            result.LocalizationItems = new List <LocalizationItem>();
            foreach (LocalizationItem src in this.LocalizationItems)
            {
                result.LocalizationItems.Add(src.Clone());
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Create new culture resources, not implemented by all providers
        /// </summary>
        /// <param name="info"></param>
        public override CultureInfo CreateCulture(CultureInfo info)
        {
            //create new file
            LocalizationFile newFile = new LocalizationFile(info.IetfLanguageTag);

            //find the english reference
            LocalizationFile maxDict = _localizationFileList.Single(p => p.IetfLanguageTag == "en");

            //copy all dictionnaries
            foreach (LocalizationDictionary dico in maxDict.Dictionnaries)
            {
                LocalizationDictionary clone = dico.Clone(newFile.IetfLanguageTag, FileExtension);
                newFile.Dictionnaries.Add(clone);
            }

            //add file to the list
            _localizationFileList.Add(newFile);

            return(CultureInfo.GetCultureInfo(newFile.IetfLanguageTag));
        }
Пример #6
0
        /// <summary>
        /// Load a given file
        /// </summary>
        /// <param name="file"></param>
        private void LoadDictionnary(string file)
        {
            try
            {
                LocalizationDictionary dict = (LocalizationDictionary)BinaryHelper.Deserialize(file);
                dict.FileName = Path.GetFileName(file);

                LocalizationFile loc_file = GetLocalizationFileFromCode(dict.IetfLanguageTag);
                if (loc_file == null)
                {
                    loc_file = new LocalizationFile(dict.IetfLanguageTag);
                    _localizationFileList.Add(loc_file);
                }

                loc_file.Dictionnaries.Add(dict);
            }
            catch (Exception err)
            {
                //no log because of vs designer
            }
        }
Пример #7
0
        internal LocalizationItem GetCorrespondingItem(LocalizationExtension ext, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(ext.DefaultValue))
            {
                ext.DefaultValue = (string)base.GetDefaultValue(ext, culture);
            }

            //add default value to the resource
            LocalizationItem itemResult = new LocalizationItem()
            {
                Key = ext.Key, Default = ext.DefaultValue, Translated = ext.DefaultValue
            };

            List <LocalizationItem> listLoc = null;

            if (string.IsNullOrEmpty(ext.ResModul))             //case modul is missing, invent a undefined.2letter.xml dictionnary
            {
                listLoc = GetLocalizationItem(culture.IetfLanguageTag, "UNDEFINED");

                //no resource dictionnary for code and modul
                if (listLoc == null)
                {
                    //create it
                    LocalizationDictionary dict = GetUndefined(culture.IetfLanguageTag);
                    dict.LocalizationItems.Add(itemResult);
                }
                else                 //list exist, what about the resource
                {
                    if (listLoc.Exists(p => p.Key == ext.Key))
                    {
                        return(listLoc.Single(p => p.Key == ext.Key));
                    }
                    else
                    {
                        listLoc.Add(itemResult);
                    }
                }

                itemResult.IsUsed = true;
                return(itemResult);
            }

            LocalizationFile loc_file = GetLocalizationFileFromCode(culture.IetfLanguageTag);

            //file is missing
            if (loc_file == null)
            {
                //create the file
                loc_file = new LocalizationFile(culture.IetfLanguageTag);
                _localizationFileList.Add(loc_file);

                //create the dico
                LocalizationDictionary dict = new LocalizationDictionary()
                {
                    Module            = ext.ResModul,
                    IetfLanguageTag   = culture.IetfLanguageTag,
                    FileName          = string.Format("{0}.{1}.{2}", ext.ResModul, culture.IetfLanguageTag, FileExtension),
                    LocalizationItems = new List <LocalizationItem>()
                };

                loc_file.Dictionnaries.Add(dict);

                dict.LocalizationItems.Add(itemResult);

                itemResult.IsUsed = true;
                return(itemResult);
            }

            LocalizationDictionary dico = GetLocalizationDictionary(culture.IetfLanguageTag, ext.ResModul);

            // no dictionnary
            if (dico == null)
            {
                //create the dico
                dico = new LocalizationDictionary()
                {
                    Module            = ext.ResModul,
                    IetfLanguageTag   = culture.IetfLanguageTag,
                    FileName          = string.Format("{0}.{1}.{2}", ext.ResModul, culture.IetfLanguageTag, FileExtension),
                    LocalizationItems = new List <LocalizationItem>()
                };

                loc_file.Dictionnaries.Add(dico);

                dico.LocalizationItems.Add(itemResult);

                itemResult.IsUsed = true;
                return(itemResult);
            }
            else
            {
                List <LocalizationItem> temp = dico.LocalizationItems.Where(p => p.Key == itemResult.Key).ToList();
                if (temp.Count == 1)
                {
                    itemResult = temp[0];
                }
                else
                {
                    dico.LocalizationItems.Add(itemResult);
                    CreateForOtherlanguage(itemResult, culture.IetfLanguageTag, ext.ResModul);
                }
            }

            itemResult.IsUsed = true;
            return(itemResult);
        }