- Command: sorts translation files by key.
- Supports nested translation keys.
- Replacing Parameters in Translation Strings.
Package description in one line displayed e.g. in README
- Add your package main features here
- and here
New to Masonite ? Please first read the Official Documentation. Masonite strives to have extremely comprehensive documentation 😃. It would be wise to go through the tutorials there. If you find any discrepencies or anything that doesn't make sense, be sure to comment directly on the documentation to start a discussion!
Have questions or want to talk? Be sure to join the Masonite Discord Community!
pip install masonite-lang
Add LangProvider to your project in config/providers.py
:
# config/providers.py
# ...
from lang import LangProvider
# ...
PROVIDERS = [
# ...
# Third Party Providers
LangProvider,
# ...
]
Then you can publish the package resources (if needed) by doing:
python craft package:publish lang
Set your application locale in .env
:
APP_LOCALE=en
defaults to 'en' if not set.
Create language files in the /locales
directory:
/locales
en.json
es.json
zh_CN.json
Example translation file (en.json
):
{
"welcome": "Welcome to our application"
}
from lang.facades import Lang
Lang.current_locale()
Lang.set_locale('en')
Lang.is_locale('en')
Lang.trans('trans')
In your templates, use the __()
helper to display translated text:
{{ __('not') }}
If the specified translation string does not exist, the __ function will return the translation string key.
Please read the Contributing Documentation here.
Masonite Lang is open-sourced software licensed under the MIT license.