A simple internationalization (i18n) library for Python.
Project description
shiertier_i18n
english | 中文
Introduction
shiertier_i18n is a simple internationalization (i18n) library for Python, designed to help developers easily localize their applications into different languages. The library is based on the gettext module and supports automatic detection of language and localization directories from environment variables, providing a simple interface for translating strings.
Installation
You can install shiertier_i18n via pip:
pip install git+https://github.com/shiertier/shiertier_i18n.git
Please note that this project is still under development.
Usage
Initialization
First, you need to initialize the I18n class:
from shiertier_i18n import I18n
# Using default language and localization directory
i18n = I18n()
# Or specify the language and localization directory
i18n = I18n(language_str='zh_CN', locales_dir='/path/to/locales')
Translating Strings
You can use the translate method to translate strings:
translated_str = i18n.translate("Hello, world!")
print(translated_str)
You can also pass a dictionary to replace placeholders in the translated string:
translated_str = i18n.translate("Hello, $$name$$!", replace_dict={'$$name$$': 'Alice'})
print(translated_str)
Shortcut
If you only need to quickly translate a string, you can use the easy_i18n shortcut:
from shiertier_i18n import easy_i18n
translated_str = easy_i18n("Hello, world!")
print(translated_str)
Configuration
Language
By default, the I18n class will get the language setting from the LANGUAGE environment variable. If LANGUAGE is not set, it defaults to en_US.
You can also specify the language when initializing the I18n class:
i18n = I18n(language_str='zh_CN')
Localization Directory
By default, the I18n class will get the localization directory from the SHIERTIER_LOCALES_DIR environment variable. If SHIERTIER_LOCALES_DIR is not set, it defaults to the .shiertier/locales directory under the user's home directory.
You can also specify the localization directory when initializing the I18n class:
i18n = I18n(locales_dir='/path/to/locales')
Dependencies
gettext
License
This project is released under the MIT License. See the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shiertier_i18n-0.0.3.tar.gz.
File metadata
- Download URL: shiertier_i18n-0.0.3.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52a6ab995fee292403569a3ba58e8b883c890a6e987a9a553ba76704c90ee1d6
|
|
| MD5 |
41407eb57aec3c79933bb710bd65288a
|
|
| BLAKE2b-256 |
9a5ee868a7b37a434d8486a0d9a2cd07c673d0fda5145c53a625fa8d6972d0f9
|
File details
Details for the file shiertier_i18n-0.0.3-py3-none-any.whl.
File metadata
- Download URL: shiertier_i18n-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33cdc76b393e7e2c394916719eef314bee1b15de2e169f6f25a26dc7a11639bc
|
|
| MD5 |
5a9d3c800d1e3353eb9717290e089d57
|
|
| BLAKE2b-256 |
eac36879d6de222aeadb04022b3c1cebdbcd13ad55855cdbed3556275660bbaa
|