Name | shiertier-i18n JSON |
Version |
0.0.6
JSON |
| download |
home_page | None |
Summary | A simple internationalization (i18n) library for Python. |
upload_time | 2024-11-06 13:03:29 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | MIT License Copyright (c) 2024 shiertier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# shiertier_i18n
english | [中文](https://github.com/shiertier-utils/shiertier_i18n/blob/main/README_zh.md)
## 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`:
```bash
pip install git+https://github.com/shiertier-utils/shiertier_i18n.git
```
Please note that this project is still under development.
## Usage
### Initialization
First, you need to initialize the `I18n` class:
```python
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:
```python
translated_str = i18n.translate("Hello, world!")
print(translated_str)
```
You can also pass a dictionary to replace placeholders in the translated string:
```python
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:
```python
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:
```python
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:
```python
i18n = I18n(locales_dir='/path/to/locales')
```
## Dependencies
- `gettext`
## License
This project is released under the MIT License. See the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "shiertier-i18n",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "shiertier <junjie.text@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/48/50/6d7ce0b440b5296bf633f05d569a658fd638310f8dddabd4eb8f8a41ef2b/shiertier_i18n-0.0.6.tar.gz",
"platform": null,
"description": "# shiertier_i18n\nenglish | [\u4e2d\u6587](https://github.com/shiertier-utils/shiertier_i18n/blob/main/README_zh.md)\n\n## Introduction\n\n`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.\n\n## Installation\n\nYou can install `shiertier_i18n` via `pip`:\n\n```bash\npip install git+https://github.com/shiertier-utils/shiertier_i18n.git\n```\n\nPlease note that this project is still under development.\n\n## Usage\n\n### Initialization\n\nFirst, you need to initialize the `I18n` class:\n\n```python\nfrom shiertier_i18n import I18n\n\n# Using default language and localization directory\ni18n = I18n()\n\n# Or specify the language and localization directory\ni18n = I18n(language_str='zh_CN', locales_dir='/path/to/locales')\n```\n\n### Translating Strings\n\nYou can use the `translate` method to translate strings:\n\n```python\ntranslated_str = i18n.translate(\"Hello, world!\")\nprint(translated_str)\n```\n\nYou can also pass a dictionary to replace placeholders in the translated string:\n\n```python\ntranslated_str = i18n.translate(\"Hello, $$name$$!\", replace_dict={'$$name$$': 'Alice'})\nprint(translated_str)\n```\n\n### Shortcut\n\nIf you only need to quickly translate a string, you can use the `easy_i18n` shortcut:\n\n```python\nfrom shiertier_i18n import easy_i18n\n\ntranslated_str = easy_i18n(\"Hello, world!\")\nprint(translated_str)\n```\n\n## Configuration\n\n### Language\n\nBy default, the `I18n` class will get the language setting from the `LANGUAGE` environment variable. If `LANGUAGE` is not set, it defaults to `en_US`.\n\nYou can also specify the language when initializing the `I18n` class:\n\n```python\ni18n = I18n(language_str='zh_CN')\n```\n\n### Localization Directory\n\nBy 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.\n\nYou can also specify the localization directory when initializing the `I18n` class:\n\n```python\ni18n = I18n(locales_dir='/path/to/locales')\n```\n\n## Dependencies\n\n- `gettext`\n\n## License\n\nThis project is released under the MIT License. See the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 shiertier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A simple internationalization (i18n) library for Python.",
"version": "0.0.6",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2d090a14ddc81d3b2429e775411e72b65be378c5f24aaadceb191a6973631594",
"md5": "82ae2dd31b94fcb10461666d994fa923",
"sha256": "7abed9f79a23f5be4e1c21b5863232ed805b46c75b633cbe27e5369039509fab"
},
"downloads": -1,
"filename": "shiertier_i18n-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "82ae2dd31b94fcb10461666d994fa923",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 4493,
"upload_time": "2024-11-06T13:03:27",
"upload_time_iso_8601": "2024-11-06T13:03:27.957541Z",
"url": "https://files.pythonhosted.org/packages/2d/09/0a14ddc81d3b2429e775411e72b65be378c5f24aaadceb191a6973631594/shiertier_i18n-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "48506d7ce0b440b5296bf633f05d569a658fd638310f8dddabd4eb8f8a41ef2b",
"md5": "3dcbbd366026c83c508a14679e29330a",
"sha256": "962ad1e18378dd5333133b47c198c4ff6bd1516445c387946afeabdb25cd7e0b"
},
"downloads": -1,
"filename": "shiertier_i18n-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "3dcbbd366026c83c508a14679e29330a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 3590,
"upload_time": "2024-11-06T13:03:29",
"upload_time_iso_8601": "2024-11-06T13:03:29.231645Z",
"url": "https://files.pythonhosted.org/packages/48/50/6d7ce0b440b5296bf633f05d569a658fd638310f8dddabd4eb8f8a41ef2b/shiertier_i18n-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-06 13:03:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "shiertier-i18n"
}