masonite-localization
Introduction
Add multi-language support in your application.
Installation
pip install masonite-localization
Configuration
Add LocalizationProvider to your project in config/providers.py:
# config/providers.py
# ...
from localization import LocalizationProvider
# ...
PROVIDERS = [
# ...
# Third Party Providers
LocalizationProvider,
# ...
]
Then you can publish the package resources (if needed) by doing:
python craft package:publish localization
Usage
The setup is very simple. Once you publish the package verify if there's a lang directory in the root of your project or not, if not then create one and then create a json file named en.json put in some values in it or you can copy/paste following contents.
{
"message": "Hello"
}
By default you'll have english language setup in config which you can change. The locale can be changed on the fly as well.
You can add as many language json files as you wish. For eg; if need Japanese locale then, I will just copy everything from en.json file and then create new file named jp.json and then update the values in those json.
Getting Current Locale
from localization.facades import Localization
# Returns current locale
Localization.current_locale()
Changing Locale
from localization.facades import Localization
# Returns nothing
Localization.set_locale('jp')
Checking if current local matches
from localization.facades import Localization
# returns either True or False
Localization.is_locale('jp')
Retrieving Translations in Template
Imagine you have following translations in en.json locale file.
{
"message": "Hello, World!",
"notification": {
"message": "This is notification message."
}
}
Then you can retrieve translation strings as below in template.
{{ __("message") }}
<!-- OR -->
{{ __("notification.message") }}
License
masonite-localization is open-sourced software licensed under the MIT license.
Metadata
Release files for masonite-localization 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| masonite-localization-0.1.3.tar.gz | 10.7 kB | Without provenance | Details for masonite-localization-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| masonite_localization-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for masonite_localization-0.1.3-py3-none-any.whl |
Total release size: 18.6 kB
Release files / masonite-localization-0.1.3.tar.gz
| Download URL | masonite-localization-0.1.3.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3ba3feb194e6cff866aecfb8c9790596e39a9ad8bf6e41e7ad0bdea2510b3c0
|
|
BLAKE2b-256 checksum How to use checksums |
c4d75a74bc53fddda0fb4bb876e8400fd37cd464b636c77e1bf2747d0fb17cc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / masonite_localization-0.1.3-py3-none-any.whl
| Download URL | masonite_localization-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97c0da41ec8a2f9576d48e15d6e01d452a42c6b24e64800f35dc06f0b97294a8
|
|
BLAKE2b-256 checksum How to use checksums |
38069c7bd7f380a8d8338d75470e6d523cac76c4e7ea508b398e85d7ad0b0d1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Security for masonite-localization 0.1.3
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.