Skip to main content

i18n engine for Django Framework

pypi version

Installation

Use the package manager pip to install django-i18n

pip3 install django-i18n

Setup

Before using library, you need setup some things in your django project, please follow this steps

  1. Setup all required variables in your settings.py
LOCALE = 'es' # Mandatory
LOCALE_FALLBACK = 'en' # Optional, default =  'en'
LOCALES = ['es'] # Mandatory
LOCALES_PATH = os.path.join(BASE_DIR, 'locales') # Optional, default path './locales' folder

INSTALLED_APPS = [
  ...
  'django_i18n',
  ...
]
  1. After that, you need create a locales folder (Setted in LOCALES_PATH variable in your settings.py), inside your folder you need some yml files with EXACT names as you setted in LOCALES variable, next you can see an example
en:
  my:
    title: "An incredible title"
    content: "Hello %{name}"

Usage in python files

from django_i18n.tools import translate, set_locale, handle_orm_errors

translate("my.title")
# OR
translate('my.content', name='World')

# Set locale
set_locale(locale="en", fallback="es") # Fallback is optional, default value is 'en'

# Handle ORM errors
form = MyForm(data)
handle_orm_errors(list_errors=form.errors, as_json=False)
# List errors is a Django forms errors
#as_json return dict as json string

Usage in template

{% load t from django_i18n %}

<html>
  <head>
    <title>{% t 'my.title' %}</title>
  </head>
  <body>
    <h1>{% t 'my.content' name='World' %}</h1>
  </body>
</head>

Fallback response

If you have setted a fallback, each translation may be return

translate('my.locale')
#> Fallback: An incredible title

If that key doesn't exists in your locale and your fallback, this is the response

translate('my.locale2')
#> Translation missin my.locale2

To Do

  1. Forms complete support handler
  2. Default messages for Django forms
  3. Other supported formats

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Metadata

Release files for django-i18n 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-i18n 1.0.5
File Size Uploaded Provenance Actions
django-i18n-1.0.5.tar.gz 7.3 kB Without provenance Details for django-i18n-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-i18n 1.0.5
File Interpreter ABI Platform Actions
django_i18n-1.0.5-py3-none-any.whl Python 3 none any Details for django_i18n-1.0.5-py3-none-any.whl

Total release size: 13.2 kB

Release files / django-i18n-1.0.5.tar.gz

Download URL django-i18n-1.0.5.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
250ad3fd07a53c8a59d8edd3c463faedf3f03d713e8f9484d2641065bafd6927
BLAKE2b-256 checksum
How to use checksums
3f00dd3f17b7b503a876bfc6c34329790b4c2f016cec420a54aa53e27e6a7770
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / django_i18n-1.0.5-py3-none-any.whl

Download URL django_i18n-1.0.5-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8058efe4893c569dd25e11d1fb2ac5520571c63ad4f055fb255de67511b59c47
BLAKE2b-256 checksum
How to use checksums
fbd62ee2b50adb4b2b924f8bc1fea96a33528f8b666613d62064303870048d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Security for django-i18n 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page