コード例 #1
0
ファイル: Translator.cs プロジェクト: Gris87/UnityEditor
        /// <summary>
        /// Return the string necessary for grammatically correct pluralization of the given resource ID for the given quantity.
        /// </summary>
        /// <returns>Localized string.</returns>
        /// <param name="id">Plurals resource ID.</param>
        /// <param name="quantity">Quantity.</param>
        public static string GetQuantityString(R.sections.Tooltips.plurals id, double quantity)
        {
            UnityTranslationInternal.Translator.LoadSection(R.sections.SectionID.Tooltips, false);

            string[] pluralsValues;
            UnityTranslationInternal.PluralsQuantity pluralsQuantity;

            if (
                UnityTranslationInternal.Translator.tokens[(int)R.sections.SectionID.Tooltips + 1].selectedLanguage != null
                &&
                UnityTranslationInternal.Translator.tokens[(int)R.sections.SectionID.Tooltips + 1].selectedLanguage.pluralsValues[(int)id] != null
                )
            {
                pluralsValues   = UnityTranslationInternal.Translator.tokens[(int)R.sections.SectionID.Tooltips + 1].selectedLanguage.pluralsValues[(int)id];
                pluralsQuantity = UnityTranslationInternal.PluralsRules.pluralsFunctions[(int)UnityTranslationInternal.Translator.language](quantity);
            }
            else
            {
                pluralsValues   = UnityTranslationInternal.Translator.tokens[(int)R.sections.SectionID.Tooltips + 1].defaultLanguage.pluralsValues[(int)id];
                pluralsQuantity = UnityTranslationInternal.PluralsRules.pluralsFunctions[0](quantity);
            }

            for (int i = (int)pluralsQuantity; i < (int)UnityTranslationInternal.PluralsQuantity.Count; ++i)
            {
                if (pluralsValues[i] != null)
                {
                    return(pluralsValues[i]);
                }
            }

            for (int i = (int)pluralsQuantity - 1; i >= 0; --i)
            {
                if (pluralsValues[i] != null)
                {
                    return(pluralsValues[i]);
                }
            }

            return("");
        }
コード例 #2
0
ファイル: Translator.cs プロジェクト: Gris87/UnityEditor
 /// <summary>
 /// Formats the string necessary for grammatically correct pluralization of the given resource ID for the given quantity, using the given arguments.
 /// </summary>
 /// <returns>Localized string.</returns>
 /// <param name="id">Plurals resource ID.</param>
 /// <param name="quantity">Quantity.</param>
 /// <param name="formatArgs">Format arguments.</param>
 public static string GetQuantityString(R.sections.Tooltips.plurals id, double quantity, params object[] formatArgs)
 {
     return(string.Format(GetQuantityString(id, quantity), formatArgs));
 }