Beispiel #1
0
        public ActionResult Translate(string culture, int id)
        {
            var category = _repository.Find(id);

            var compared   = new CategoryModel(category);
            var translated = new CategoryModel
            {
                Id = category.Id
            };
            var diff = new CategoryModel
            {
                Id = category.Id
            };

            var translation = _translationStore.Find(CultureInfo.GetCultureInfo(culture), new EntityKey(typeof(Category), category.Id));

            if (translation != null)
            {
                translated.Name        = translation.GetTranslatedText("Name");
                translated.Description = translation.GetTranslatedText("Description");

                diff.Name        = DiffHelper.GetDiffHtml(translation.GetOriginalText("Name"), category.Name);
                diff.Description = DiffHelper.GetDiffHtml(translation.GetOriginalText("Description"), category.Description);
            }

            ViewBag.Compared   = compared;
            ViewBag.Difference = diff;

            return(View(translated));
        }
        private CustomFieldDefinitionModel LoadFieldDiff(CustomFieldDefinitionModel compared, string prefix, EntityTransaltion translation)
        {
            prefix = prefix + "[" + compared.Name + "].";

            var diff = new CustomFieldDefinitionModel
            {
                Id          = compared.Id,
                Name        = compared.Name,
                ControlType = compared.ControlType
            };

            if (translation != null)
            {
                diff.Label        = DiffHelper.GetDiffHtml(translation.GetOriginalText(prefix + "Label"), compared.Label);
                diff.DefaultValue = DiffHelper.GetDiffHtml(translation.GetOriginalText(prefix + "DefaultValue"), compared.DefaultValue);
            }

            foreach (var item in compared.SelectionItems)
            {
                var itemDiff = new SelectionItem {
                    Value = item.Value
                };
                if (translation != null)
                {
                    itemDiff.Text = DiffHelper.GetDiffHtml(translation.GetOriginalText(prefix + "SelectionItems[" + item.Value + "]"), item.Text);
                }
                diff.SelectionItems.Add(itemDiff);
            }

            return(diff);
        }
Beispiel #3
0
        private List <ProductVariantModel> GetVariants(Product product, ProductType productType, string culture)
        {
            var controls = FormControls.Controls().ToList();
            var models   = new List <ProductVariantModel>();

            foreach (var variant in product.Variants)
            {
                var variantKey  = new EntityKey(typeof(ProductVariant), variant.Id);
                var translation = _translationStore.Find(CultureInfo.GetCultureInfo(culture), variantKey);

                var model = new ProductVariantModel
                {
                    Id    = variant.Id,
                    Sku   = variant.Sku,
                    Price = variant.Price
                };

                foreach (var fieldDefinition in productType.VariantFieldDefinitions)
                {
                    // field might be null because admin can add new fields to product types when products already exist
                    var field    = variant.VariantFields.FirstOrDefault(f => f.FieldName == fieldDefinition.Name);
                    var control  = controls.Find(c => c.Name == fieldDefinition.ControlType);
                    var compared = new CustomFieldModel
                    {
                        FieldName  = fieldDefinition.Name,
                        FieldText  = control.GetFieldDisplayText(fieldDefinition, field == null ? null : field.FieldValue),
                        FieldValue = field == null ? null : field.FieldValue
                    };

                    var translated = new CustomFieldModel
                    {
                        FieldName  = compared.FieldName,
                        FieldText  = compared.FieldText,
                        FieldValue = compared.FieldValue
                    };

                    var diff = new CustomFieldModel
                    {
                        FieldName = compared.FieldName
                    };

                    // If the field value is entered in product editing page, then it's always the field value that get translated
                    if (translation != null && !control.IsSelectionList && !control.IsValuesPredefined)
                    {
                        translated.FieldText  = translation.GetTranslatedText("VariantFields[" + fieldDefinition.Name + "]");
                        translated.FieldValue = translated.FieldText;

                        diff.FieldText = DiffHelper.GetDiffHtml(translation.GetOriginalText("VariantFields[" + fieldDefinition.Name + "]"), field == null ? null : field.FieldValue);
                    }

                    model.VariantFields.Add(new TranslationTuple <CustomFieldModel>(compared, diff, translated));
                }

                models.Add(model);
            }

            return(models);
        }
Beispiel #4
0
        public ActionResult Translate(int id, string culture)
        {
            var brand    = _brandService.Find(id);
            var compared = new BrandModel
            {
                Id          = brand.Id,
                Name        = brand.Name,
                Description = brand.Description
            };

            var translated = new BrandModel
            {
                Id = brand.Id
            };

            var diff = new BrandModel
            {
                Id = brand.Id
            };

            var translation = _translationStore.Find(CultureInfo.GetCultureInfo(culture), EntityKey.FromEntity(brand));

            if (translation != null)
            {
                translated.Name        = translation.GetTranslatedText("Name");
                translated.Description = translation.GetTranslatedText("Description");

                diff.Name        = DiffHelper.GetDiffHtml(translation.GetOriginalText("Name"), brand.Name);
                diff.Description = DiffHelper.GetDiffHtml(translation.GetOriginalText("Description"), brand.Description);
            }

            ViewBag.Difference = diff;
            ViewBag.Compared   = compared;

            return(View(translated));
        }
Beispiel #5
0
        public ActionResult Translate(int id, string culture)
        {
            var product     = CurrentInstance.Database.Repository <Product>().Find(id);
            var productType = product.ProductType;

            var controls = FormControls.Controls().ToList();

            var compared   = Mapper.Map <Product, ProductModel>(product);
            var translated = Mapper.Map <Product, ProductModel>(product);
            var difference = new ProductModel();

            var productKey  = new EntityKey(typeof(Product), product.Id);
            var translation = _translationStore.Find(CultureInfo.GetCultureInfo(culture), productKey);

            if (translation != null)
            {
                translated.Name = translation.GetTranslatedText("Name");
                difference.Name = DiffHelper.GetDiffHtml(translation.GetOriginalText("Name"), product.Name);
            }

            // Custom fields
            // Product type definition might change, so we need to display fields base on product type definition
            compared.CustomFields.Clear();
            translated.CustomFields.Clear();

            foreach (var definition in productType.CustomFieldDefinitions)
            {
                var control = controls.Find(c => c.Name == definition.ControlType);
                var field   = product.CustomFields.FirstOrDefault(f => f.FieldName == definition.Name) ?? new ProductCustomField(definition.Name, null);

                var comparedField = MapOrDefault(definition, field);
                comparedField.FieldText = control.GetFieldDisplayText(definition, field == null ? null : field.FieldValue);
                compared.CustomFields.Add(comparedField);

                var translatedField = MapOrDefault(definition, field);
                translatedField.FieldText = comparedField.FieldText;

                var diffField = new CustomFieldModel {
                    FieldName = definition.Name
                };

                // If the field value is defined in product editing page, then it's always the field value that get translated
                if (translation != null && !control.IsSelectionList && !control.IsValuesPredefined)
                {
                    translatedField.FieldText  = translation.GetTranslatedText("CustomFields[" + field.FieldName + "]");
                    translatedField.FieldValue = translatedField.FieldText;

                    diffField.FieldText = DiffHelper.GetDiffHtml(translation.GetOriginalText("CustomFields[" + field.FieldName + "]"), comparedField.FieldText);
                }

                translated.CustomFields.Add(translatedField);
                difference.CustomFields.Add(diffField);
            }

            // Variants
            translated.Variants = GetVariants(product, productType, culture);

            ViewBag.ProductType = productType;
            ViewBag.Compared    = compared;
            ViewBag.Difference  = difference;

            return(View(translated));
        }