Merge pull request #152 from dmarcelino/translation_options

Remove WagtailTranslationOptions and update docs
This commit is contained in:
Dário 2017-12-27 19:49:12 +00:00 committed by GitHub
commit bd93e06adc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 30 deletions

View file

@ -47,6 +47,7 @@ Quick start
INSTALLED_APPS = (
...
'wagtail_modeltranslation',
'wagtail_modeltranslation.makemigrations',
)
3. Add "django.middleware.locale.LocaleMiddleware" to MIDDLEWARE_CLASSES on your settings.py::
@ -71,18 +72,33 @@ Quick start
6. Create translation.py inside the root folder of the app where the model you want to translate exists::
from .models import Foo
from wagtail_modeltranslation.translator import WagtailTranslationOptions
from modeltranslation.translator import TranslationOptions
from modeltranslation.decorators import register
@register(Foo)
class FooTR(WagtailTranslationOptions):
class FooTR(TranslationOptions):
fields = (
'body',
)
7. Run :code:`python manage.py makemigrations` followed by :code:`python manage.py migrate`
7. Run :code:`python manage.py makemigrations` followed by :code:`python manage.py migrate` (repeat every time you add a new language)
8. Run :code:`python manage.py sync_page_translation_fields` (repeat every time you add a new language)
9. If you're adding :code:`wagtail-modeltranslation`:: to an existing site run :code:`python manage.py update_translation_fields`
Upgrade considerations (v0.8)
======================
This version includes breaking changes as some key parts of the app have been re-written. The most important change is that
``Page`` is now patched with translation fields.
To upgrade to this version you need to:
- Replace the ``WagtailTranslationOptions`` with ``TranslationOption`` in all translation.py files
- While optional it's recommended to add ``'wagtail_modeltranslation.makemigrations'`` to your INSTALLED_APPS
Upgrade considerations (v0.6)
======================

View file

@ -88,16 +88,16 @@ To setup the application please follow these steps:
When the LANGUAGES setting isn't present in ``settings/base.py`` (and neither is ``MODELTRANSLATION_LANGUAGES``), it defaults to Django's global LANGUAGES setting instead, and there are quite a few languages in the default!
2. Create a ``translation.py`` file in your app directory and register ``WagtailTranslationOptions`` for every model you want to translate.
2. Create a ``translation.py`` file in your app directory and register ``TranslationOptions`` for every model you want to translate.
.. code-block:: console
from .models import foo
from wagtail_modeltranslation.translator import WagtailTranslationOptions
from modeltranslation.translator import TranslationOptions
from wagtail_modeltranslation.translation import register
@register(foo)
class FooTR(WagtailTranslationOptions):
class FooTR(TranslationOptions):
fields = (
'body',
)
@ -106,4 +106,4 @@ To setup the application please follow these steps:
3. Run ``python manage.py makemigrations`` followed by ``python manage.py migrate``. This will add extra fields in the database.
4. Define the panels for the original fields, as you normally would, as wagtail-modeltranslation would generate the panels for the translated fields.
4. Define the panels for the original fields, as you normally would, as wagtail-modeltranslation will generate the panels for the translated fields.

View file

@ -9,14 +9,14 @@ Registering models for translation
Registering models and their fields used for translation requires the following steps:
1. Create **translation.py** in your app directory.
2. Define the models you want to use, import wagtail-modeltranslation's **WagtailTranslationOptions** and the django-modeltranslation **register** decorator
2. Define the models you want to use, import django-modeltranslation's **TranslationOptions** and the django-modeltranslation **register** decorator
3. Create a translation option class for every model you want to translate and precede the class with the **@register** decorator.
The django-modeltranslation application reads the **translation.py** file in your app directory thereby triggering the registration
of the translation options found in the file.
A translation option is a class that declares which model fields are needed for translation. The class must derive from
**wagtail_modeltranslation.translator.WagtailTranslationOptions** and it must provide a **field** attribute storing the list of
**modeltranslation.translator.TranslationOptions** and it must provide a **field** attribute storing the list of
field names. The option class must be registered with the **modeltranslation.decorators.register** instance.
To illustrate this let's have a look at a simple example using a **Foo** model. The example only contains an **introduction**
@ -27,11 +27,11 @@ Instead of a **Foo** model, this could be any Wagtail model class:
.. code-block:: console
from .models import Foo
from wagtail_modeltranslation.translation import WagtailTranslationOptions
from modeltranslation.translator import TranslationOptions
from modeltranslation.decorators import register
@register(Foo)
class FooTR(WagtailTranslationOptions):
class FooTR(TranslationOptions):
fields = (
'introduction',
'body',
@ -96,8 +96,8 @@ Committing fields to database
Modeltranslation supports the migration system introduced by Django 1.7. Besides the normal workflow as described in Django's
`Migration Docs <https://docs.djangoproject.com/en/1.8/topics/migrations/>`__, you should do a migration whenever one of the following changes have been made to your project:
- Added or removed a language through ``settings.LANGUAGES`` or ``settings.MODELTRANSLATION LANGUAGES``.
- Registered or unregistered a field through ``WagtailTranslationOptions``.
- Added or removed a language through ``settings.LANGUAGES`` or ``settings.MODELTRANSLATION LANGUAGES``.
- Registered or unregistered a field through ``TranslationOptions``.
It doesn't matter if you are starting a fresh project or change an existing one, it's always:
@ -106,6 +106,8 @@ It doesn't matter if you are starting a fresh project or change an existing one,
2. ``python manage.py migrate`` to apply the changes.
3. If you've added a new language ``python manage.py sync_page_translation_fields`` to add `Page` translation fields.
.. _required_langs:

View file

@ -55,14 +55,13 @@ class WagtailModeltranslationTransactionTestBase(TransactionTestCase):
# reload the translation module to register the Page model
# and also edit_handlers so any patches made to Page are reapplied
from wagtail_modeltranslation import translation as wag_translation, translator as wag_translator
from wagtail_modeltranslation import translation as wag_translation
from wagtail.wagtailadmin import edit_handlers
import sys
del cls.cache.all_models['wagtailcore']
sys.modules.pop('wagtail_modeltranslation.translation.pagetr', None)
sys.modules.pop('wagtail.wagtailcore.models', None)
imp.reload(wag_translation)
imp.reload(wag_translator)
imp.reload(edit_handlers) # so Page can be repatched by edit_handlers
wagtailcore_args = []
if django.VERSION < (1, 11):

View file

@ -1,15 +0,0 @@
from modeltranslation.translator import TranslationOptions
class WagtailTranslationOptions(TranslationOptions):
def __init__(self, model):
from wagtail.wagtailcore.models import Page
if Page in model.__bases__:
self.fields += (
'title',
'slug',
'seo_title',
'search_description',
'url_path',)
super(WagtailTranslationOptions, self).__init__(model)