Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
wagtail-modeltranslation
Advanced tools
This app is built using core features of django-modeltranslation: https://github.com/deschler/django-modeltranslation
It's an alternative approach for i18n support on Wagtail CMS websites.
The wagtail-modeltranslation application is used to translate dynamic content of existing Wagtail models to an arbitrary number of languages, without having to change the original model classes. It uses a registration approach (comparable to Django's admin app) to add translations to existing or new projects and is fully integrated into the Wagtail admin UI.
The advantage of a registration approach is the ability to add translations to models on a per-app basis. You can use the same app in different projects, whether or not they use translations, and without touching the original model class.
.. image:: https://github.com/infoportugal/wagtail-modeltranslation/blob/master/screenshot.png?raw=true :target: https://github.com/infoportugal/wagtail-modeltranslation/blob/master/screenshot.png?raw=true
:code:wagtail-modeltranslation
patches Wagtail's :code:Page
model with translation fields
:code:title_xx
, :code:slug_xx
, :code:seo_title_xx
, :code:search_description_xx
and :code:url_path_xx
where "xx" represents the language code for each translated language. This
is done without migrations through command :code:sync_page_translation_fields
. Since :code:Page
model belongs to
Wagtail it's within the realm of possibility that one day Wagtail may add a conflicting field to :code:Page
thus interfering with :code:wagtail-modeltranslation
.
Wagtail's :code:slugurl
tag does not work across languages. :code:wagtail-modeltranslation
provides a drop-in replacement named :code:slugurl_trans
which by default takes the slug parameter in the default language.
Install :code:wagtail-modeltranslation
::
pip install wagtail-modeltranslation
Add 'wagtail_modeltranslation' to your INSTALLED_APPS
setting like this (before all apps that you want to translate)::
INSTALLED_APPS = ( ... 'wagtail_modeltranslation', 'wagtail_modeltranslation.makemigrations', 'wagtail_modeltranslation.migrate', )
Add 'django.middleware.locale.LocaleMiddleware' to MIDDLEWARE
on your settings.py
::
MIDDLEWARE = ( ... 'django.middleware.locale.LocaleMiddleware', # should be after SessionMiddleware and before CommonMiddleware )
Enable i18n on settings.py
::
USE_I18N = True
Define available languages on settings.py
::
from django.utils.translation import gettext_lazy as _
LANGUAGES = ( ('pt', _('Portuguese')), ('es', _('Spanish')), ('fr', _('French')), )
Create translation.py
inside the root folder of the app where the model you want to translate exists::
from .models import Foo from modeltranslation.translator import TranslationOptions from modeltranslation.decorators import register
@register(Foo) class FooTR(TranslationOptions): fields = ( 'body', )
Run :code:python manage.py makemigrations
followed by :code:python manage.py migrate
(repeat every time you add a new language or register a new model)
Run :code:python manage.py sync_page_translation_fields
(repeat every time you add a new language)
If you're adding :code:wagtail-modeltranslation
to an existing site run :code:python manage.py update_translation_fields
.. list-table:: Title :widths: 25 25 25 25 :header-rows: 1
= 1.12, < 2.12
= 1.11
= 2.13, < 3.0
= 3.0
= 3.0, < 4.0
= 3.2
= 4.0, < 5.0
= 3.2
= 5.0, < 6.0
= 3.2
= 5.2
= 4.2
change_lang
now needs a second parameter, page
This version includes breaking changes as some key parts of the app have been re-written:
Page
is now patched with translation fields.WAGTAILMODELTRANSLATION_ORIGINAL_SLUG_LANGUAGE
setting has been deprecated.To upgrade to this version you need to:
WagtailTranslationOptions
with TranslationOptions
in all translation.py filespython manage.py sync_page_translation_fields
at least once to create Page
's translation fields{% slugurl ... %}
for :code:wagtail-modeltranslation
's own {% slugurl_trans ... %}
'wagtail_modeltranslation.makemigrations'
to your INSTALLED_APPS. This will override Django's makemigrations
command to avoid creating spurious Page
migrations.This version has some important changes as there was a refactoring to include django-modeltranslation as a dependency instead of duplicating their code in our version. This allow us to focus on Wagtail admin integration features as django-modeltranslation is very well mantained and is very quickly to fix problems with the latest Django versions. This way we also keep all the django-modeltranslation features (if you want you can also customize django-admin, for example). We also provide a new class to create the translation options classes: WagtailTranslationOptions Most of the changes are related to imports as they change from wagtail-modeltranslation to modeltranslation.
To upgrade to this version you need to:
TranslationOptions
with WagtailTranslationOptions
in all translation.py filesfrom modeltranslation.decorators import register
from modeltranslation.translator import translator
https://github.com/infoportugal/wagtail-modeltranslation
FAQs
Translates Wagtail CMS models using a registration approach.
We found that wagtail-modeltranslation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.