// Find the best matching SymbolText. Gender can be null or empty for don't care. Same with nounCase. If // nounCase is empty then the first noun case from the language is chosen if possible. static SymbolText FindBestText(SymbolDB symbolDB, List <SymbolText> texts, string language, bool plural, string gender, string nounCase) { int best = 99999; SymbolText bestSymText = null; if (gender == null) { gender = ""; } string defaultNounCase = ""; SymbolLanguage symbolLanguage = symbolDB.GetLanguage(language); if (symbolLanguage != null && symbolLanguage.CaseModifiers && symbolLanguage.Cases.Length > 0) { defaultNounCase = symbolLanguage.Cases[0]; } // Search for exact match. foreach (SymbolText symtext in texts) { int metric = 0; if (symtext.Lang != language && symtext.Lang != "en") { metric += 100; } if (symtext.Lang != language && symtext.Lang == "en") // english is most preferred if no language match { metric += 50; } if (symtext.Plural != plural) { metric += 10; } if (gender != "" && symtext.Gender != gender) { metric += 5; } if (nounCase != "" && symtext.Case != nounCase) { metric += 3; } if (nounCase == "" && symtext.Case != null && symtext.Case != defaultNounCase) { metric += 1; } if (metric < best) { best = metric; bestSymText = symtext; } } return(bestSymText); }
// Find the best matching SymbolText. Gender can be null or empty for don't care. Same with nounCase. If // nounCase is empty then the first noun case from the language is chosen if possible. static SymbolText FindBestText(SymbolDB symbolDB, List<SymbolText> texts, string language, bool plural, string gender, string nounCase) { int best = 99999; SymbolText bestSymText = null; if (gender == null) gender = ""; string defaultNounCase = ""; SymbolLanguage symbolLanguage = symbolDB.GetLanguage(language); if (symbolLanguage != null && symbolLanguage.CaseModifiers && symbolLanguage.Cases.Length > 0) defaultNounCase = symbolLanguage.Cases[0]; // Search for exact match. foreach (SymbolText symtext in texts) { int metric = 0; if (symtext.Lang != language && symtext.Lang != "en") metric += 100; if (symtext.Lang != language && symtext.Lang == "en") // english is most preferred if no language match metric += 50; if (symtext.Plural != plural) metric += 10; if (gender != "" && symtext.Gender != gender) metric += 5; if (nounCase != "" && symtext.Case != nounCase) metric += 3; if (nounCase == "" && symtext.Case != null && symtext.Case != defaultNounCase) metric += 1; if (metric < best) { best = metric; bestSymText = symtext; } } return bestSymText; }