public void Can_get_localized_value_using_default_language()
        {
            // setup
            var language1 = LanguageRepository.Insert(CreateLanguage(1));
            var language2 = LanguageRepository.Insert(CreateLanguage(2));
            var entity    = new LocalizedEntity {
                Id = new ObjectId(CommonHelper.CurrentTime(), 1, 2, 3)
            };

            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value1, "language 1 value 1.", language1.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value2, "language 1 value 2", language1.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value1, "language 2 value 1", language2.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value2, "language 2 value 2", language2.Id);
            var setting = Kernel.Resolve <LocalizationSettings>();

            setting.DefaultLanguageId = language2.Id;
            Kernel.Resolve <ISettingService>().SaveSetting(setting);
            LocalizedEntityService = Kernel.Resolve <ILocalizedEntityService>();

            // act
            var value1 = LocalizedEntityService.GetLocalizedValue <LocalizedEntity>(entity.Id, x => x.Value1);
            var value2 = LocalizedEntityService.GetLocalizedValue <LocalizedEntity>(entity.Id, x => x.Value2);

            // assert
            value1.ShouldEqual("language 2 value 1");
            value2.ShouldEqual("language 2 value 2");
        }
Exemplo n.º 2
0
        private void TranslateProperty <T>(T property, string propertyName, int languageId) where T : BaseEntity
        {
            var propertyValue = (typeof(T)).GetProperty(propertyName).GetValue(property, null).ToString();
            var lan           = GetLocalizedProperty(property.Id, typeof(T).Name, propertyName, propertyValue, languageId);

            LocalizedEntityService.InsertLocalizedProperty(lan);
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
        public void Can_get_localized_value()
        {
            // setup
            var language = LanguageRepository.Insert(CreateLanguage());
            var entity   = new LocalizedEntity {
                Id = new ObjectId(CommonHelper.CurrentTime(), 1, 2, 3)
            };

            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value1, "Value 1...", language.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value2, "Value 2...", language.Id);

            // act
            var value1 = LocalizedEntityService.GetLocalizedValue <LocalizedEntity>(entity.Id, x => x.Value1, language.Id);
            var value2 = LocalizedEntityService.GetLocalizedValue <LocalizedEntity>(entity.Id, x => x.Value2, language.Id);

            // assert
            value1.ShouldEqual("Value 1...");
            value2.ShouldEqual("Value 2...");
        }
        public void Can_update_localized_properties()
        {
            // setup
            var language = LanguageRepository.Insert(CreateLanguage());
            var entity   = new LocalizedEntity {
                Id = new ObjectId(CommonHelper.CurrentTime(), 1, 2, 3)
            };

            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value1, "Value 1...", language.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value2, "Value 2...", language.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value1, "Value 1 updated...", language.Id);
            LocalizedEntityService.SaveLocalizedValue(entity, (x) => x.Value2, "Value 2 updated...", language.Id);

            // act
            var values = LocalizedEntityService.GetLocalizedProperties(entity);

            // assert
            values.Count.ShouldEqual(2);
            values[0].LocaleValue.ShouldEqual("Value 1 updated...");
            values[1].LocaleValue.ShouldEqual("Value 2 updated...");
        }