private void ParsePresentedLanguagesSection(XElement presentedLanguagesSection) { ElementNameToLanguageMap = presentedLanguagesSection .LanguageSections() .Select( languageSection => { // ReSharper disable PossibleNullReferenceException var languageName = languageSection.Attribute("Name").Value; // ReSharper restore PossibleNullReferenceException var nodeName = languageSection.Attribute("NodeName").Value(); return(new { LanguageName = languageName, NodeName = nodeName ?? languageName }); } ) .Where( languageNodeData => AllowedLanguages == null || AllowedLanguages.Contains(languageNodeData.LanguageName) ) .ToDictionary( x => x.NodeName, x => x.LanguageName ); PresentedLanguages = ElementNameToLanguageMap.Select(x => x.Value).ToList(); }
private void ParseItemsSection(XElement itemsSection) { LocalizationDataItems = itemsSection .ItemSections() .Select( itemSection => { var KEY = itemSection.Attribute("KEY").Value() ?? itemSection.Elements("KEY").Single().Value; var VALUES = itemSection .Elements() .Where( element => element.Name != "KEY" ) .Select( element => new { ElementName = element.Name.ToString(), // ReSharper disable RedundantAnonymousTypePropertyName Value = element.Value // ReSharper restore RedundantAnonymousTypePropertyName } ) .Select( elementData => new { Language = ElementNameToLanguageMap .ValueOrDefault( elementData.ElementName ), // ReSharper disable RedundantAnonymousTypePropertyName Value = elementData.Value // ReSharper restore RedundantAnonymousTypePropertyName } ) .Where( languageData => languageData.Language != null ) .ToDictionary( languageData => languageData.Language, languageData => languageData.Value ); if (DefaultLanguage.IsNotEmpty()) { if (VALUES.ContainsKey(DefaultLanguage) == false) { VALUES.Add(DefaultLanguage, KEY); } } return(new LocalizationDataItem { Key = KEY, Values = VALUES }); } ) .ToList(); }