How to actually duplicate the page tree and choose page language when adding content?

362 views
Skip to first unread message

Robin Eriksen

unread,
Dec 14, 2015, 12:32:58 AM12/14/15
to Wagtail support
I am trying to follow the docs for 1.2 where I'm trying to duplicate the page tree to get a bilingual site, but it is not clear to me from the documentation how to actually set the language when creating a page and how the page tree is actually duplicated when creating new models that use the `TranslatablePageMixin`.

I have added the mixin, the `LanguageRedirectionPage` class, the `i18n_patterns`, the `LocaleMiddleware` to MIDDLEWARE_CLASSES, set LANGUAGES and LANGUAGE_CODE and ensured that `USE_I18N = True`, as well as adding the links to the template file.

Any help is highly appreciated.

PS: I tried to add some code, but the template code messed up the formatting, since it tried to parse the HTML code I wanted to show :(

Dino Luk

unread,
Dec 15, 2015, 4:30:40 AM12/15/15
to Wagtail support
Follow the docs here: http://wagtail.readthedocs.org/en/v1.2/advanced_topics/i18n/duplicate_tree.html

This is what you should do in Wagtail admin, considering you have model like this

class HomePage(Page, TranslatablePageMixin):
   
pass

1. Log into wagtail admin, go to Settings -> Sites
2. Delete current site
3. Go to Root and delete default Wagtail page
4. While in Root, create new LanguageRedirectPage (title and slug values don't matter)
5. Go to Settings -> Sites and create new Site (hostname=localhost, port=80, is_default=True, checked, root page is LanguageRedirectPage created in step 4)
6. Go to LanguageRedirectPage created in step 4 and from there create new HomePage. Title value doesn't matter, but slug field should be set to one of Django language codes: en - english, fr - french, es - spanish, ... Let's say that here you defined slug as 'en'
7. repeat step 6 and DUPLICATE page tree content but this time set slug field to let's say 'fr'

Because you need to define every page twice (if bilingual site) it is called duplicating page tree content. You will end up with two homepages (one in english, the other in french or whatever other language) and at the end you will have two similar page tree structures. 

Now, if you want to test how TranslatablePageMixin works, easiest way for me was to define a language cookie (considering you have everything set up in your Django settings): document.cookie="django_language=de; expires=Fri 18 Dec 2015 12:00:00 UTC; path=/" 
Other options are: changing browser settings, removig LocaleMiddleware from Django settings, using sessins, ... Here is how django discovers language preference: https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#how-django-discovers-language-preference
Reply all
Reply to author
Forward
0 new messages