示例#1
0
        private string GetTranslation(string name, string context, int?count)
        {
            var key = CultureDictionaryRecord.GetKey(name, context);

            try
            {
                var translation = _dictionary[key, count];

                if (translation == null && _parentCultureDictionary != null)
                {
                    translation = _parentCultureDictionary[key, count]; // fallback to the parent culture
                }

                if (translation == null && context != null)
                {
                    translation = GetTranslation(name, null, count); // fallback to the translation without context
                }

                return(translation);
            }
            catch (PluralFormNotFoundException ex)
            {
                _logger.LogWarning(ex.Message);
            }

            return(null);
        }
        private string GetTranslation(string name, string context, CultureInfo culture, int?count)
        {
            var key = CultureDictionaryRecord.GetKey(name, context);

            try
            {
                var dictionary = _localizationManager.GetDictionary(culture);

                var translation = dictionary[key, count];

                if (translation == null && culture.Parent != null && culture.Parent != culture)
                {
                    dictionary = _localizationManager.GetDictionary(culture.Parent);

                    if (dictionary != null)
                    {
                        translation = dictionary[key, count]; // fallback to the parent culture
                    }
                }

                if (translation == null && context != null)
                {
                    translation = GetTranslation(name, null, culture, count); // fallback to the translation without context
                }

                return(translation);
            }
            catch (PluralFormNotFoundException ex)
            {
                _logger.LogWarning(ex.Message);
            }

            return(null);
        }
示例#3
0
        private string GetTranslation(string name, string context, CultureInfo culture, int?count)
        {
            string translation = null;

            try
            {
                if (_fallBackToParentCulture)
                {
                    do
                    {
                        if (ExtractTranslation() != null)
                        {
                            break;
                        }

                        culture = culture.Parent;
                    }while (culture != CultureInfo.InvariantCulture);
                }
                else
                {
                    ExtractTranslation();
                }

                string ExtractTranslation()
                {
                    var dictionary = _localizationManager.GetDictionary(culture);

                    if (dictionary != null)
                    {
                        // Extract translation with context
                        var key = CultureDictionaryRecord.GetKey(name, context);
                        translation = dictionary[key, count];

                        if (context != null && translation == null)
                        {
                            // Extract translation without context
                            key         = CultureDictionaryRecord.GetKey(name, null);
                            translation = dictionary[key, count];
                        }
                    }

                    return(translation);
                }
            }
            catch (PluralFormNotFoundException ex)
            {
                _logger.LogWarning(ex.Message);
            }

            return(translation);
        }