private static IKeyedCollection <string, SldrLanguageTagInfo> DeriveTagsFromJsonEntries(List <AllTagEntry> rootObject) { var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase); foreach (AllTagEntry entry in rootObject) { // tags starting with x- have undefined structure so ignoring them // tags starting with _ showed up in buggy data so we'll drop them also if (!entry.tag.StartsWith("x-") && !entry.tag.StartsWith("_")) { LanguageSubtag languageTag; if (!entry.deprecated && !StandardSubtags.RegisteredLanguages.TryGet(entry.tag.Split('-')[0], out languageTag)) { if (entry.iso639_3 == null) { StandardSubtags.AddLanguage(entry.tag.Split('-')[0], entry.name, false, entry.tag.Split('-')[0]); } else if (!StandardSubtags.RegisteredLanguages.TryGet(entry.iso639_3, out languageTag)) { StandardSubtags.AddLanguage(entry.iso639_3, entry.name, false, entry.iso639_3); } } string implicitStringCode = null; // the script is always in the full tag string scriptCode = entry.full.Split('-')[1]; if (scriptCode.Length == 4) { var tagComponents = entry.tag.Split('-'); ScriptSubtag scriptTag; if (!StandardSubtags.RegisteredScripts.TryGet(scriptCode, out scriptTag)) { StandardSubtags.AddScript(scriptCode, scriptCode); } // if the script is also in the tag then it is explicit not implicit if (tagComponents.Length == 1 || tagComponents[1] != scriptCode) { implicitStringCode = scriptCode; } } tags.Add(new SldrLanguageTagInfo(entry.tag, implicitStringCode, entry.tag, entry.sldr)); } } return(tags); }
internal static IKeyedCollection <string, SldrLanguageTagInfo> ParseAllTagsJson(string allTagsContent) { // read in the json file /* { * "full": "aa-Latn-ET", * "name": "Afar", * "names": [ * "Adal", * ... * ], * "sldr": true, * "tag": "aa", * "tags": [ * "aa-ET", * "aa-Latn" * ] * },*/ // for each entry // tag -> langtag which is same as sldrtag // sldr -> isAvailable // tags -> process to find implicitScript var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase); List <AllTagEntry> rootObject = JsonConvert.DeserializeObject <List <AllTagEntry> >(allTagsContent); foreach (AllTagEntry entry in rootObject) { if (!entry.tag.StartsWith("x-")) // tags starting with x- have undefined structure so ignoring them { LanguageSubtag languageTag; if (!entry.deprecated && !StandardSubtags.RegisteredLanguages.TryGet(entry.tag.Split('-')[0], out languageTag)) { if (entry.iso639_3 == null) { StandardSubtags.AddLanguage(entry.tag.Split('-')[0], entry.name, false, entry.tag.Split('-')[0]); } else if (!StandardSubtags.RegisteredLanguages.TryGet(entry.iso639_3, out languageTag)) { StandardSubtags.AddLanguage(entry.iso639_3, entry.name, false, entry.iso639_3); } } string implicitStringCode = null; // the script is always in the full tag string scriptCode = entry.full.Split('-')[1]; if (scriptCode.Length == 4) { var tagComponents = entry.tag.Split('-'); ScriptSubtag scriptTag; if (!StandardSubtags.RegisteredScripts.TryGet(scriptCode, out scriptTag)) { StandardSubtags.AddScript(scriptCode, scriptCode); } // if the script is also in the tag then it is explicit not implicit if (tagComponents.Length == 1 || tagComponents[1] != scriptCode) { implicitStringCode = scriptCode; } } tags.Add(new SldrLanguageTagInfo(entry.tag, implicitStringCode, entry.tag, entry.sldr)); } } return(tags); }