Skip to main content

Okrand is an internationalization/translation tool for Django

Project description

Okrand is an internationalization/translation tool for Django.

It is a pure Python program so doesn’t rely on gettext.

Okrand will respect your .gitignore.

Django models

Okrand can upgrade Django models so translation is much easier. You don’t need to write verbose_name anymore! And if you do write them Okrand will upgrade raw strings to gettext_lazy.

Turn this feature on in your setup.cfg:

[tool:okrand]
django_model_upgrade=1
django_model_prefixes=
    your_package.

So concretely this model:

from django.utils.translation import gettext_lazy as _


class Book(Model):
    name = CharField(verbose_name=_('name'))
    isbn = CharField(verbose_name=_('ISBN'))

    class Meta:
        verbose_name = _('book')
        verbose_name = _('books')

Can now be changed to the more natural:

class Book(Model):
    name = CharField()
    isbn = CharField(verbose_name='ISBN')

Note that you don’t need to wrap the verbose_name in a gettext_lazy call anymore.

Installation

First pip install okrand, then add okrand to INSTALLED_APPS.

Add OKRAND_STATIC_PATH to settings, pointing to where Okrand should write the JavaScript catalog files. Typically something like:

OKRAND_STATIC_PATH = Path(BASE_DIR) / 'yourproject' / 'base' / 'static'

If you have a base app to put common stuff.

Configuration

In setup.cfg you set:

  • additional ignore rules beyond .gitignore. These are regexes for the full path.

  • sorting: none (default), alphabetical

  • if the django model upgrade is enabled

  • custom collector functions

  • turn off rename support

[tool:okrand]
ignore=
    .*some_annoying_path.*
sort=alphabetical
django_model_upgrade=1
django_model_prefixes=
    some_app.
    another_app.
find_source_strings_plugins=
    your.module.function_name
renames=0

Installing the frontend

There is a built in web based frontend to okrand. To install it first install iommi.

Then add the following to your urls.py:

from okrand.views import i18n

urlpatterns = [
    path('i18n/', i18n),
]

What does “Okrand” mean?

Marc Okrand is a linguist who is best known for his work on Star Trek where he created the Klingon language.

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

okrand-1.7.0.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

okrand-1.7.0-py2.py3-none-any.whl (29.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file okrand-1.7.0.tar.gz.

File metadata

  • Download URL: okrand-1.7.0.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for okrand-1.7.0.tar.gz
Algorithm Hash digest
SHA256 247dd12d2b14ce1049088237d52e791a512a22f40b787fa4b003eda4196c119f
MD5 5015940acc126907bbfe557d1037eafb
BLAKE2b-256 a49701b4d9b85c2b89b2d3930d982376784ce70f94af0f9ad9b302e14d95491e

See more details on using hashes here.

File details

Details for the file okrand-1.7.0-py2.py3-none-any.whl.

File metadata

  • Download URL: okrand-1.7.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for okrand-1.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 434c165208d1f0138cd235e57e0c8ab7a5824522b81a7ce48f0057fdabe7c029
MD5 a66ebb6356054038e599e5d16ea61934
BLAKE2b-256 9737a52f46a914697904bf9664b4a49cfd6b910c6d5c79719ccb49aee39633d1

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