GitXplorerGitXplorer
b

okrand

public
11 stars
0 forks
2 issues

Commits

List of commits on branch main.
Unverified
240ffe3660ae501efc1b200e0bd17a18b55393b1

Release

bboxed committed 2 months ago
Unverified
8bd8cd5627f02e6535f5cdb75c79b9bdf1b9f907

Plugin system

bboxed committed 2 months ago
Unverified
366414bc747f2da54a7f6c1197db252317b8eee5

Release

bboxed committed 2 months ago
Unverified
9a4a71ad20823056c7312f071649131e49609547

Fix plural handling for Django models (fixes #7), and also allow a list of prefixes to translate (to avoid translating all of Django and third party libs)

bboxed committed 2 months ago
Unverified
86491a6d41cc49ded57975dd2d0e201cd45158f4

Release

bboxed committed 4 months ago
Unverified
5bac8ca899f829803dfd1d449ef9e939e0c02223

Fixed crash with translation strings with many spaces, _ and/or parenthesis

bboxed committed 4 months ago

README

The README file for this repository.

Okrand

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:

.. code-block::

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

So concretely this model:

.. code-block:: python

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:

.. code-block:: python

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:

.. code-block:: python

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

.. code-block::

[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

Installing the frontend

There is a built in web based frontend to okrand. To install it first install iommi <https://docs.iommi.rocks/en/latest/getting_started.html>_.

Then add the following to your urls.py:

.. code-block:: python

from okrand.views import i18n

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

What does "Okrand" mean?


`Marc Okrand <https://en.wikipedia.org/wiki/Marc_Okrand>`_ is a linguist who is best known for his work on Star Trek where he created the Klingon language.