Django bindings for Fluent, the localization system from Mozilla for today.
Project description
django-ftl is a Django package for using for Fluent, a localization system for today’s world. (It would have been called django-fluent but that was already taken).
This package builds upon fluent-compiler and provides:
A structure for setting up and managing your .ftl files.
Methods for switching/setting the current language.
Integration into Django templates.
Why would I use this?
The defacto standard in Django world is GNU Gettext. See this Fluent vs gettext page for a comparison. In brief, here are some advantages:
Fluent makes concerns like plural rules the job of the translator.
Fluent gives translators the power to obey language specific rules (gender, case, plurals) that the developer may not be aware of, and shouldn’t have to build into the software.
Fluent integrates number and date formatting, and gives both developer and translators control over these, instead of these having to be handled separately, and only controlled by the developer.
To give an example, in GNU Gettext there is support for plural rules. However, this is the only language specific feature Gettext supports, and it is kind of bolted on afterwards. The developer also has to partially hard code the English rules (that is, the fact that there are two variants in English), as per the Django docs:
msg = ngettext(
'there is %(count)d object.',
'there are %(count)d objects.',
count) % {
'count': count,
}
Finally, this still doesn’t work very well, because often you want to special case zero anyway - “there are no objects” (or “your inbox is empty” etc.) instead of “there are 0 objects”.
In Fluent, plural rules are one example of a more generic mechanism for selecting variants, and the translator is in control. The equivalent with fluent/django-ftl, with special handling of the zero case included, looks like this in an English .ftl file:
there-are-some-objects = { $count -> [0] There are no objects. [1] There is one object. [other] There are { $count } objects. }
The Python code referencing this will only need to use the ID (there-are-some-objects) and pass the $count argument.
Another problem that comes up is gender - for example, in French adjectives must agree in gender with the person being described. This can be solved in Fluent by passing the gender of the person as an argument, and allowing the translator to use the variant mechanism to write the correct language. This contrasts with GNU Gettext where the developer would have to create separate message strings for each case, because the message format is not powerful enough to allow the translator to add variant selection. Also, these different message strings will be identical in languages which don’t have that feature — in other words, the grammatical features of all languages end up either having a disproportionate effect on the source code and on other translators, or being neglected entirely.
Documentation
The documentation for how to use django-ftl is in the docs/folder and online at https://django-ftl.readthedocs.io.
Status
The library is now pretty stable, with a full test suite, no major missing features and no major breaking changes planned.
It has seen real-world usage in:
Learn Scripture - the original project it was created for, see the GitLab learnscripture.net project.
Probably a fair number of other projects, but I don’t know about them…
Credits
Tools used in rendering this package:
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
Built Distribution
File details
Details for the file django-ftl-0.14.tar.gz
.
File metadata
- Download URL: django-ftl-0.14.tar.gz
- Upload date:
- Size: 46.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f881f143dd6509175d5e0722407ddf42a84f4a10680ed972ed3b4c6ad2107aa |
|
MD5 | 2d95aab6049d88922a27086efb911a21 |
|
BLAKE2b-256 | 31ec52747f9e6d955aadc291618b453f9f92ebf1335ea7d44c4b48f6dc9697bf |
File details
Details for the file django_ftl-0.14-py3-none-any.whl
.
File metadata
- Download URL: django_ftl-0.14-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87e1b374fb307e9bfac402abc87b347212e02288ca2d333d27bdbc481c71e0bf |
|
MD5 | 1b42a98acafe79a4430155b7981b8877 |
|
BLAKE2b-256 | f6bd9db699374a4c01b8d7715d61cbc7948a26155a2de3e5d91f82cd9c762f0f |