Esempio n. 1
0
        public void TranslateName(ContentApiInstruction apiInstruction, string subscriptionKey, string uriBase, ILanguage defaultLanguage, IContent content)
        {
            var currentCultureNameValue = content.GetCultureName(apiInstruction.CurrentCulture);
            var defaultCultureNameValue = content.GetCultureName(defaultLanguage.IsoCode);

            if (!string.IsNullOrWhiteSpace(defaultCultureNameValue) &&
                (apiInstruction.OverwriteExistingValues || string.IsNullOrWhiteSpace(currentCultureNameValue)))
            {
                var    result          = _textTranslationService.MakeTranslationRequestAsync(defaultCultureNameValue, subscriptionKey, uriBase, new[] { apiInstruction.CurrentCulture }, defaultLanguage.IsoCode);
                JToken translatedValue = CommonHelpers.GetTranslatedValue(result);
                content.SetCultureName(translatedValue.ToString(), apiInstruction.CurrentCulture);
            }
        }
        public void UpdateDictionaryTranslations(DictionaryApiInstruction apiInstruction, string subscriptionKey, string uriBase, IDictionaryItem dictionaryItem, ILanguage defaultLanguage, IEnumerable <ILanguage> allLanguages, string valueToTranslate)
        {
            var allLanguagesList = allLanguages.ToList();

            foreach (var translation in dictionaryItem.Translations)
            {
                var cultureToTranslateTo = allLanguagesList.FirstOrDefault(x => x.Id == translation.LanguageId)?.IsoCode;

                if (string.IsNullOrWhiteSpace(translation.Value) || apiInstruction.OverwriteExistingValues)
                {
                    var    result          = _textService.MakeTranslationRequestAsync(valueToTranslate, subscriptionKey, uriBase, new[] { cultureToTranslateTo }, defaultLanguage.IsoCode);
                    JToken translatedValue = CommonHelpers.GetTranslatedValue(result);
                    translation.Value = translatedValue.ToString();
                }
            }
        }