Bloom.Book.RuntimeInformationInjector.AddLanguagesUsedInPage C# (CSharp) Method

AddLanguagesUsedInPage() static private method

Add to the dictionary which maps original to Localized strings an entry for any language code that doesn't already have one. We have localizations for a few major languages that map e.g. de->German/Deutsch/etc, so they are functioning not just to localize but to expand from a language code to an actual name. For any other languages where we don't have localization information, we'd like to at least expand the cryptic code into a name. This method does that.
static private AddLanguagesUsedInPage ( XmlDocument xmlDocument, string>.Dictionary mapOriginalToLocalized ) : void
xmlDocument System.Xml.XmlDocument
mapOriginalToLocalized string>.Dictionary
return void
        internal static void AddLanguagesUsedInPage(XmlDocument xmlDocument, Dictionary<string, string> mapOriginalToLocalized)
        {
            var langs = xmlDocument.SafeSelectNodes("//*[@lang]").Cast<XmlElement>()
                .Select(e => e.Attributes["lang"].Value)
                .Distinct()
                .Where(lang => !mapOriginalToLocalized.ContainsKey(lang))
                .ToList();
            if (langs.Any())
            {
                // We don't have a localization for these languages, but we can at least try to give them a name
                var lookup = new LanguageLookupModel(); // < 1ms
                foreach (var lang in langs) // may include things like empty string, z, *, but this is harmless as they are not language codes.
                {
                    string match;
                    if (lookup.GetBestLanguageName(lang, out match)) // some better name found
                        mapOriginalToLocalized[lang] = match;
                }
            }
        }