-
-
Save Pacu2/6f4d08f037f468ba411c66de44435a16 to your computer and use it in GitHub Desktop.
helper function that can be used to create translations for all database content in Saleor shop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_translations(): | |
# Helper function for debugging storefront | |
from saleor.product.models import ( | |
AttributeChoiceValueTranslation, | |
CategoryTranslation, CollectionTranslation, ProductTranslation, | |
ProductVariantTranslation, ProductAttributeTranslation) | |
from saleor.page.models import PageTranslation | |
from saleor.menu.models import MenuItemTranslation | |
from saleor.site.models import SiteSettingsTranslation | |
from saleor.discount.models import Voucher, VoucherTranslation | |
from saleor.site.models import SiteSettings | |
from saleor.menu.models import MenuItem | |
from django.conf import settings | |
settings.LANGUAGE_CODE = 'pl' | |
for i, category in enumerate(Category.objects.iterator()): | |
CategoryTranslation.objects.create( | |
language_code='pl', name='Kategoria %s' % category.pk, | |
category=category, | |
seo_title='Seo tytul kategoria %s' % category.pk, | |
seo_description='Seo opis kategoria %s' % category.pk) | |
for i, product in enumerate(Product.objects.iterator()): | |
ProductTranslation.objects.create( | |
language_code='pl', name='Produkt %s' % product.pk, | |
product=product, description='Opis produktu %s' % product.pk, | |
seo_title='Seo tytul produkt %s' % product.pk, | |
seo_description='Seo opis produkt %s' % product.pk) | |
for i, variant in enumerate(ProductVariant.objects.iterator()): | |
ProductVariantTranslation.objects.create( | |
language_code='pl', | |
name='Produkt %s Wariant %s' % (variant.product.pk, variant.pk), | |
product_variant=variant) | |
for i, collection in enumerate(Collection.objects.iterator()): | |
CollectionTranslation.objects.create( | |
language_code='pl', name='Kolekcja %s' % collection.pk, | |
collection=collection, | |
seo_title='Seo tytul kolekcja %s' % collection.pk, | |
seo_description='Seo opis kolekcja %s' % collection.pk) | |
for i, menu_item in enumerate(MenuItem.objects.iterator()): | |
name = 'Przedmiot %s' % menu_item.pk | |
MenuItemTranslation.objects.create( | |
language_code='pl', name=name, | |
menu_item=menu_item) | |
for i, page in enumerate(Page.objects.iterator()): | |
PageTranslation.objects.create( | |
language_code='pl', title='Strona %s' % page.pk, | |
page=page, content='Zawartosc strony %s' % page.pk, | |
seo_title='Seo tytul strona %s' % page.pk, | |
seo_description='Seo opis strona %s' % page.pk) | |
for attr in ProductAttribute.objects.iterator(): | |
ProductAttributeTranslation.objects.create( | |
language_code='pl', name='Atrybut %s' % attr.pk, | |
product_attribute=attr) | |
for value in AttributeChoiceValue.objects.iterator(): | |
AttributeChoiceValueTranslation.objects.create( | |
language_code='pl', name='Wartość %s' % value.pk, | |
attribute_choice_value=value) | |
for site_set in SiteSettings.objects.iterator(): | |
SiteSettingsTranslation.objects.create( | |
site_settings=site_set, language_code='pl', | |
header_text='Tekst nagłówka po polsku %s' % site_set.pk, | |
description='Opis strony, tez po polsku %s' % site_set.pk) | |
for voucher in Voucher.objects.iterator(): | |
VoucherTranslation.objects.create( | |
language_code='pl', voucher=voucher, name='Nazwa vouchera') | |
from ...dashboard.menu.utils import update_menu | |
for menu in Menu.objects.iterator(): | |
update_menu(menu) | |
from saleor.order.models import OrderLine | |
for line in OrderLine.objects.iterator(): | |
line.translated_product_name = line.variant.display_product( | |
translated=True) | |
line.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment