Mobetta

Manage translations in Django projects

https://travis-ci.org/maykinmedia/mobetta.svg?branch=master https://codecov.io/gh/maykinmedia/mobetta/branch/develop/graph/badge.svg https://img.shields.io/pypi/v/mobetta.svg https://lintly.com/gh/maykinmedia/mobetta/badge.svg

Mobetta is a reusable app to manage translation files in Django projects.

It’s inspired on django-rosetta, but takes a more modern approach to problem and adds extra features, such as:

Installation

The Quickstart section covers the basic installation without any extra plugins.

ICU message files

ICU message files support is optional, and can be installed in one go with:

pip install mobetta[icu]

Since this is set-up as a Django app as well, you’ll need to add it to INSTALLED_APPS:

INSTALLED_APPS = [
    ...,
    'mobetta',
    'mobetta.icu',
    ...,
]

Migrate your database to finalize the installation:

python manage.py migrate

Contributor

You can install the library with all the dev-dependencies with:

pip install -e .[icu,test,docs]

Usage

See the index page Usage for base-usage instructions. This covers the Django po/mo files.

ICU message files

The ICU message format is popular in the frontend, and it’s quite different from .po files. Django does not support them (out of the box).

After installing the ICU message plugin, you can still manage your translations with mobetta.

Navigate to the translation interface (localhost:8000/admin/mobetta/) and locate the ICU translation files. Create a new translation file, and point it to the JSON file containing the translations.

Currently, the only supported format is simple key-values, for example src/locale/en.json

{
    "myapp.unique.identifier": "My app is awesome!",
    "myapp.unique.identifier2": "My app is translated!"
}

The translations are checked to have a valid ICU message format.

Quickstart

Install with pip:

pip install mobetta

Add it to your installed apps:

INSTALLED_APPS = [
    ...,
    'mobetta',
    ...,
]

Hook up the urls in your root urls.py:

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),  # optional
    url(r'^admin/mobetta/', include('mobetta.urls', namespace='mobetta')),
    ...
]

Run migrate to create the necessary database tables:

python manage.py migrate

Usage

Mobetta discovers your translation files with a management command:

python manage.py locate_translation_files

Open localhost:8000/admin/mobetta/ to manage your translations.

Notes

How Django loads your translation files

See the django translation docs

Indices and tables