/// <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); } }
/// <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 } }
public override void DeleteCulture(string ietfCode) { LocalizationFile oldFile = _localizationFileList.Single(p => p.IetfLanguageTag == ietfCode); //copy all dictionnaries foreach (LocalizationDictionary dico in oldFile.Dictionnaries) { string fullPath = Path.Combine(this.ResourceFolder, dico.FileName); if (File.Exists(fullPath)) { File.Delete(fullPath); } } _localizationFileList.Remove(oldFile); }
/// <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)); }
/// <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 } }
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); }