PurplePen.SymbolDB.GetLanguage C# (CSharp) Méthode

GetLanguage() public méthode

public GetLanguage ( string langId ) : SymbolLanguage
langId string
Résultat SymbolLanguage
        public SymbolLanguage GetLanguage(string langId)
        {
            SymbolLanguage language;
            if (languages.TryGetValue(langId, out language))
                return language;
            else
                return null;
        }

Usage Example

Exemple #1
0
        // 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);
        }
All Usage Examples Of PurplePen.SymbolDB::GetLanguage