Exemple #1
0
        /// <summary>
        /// Effectivly find the value for the requested Key,Category,Culture
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        private async Task <string> GetLocalizedStringAsync(GetLocalizedParam param)
        {
            LocalizationTree tree = await GetLocalizationTreeAsync(param.CultureInfo).ConfigureAwait(false);

            if (tree.LocalizedCategories.TryGetValue(param.Category.ToLowerInvariant(), out LocalizationCategory category) &&
                category.LocalizedValues.TryGetValue(param.Key, out string value))
            {
                return(value);
            }
            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Gets the localized string based on the category, the key and the culture.
        /// </summary>
        /// <param name="param">The parameter which contains the category, the key and the culture.</param>
        /// <returns>
        /// Localized string
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// GetLocalizedParam.Category
        /// or
        /// GetLocalizedParam.Key
        /// or
        /// GetLocalizedParam.Culture
        /// </exception>
        public string GetLocalizedString(GetLocalizedParam param)
        {
            if (string.IsNullOrWhiteSpace(param.Category))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Category)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Key))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Key)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CultureInfo?.Name))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CultureInfo.Name)), nameof(param));
            }

            return(GetLocalizedStringAsync(param).Result);
        }
Exemple #3
0
        /// <summary>
        /// Gets the localized string based on the category, the key and the culture.
        /// </summary>
        /// <param name="param">The parameter which contains the category, the key and the culture.</param>
        /// <returns>
        /// Localized string
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// GetLocalizedParam.Category
        /// or
        /// GetLocalizedParam.Key
        /// or
        /// GetLocalizedParam.Culture
        /// </exception>
        public string GetLocalizedString(GetLocalizedParam param)
        {
            if (string.IsNullOrWhiteSpace(param.Category))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Category"), "param");
            }

            if (string.IsNullOrWhiteSpace(param.Key))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Key"), "param");
            }

            if (param.CultureInfo == null || string.IsNullOrWhiteSpace(param.CultureInfo.Name))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Culture"), "param");
            }

            return(GetLocalizedStringAsync(param).Result);
        }