Skip to main content

Django modeltranslation-lokalise

Integrate django-modeltranslation with lokalise.co. It will let your project upload translatable fields of your model into lokalise.io using it's API and also update your local translations when someone updates them on lokalise. Currently suppors Lokalise-api v2 (thanks to @ddomenech).

Installing

pip install modeltranslation-lokalise

modeltranslation_lokalise depends on Django's contribtypes application, so make sure you include it in your INSTALLED_APPS setting before modeltranslation_lokalise:

INSTALLED_APPS = [
    ...
    'django.contrib.contenttypes',
    ...
    'modeltranslation_lokalise',
    ...
]

You need to provide your lokalise proyect id and your api key in order to let modeltranslation_lokalise properly update your translations.

LOKALISE_API_KEY = ''
LOKALISE_PROJECT_ID = ''

If you want to get your models updated automatically when someone updates them on lokalise, enable it by adding the view to your urls.py conf. Note that currently only translation.updated is supported:

from modeltranslation_lokalise import TranslationWebhookView

urlpatterns = [
    ...
    path('api/translations/', TranslationWebhookView.as_view(), name='translation_webhook'),
    ...
]

You also need to make migrations in order to create the necessary tables on your database to handle the translations:

python manage.py makemigrations
python manage.py migrate

How to use

Instead of using modeltranslation translator.register, you should use modeltranslation_lokalise.register_translation:

from modeltranslation.translator import TranslationOptions
from modeltranslation_lokalise.signals import register_translation

from your_app.models import Model1


class Model1TranslationOptions(TranslationOptions):
    fields = ('name', 'description',)


register_translation(Model1, Model1TranslationOptions)

And that's all, modeltranslations-lokalise will keep track of changes on your translatable models and import them in your lokalise project each time you update one of your translatable fields.

Non-lokalise translatable fields

It's possible that you want certain fields to be translatable in terms of modeltranslations but exclude them from being uploaded to Lokalise. In that case you can add an attribute non_lokalise_fields to your TranslationOptions object. Modeltranslation-lokalise will not track changes on that fields.

class ProductTranslationOptions(TranslationOptions):
    non_lokalise_fields = ('slug', )
    fields = ('title', 'description', ) + non_lokalise_fields

License

This project is licensed under the MIT License - see the LICENSE file for details

Release files for modeltranslation-lokalise 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modeltranslation-lokalise 0.2.0
File Size Uploaded
modeltranslation-lokalise-0.2.0.tar.gz 6.4 kB Details

Release files / modeltranslation-lokalise-0.2.0.tar.gz

Download URL modeltranslation-lokalise-0.2.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0c8eee8fc7f9935fada9755b95b02bbb262dd3c018db1b0ac0d0279e42e49dcd
BLAKE2b-256 checksum
How to use checksums
b3628f295e3decaebdd817eee7839c874a8dc1f79b4847a51a5fe0abf780e42e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page