Metadata-Version: 2.1
Name: shiertier_i18n
Version: 0.0.4
Summary: A simple internationalization (i18n) library for Python.
Author-email: shiertier <junjie.text@gmail.com>
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.
        
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: shiertier-logger

# 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.
