Exemplo n.º 1
0
        /// <summary>
        /// Returns translated into the selected language.
        /// </summary>
        /// <returns>Translated strings.</returns>
        public virtual string GetString()
        {
            if (LocalizationManager.IsDefaultCulture)
            {
                return(this._defaultStrings[0]);
            }

            string[] translations = LocalizationCache.GetStringsById(this._id);

            return(translations?[0] ?? this._defaultStrings[0]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the plural form for <paramref name="n"/> of the translation.
        /// </summary>
        /// <param name="n">Value that determines the plural form.</param>
        /// <returns>Translated strings.</returns>
        public virtual string GetPString(int n)
        {
            int pluralIndex = LocalizationManager.PluralForm.EvaluatePlural(n);

            if (pluralIndex < 0 || pluralIndex >= LocalizationManager.PluralForm.PluralsCount)
            {
                throw new IndexOutOfRangeException(
                          $"Calculated plural form index ({pluralIndex}) is out of allowed range (0~{LocalizationManager.PluralForm.PluralsCount - 1}).");
            }

            if (LocalizationManager.IsDefaultCulture)
            {
                return(this._defaultStrings[pluralIndex]);
            }

            string[] translations = LocalizationCache.GetStringsById(this._id);

            if (translations == null || translations.Length <= pluralIndex)
            {
                return((n == 1) ? this._defaultStrings[0] : this._defaultStrings[1]);
            }

            return(translations[pluralIndex]);
        }