private void TranslateMetaKeywords(NopProduct nopProduct) { foreach (var googleLanguage in GoogleLanguage.Languages) { if (googleLanguage.Id != 1) { string translatedText = null; if (googleLanguage.Id == 2) { translatedText = @"保健品 维生素 抗衰老 医药 在线 护理 健康 美容 产品 减肥 处方药 药物 扑热息痛 皮肤 流感 阿司匹林 奶粉 婴儿食品 母婴用品 儿童 男人 女人 老人 小孩 自然 有机"; } else { var keywords = nopProduct.MetaKeywords.Replace(" ", "/ "); var language = GoogleLanguage.GetLanguageById(googleLanguage.Id); if (language != null && googleLanguage.Id != 1) { translatedText = NopDictionary.GetTranslate(keywords, googleLanguage.Id); if (string.IsNullOrWhiteSpace(translatedText)) { translatedText = Translator.Translate(keywords, "English", GoogleLanguage.GetLanguageById(googleLanguage.Id).Name); translatedText = translatedText.Replace("/", " "); } } } var lan = new LocalizedProperty { EntityId = nopProduct.Id, LanguageId = googleLanguage.Id, LocaleKey = "MetaKeywords", LocaleKeyGroup = "Prodcut", LocaleValue = translatedText }; LocalizedEntityService.InsertLocalizedProperty(lan); } } }
private LocalizedProperty GetLocalizedProperty(int entityId, string keyGroup, string key, string value, int languageId) { var language = GoogleLanguage.GetLanguageById(languageId); string translatedText = null; if (language != null && languageId != 1) { translatedText = NopDictionary.GetTranslate(value, languageId); if (string.IsNullOrWhiteSpace(translatedText)) { if (value.Contains("<") && value.Contains(">")) { translatedText = GetTranslateHtml(value, languageId); } else { translatedText = Translator.Translate(value, "English", GoogleLanguage.GetLanguageById(languageId).Name); } translatedText = translatedText.Replace("\\r \\n", "<br/>").Replace("\\r\\n", "<br/>").Replace("\\r", "<br/>").Replace("\\n", "<br/>"); } } return(new LocalizedProperty { EntityId = entityId, LanguageId = languageId, LocaleKey = key, LocaleKeyGroup = keyGroup, LocaleValue = translatedText }); //LocalizedSettingService.SaveSetting(lan, 1); }