django-modeltranslation-wagtail¶
Keep-it-simple glue between django-modeltranslation and Wagtail.
Features¶
- Field-based translation for Wagtail using django-modeltranslation
- TODO Makes translated fields easily accessible to the Wagtail admin.
- Sensible to the currently activated language.
- The
Page
model isn’t modified (no migrations added to Wagtail), translations oftitle
,seo_title
andsearch_description
are local to the translated models.
How to use¶
You create Wagtail models and activate them with a <yourapp>.translation
module, just like you would with any other modeltranslation-based model.
In Wagtail, it’s the active language that decides what language you are editing in your translated model.
For instance, navigating to /en/wagtail/pages/add/<yourapp>/<yourmodel>/<ptr_id>/
will create a new page in English.
Drawback: There is currently no UI for the translation workflow. This means that users have to know that they need to switch /en/
with /fr/
in the URL path after creating an English entry to edit it in French.
When to use this¶
Actually, you might not want to use this! Consider carefully to use
wagtail-modeltranslation as it has
substantially improved by not hard-copying django-modeltranslation
anymore.
If you need to have 1:1 translation for Pages or Snippets in Wagtail, you could use django-modeltranslation.
However, wagtail-modeltranslation
is a complex project that patches a lot of external code and therefore often breaks with the latest versions of Wagtail.
If you only need freeform translation (when pages in the page-tree aren’t translated 1:1 but translations exist independently from one another), look no further than either Wagtail’s built-in simple_translation or wagtail-localize.
Background¶
Originally, I was using wagtail-modeltranslation. The project has been sparsely maintained, but more seriously, it was monkey-patching Wagtail and using a hard-copy of the modeltranslation codebase instead of a dependency reference to django-modeltranslation. The latter has now been restored, which as lowered the motivation for this project.
A few years later, I returned to use wagtail-modeltranslation but once again found myself spending way too much time understanding non-merged PRs etc. To be fair, the project has been maintained in the meantime, but it was lacking behind and I couldn’t figure out what to do to use it with the latest version of Wagtail.
This project introduces a bit of naming hell. But remember it like this: django-modeltranslation-wagtail has wagtail at the end because it depends on django-modeltranslation, which depends on django.
Using django-modeltranslation or wagtail-modeltranslation?¶
Switching is easy!
Since this project is directly based on django-modeltranslation, the creation of fields in the database and
django migrations remains the same. In case you are switching, just revisit your translation.py
files
and change the imports to point to modeltranslation_wagtail
.
Contents¶
Installation¶
At the command line either via easy_install or pip:
$ easy_install modeltranslation_wagtail
$ pip install modeltranslation_wagtail
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv modeltranslation_wagtail
$ pip install modeltranslation_wagtail
Usage¶
In your Django settings, you need to add the following
INSTALLED_APPS = [
# NOTE THE ORDER - IT MATTERS!
"modeltranslation_wagtail",
"modeltranslation",
]
To use django-modeltranslation-wagtail in myapp.translation
from modeltranslation.translator import register
from modeltranslation_wagtail.translator import TranslationOptions
from myapp.models import MyModel
@register(MyModel)
class MyModelTranslation(TranslationOptions):
fields = (
'content',
)
modeltranslation_wagtail¶
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/benjaoming/modeltranslation_wagtail/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
django-modeltranslation-wagtail could always use more documentation, whether as part of the official django-modeltranslation-wagtail docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/benjaoming/modeltranslation_wagtail/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up modeltranslation_wagtail for local development.
Fork the modeltranslation_wagtail repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/modeltranslation_wagtail.git
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass style and unit tests, including testing other Python versions with tox:
$ tox
To get tox, just pip install it.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy.
Check https://travis-ci.org/benjaoming/modeltranslation_wagtail
under pull requests for active pull requests or run the
tox
command and make sure that the tests pass for all supported Python versions.
History¶
0.4.1 (2021-12-24)¶
- Support for Wagtail StreamField
- Very sparse documentation (please do help to expand)
0.4 (2021-12-24)¶
- New tests
- Updates for Django 3 and Wagtail 2+
0.2.1 (2018-02-20)¶
- Changes to release meta data
0.2.0 (2017-12-17)¶
- Do not translate URL slugs for now, it breaks and needs a more patching in order to work.
0.1.0 (2017-01-20)¶
- First release on PyPI.
Feedback¶
If you have any suggestions or questions about django-modeltranslation-wagtail feel free to email me at benjamin@overtag.dk.
If you encounter any errors or problems with django-modeltranslation-wagtail, please let me know! Open an Issue at the GitHub http://github.com/benjaoming/modeltranslation_wagtail main repository.