Skip to main content

Integrate django-modeltranslation with lokalise.co

Project description

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modeltranslation-lokalise-0.1.5.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modeltranslation_lokalise-0.1.5-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file modeltranslation-lokalise-0.1.5.tar.gz.

File metadata

  • Download URL: modeltranslation-lokalise-0.1.5.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for modeltranslation-lokalise-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8767f3d1ef122d2ee0dc1e1c3ab46d6f4082ea3ad35c6f833d5d339680d4bf4f
MD5 739dc95ac97de76f3c08f6890a1fa99e
BLAKE2b-256 daad82ce5249930a63cc40b96913e8e07708b5d33fef4d0f7e984fe2d014e1f3

See more details on using hashes here.

File details

Details for the file modeltranslation_lokalise-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: modeltranslation_lokalise-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for modeltranslation_lokalise-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a3c797f39f80fb196f266546ee455d97b7198effb1daa6a04fa4cea1d0dbf2b0
MD5 3bd4fc86c6a41453200d5f78b57b1d6f
BLAKE2b-256 cba2bbafc61a773ef29de8767cfcde1abc93bd5be2dcdc60b59f40830edf7afc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page