/// <summary> /// Replaces the SQL stored function fnGetLanguagesForIso. /// </summary> public List <Names> GetLanguagesForIso(string sIso6393) { List <Names> rgNames = new List <Names>(); int eId; if (s_mapIso6393ToIdx.TryGetValue(sIso6393, out eId)) { for (int i = 0; i < s_tblLanguageLocation.Count; ++i) { LanguageLocation ll = s_tblLanguageLocation[i]; if (ll.EthnologueIdx == eId) { for (int j = 0; j < s_tblCountry.Count; ++j) { if (ll.CountryUsedInId == s_tblCountry[j].Id) { rgNames.Add(new Names(ll.LanguageIdx, s_tblLanguageName[ll.LanguageIdx], ll.CountryUsedInId, s_tblCountry[j].Name, eId, sIso6393)); } } } } } SelectDistinctNames(rgNames); return(rgNames); }
/// <summary> /// Replaces the SQL stored function named fnGetOtherLanguageNames. /// </summary> public List <OtherNames> GetOtherLanguageNames(string sEthnoCode) { List <OtherNames> rgOtherNames = new List <OtherNames>(); int eId; if (s_mapIso6393ToIdx.TryGetValue(sEthnoCode, out eId)) { for (int i = 0; i < s_tblLanguageLocation.Count; ++i) { LanguageLocation ll = s_tblLanguageLocation[i]; if (ll.EthnologueIdx == eId) { string sLanguageName = s_tblLanguageName[ll.LanguageIdx]; bool fPrimary = false; for (int j = 0; j < s_tblEthnologueLocation.Count; ++j) { if (s_tblEthnologueLocation[j].PrimaryNameIdx == ll.LanguageIdx) { fPrimary = true; break; } } rgOtherNames.Add(new OtherNames(fPrimary, sLanguageName)); } } } SelectDistinctOtherNames(rgOtherNames); return(rgOtherNames); }
/// <summary> /// Replaces the SQL stored function fnGetLanguagesInCountry. /// If fPrimary, gets languages and dialects used mainly in the given country. /// Otherwise, gets all dialects and languages for the country /// </summary> public List <Names> GetLanguagesInCountry(string sCountryName1, bool fPrimary) { var sCountryName = sCountryName1.ToLowerInvariant().Normalize(NormalizationForm.FormD); List <Names> rgNames = new List <Names>(); if (fPrimary) { for (int i = 0; i < s_tblCountry.Count; ++i) { if (CorrectedStartsWith(s_tblCountry[i].Name, sCountryName)) { for (int j = 0; j < s_tblEthnologueLocation.Count; ++j) { EthnologueLocation el = s_tblEthnologueLocation[j]; if (el.MainCountryUsedId == s_tblCountry[i].Id) { rgNames.Add(new Names(el.PrimaryNameIdx, s_tblLanguageName[el.PrimaryNameIdx], el.MainCountryUsedId, s_tblCountry[i].Name.Normalize(NormalizationForm.FormD), el.EthnologueIdx, s_tblEthnologue[el.EthnologueIdx].Iso6393)); } } break; } } } else { for (int i = 0; i < s_tblCountry.Count; ++i) { if (CorrectedStartsWith(s_tblCountry[i].Name, sCountryName)) { for (int j = 0; j < s_tblLanguageLocation.Count; ++j) { LanguageLocation ll = s_tblLanguageLocation[j]; if (ll.CountryUsedInId == s_tblCountry[i].Id) { rgNames.Add(new Names(ll.LanguageIdx, s_tblLanguageName[ll.LanguageIdx], ll.CountryUsedInId, s_tblCountry[i].Name.Normalize(NormalizationForm.FormD), ll.EthnologueIdx, s_tblEthnologue[ll.EthnologueIdx].Iso6393)); } } } } } SelectDistinctNames(rgNames); return(rgNames); }
/// <summary> /// Replaces the SQL stored function named fnGetLanguageNamesLike. /// </summary> public List <Names> GetLanguageNamesLike(string sNameLike, char chWhichPart) { List <Names> rgNames = new List <Names>(); string query = sNameLike.ToLowerInvariant().Normalize(NormalizationForm.FormD); List <int> matchingLanguages = new List <int>(); // For every language, match query to a substring of language. for (int i = 0; i < s_tblLanguageName.Count; ++i) { string language = s_tblLanguageName[i].ToLowerInvariant().Normalize(NormalizationForm.FormD); if (chWhichPart == 'L') { if (language.StartsWith(query)) { matchingLanguages.Add(i); } else if (language.CompareTo(query) > 0) { break; // no point looking further in a sorted list. } } else if (chWhichPart == 'R') { if (language.EndsWith(query)) { matchingLanguages.Add(i); } } else { if (language.Contains(query)) { matchingLanguages.Add(i); } } } // If the first attempt fails, split name apart, and // retry using the parts of the name. if (matchingLanguages.Count == 0) { // Strip out periods, commas, and percents query = query.Replace(".", ""); query = query.Replace(",", ""); query = query.Replace("%", ""); // Split into pieces (on space) string[] queryComponents = query.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Debug.Assert(queryComponents.Length > 0); // For each language, match any component of query to a substring of language. for (int i = 0; i < s_tblLanguageName.Count; ++i) { string language = s_tblLanguageName[i].ToLowerInvariant(); bool fMatch = true; for (int j = 0; j < queryComponents.Length; ++j) { if (!language.Contains(queryComponents[j])) { fMatch = false; break; } } if (fMatch) { matchingLanguages.Add(i); } } } // For each language location that has a language that matched query, // if any country uses the language then add the language and this information // to the return list. foreach (int matchedLanguage in matchingLanguages) { // For each language location for (int i = 0; i < s_tblLanguageLocation.Count; ++i) { LanguageLocation languageLocation = s_tblLanguageLocation[i]; // If the matched language is in the location if (languageLocation.LanguageIdx == matchedLanguage) { // For each country, if the language is used in the country, add to return list. for (int j = 0; j < s_tblCountry.Count; ++j) { if (s_tblCountry[j].Id == languageLocation.CountryUsedInId) { rgNames.Add(new Names(matchedLanguage, s_tblLanguageName[matchedLanguage], languageLocation.CountryUsedInId, s_tblCountry[j].Name, languageLocation.EthnologueIdx, s_tblEthnologue[languageLocation.EthnologueIdx].Iso6393)); } } } } } SelectDistinctNames(rgNames); return(rgNames); }
/// <summary> /// Gets the language location. /// </summary> /// <param name="configValue">The configurative value.</param> /// <param name="defaultValue">The default value.</param> /// <returns>The language location.</returns> private static LanguageLocation GetLanguageLocation(string configValue, LanguageLocation defaultValue) { if (string.IsNullOrEmpty(configValue)) { return defaultValue; } switch (configValue.ToLowerInvariant()) { case "filepath": return LanguageLocation.FilePath; case "querystring": return LanguageLocation.QueryString; default: return defaultValue; } }