Esempio n. 1
0
        /// <summary>
        /// GetLanguageVal
        /// </summary>
        /// <param name="item"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public static string GetLanguageVal(this PublicTranslationResource item, string language)
        {
            var value = string.Empty;

            switch (language)
            {
            case "en":
                value = item.En;
                break;

            case "nl":
                value = item.Nl;
                break;

            case "de":
                value = item.De;
                break;

            case "fr":
                value = item.Fr;
                break;

            case "ro":
                value = item.Ro;
                break;
            }
            return(string.IsNullOrEmpty(value)
                ? (language != "en" && !string.IsNullOrEmpty(item.En)
                    ? item.En
                    : string.Format("Module translation not found. Translation key: {0}", item.KeyString))
                : value);
        }
        /// <summary>
        /// Get translations
        /// </summary>
        /// <param name="keyString"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public async Task <TranslationResource> GetApplicationTranslationByKeyString(string keyString,
                                                                                     string language)
        {
            var translations = _cacheService.Get("applicationTranslations_" + language) as IEnumerable <TranslationResource>;
            PublicTranslationResource translation = null;

            if (translations == null)
            {
                translation =
                    (await _unitOfWork.PublicTranslationResourceRepository.GetAllAsync()).FirstOrDefault(item => item.KeyString == keyString);
            }
            else
            {
                //var translations = _memoryCache.get
                return(translations.FirstOrDefault(item => item.KeyString == keyString));
            }

            return(new TranslationResource
            {
                KeyString = translation.KeyString,
                Value = translation.GetLanguageVal(language)
            });
        }