Skip to main content

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

shiertier_i18n-0.0.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shiertier_i18n-0.0.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file shiertier_i18n-0.0.1.tar.gz.

File metadata

  • Download URL: shiertier_i18n-0.0.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for shiertier_i18n-0.0.1.tar.gz
Algorithm Hash digest
SHA256 721989b721782e0fcb16dc210ac5482a2a1c0de8c6e1f718b7a8d0c240fd67c3
MD5 4e314073a77ca219ced2b24e34d820a7
BLAKE2b-256 180dbb34bbe9091415dfa3b3df0d7e9cf548d0caa0de9edc32cdd6e55c02e37a

See more details on using hashes here.

File details

Details for the file shiertier_i18n-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: shiertier_i18n-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for shiertier_i18n-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 08577281e8c5cc583a4974834d36b712fb091ee9efd1005f73dc346e1f03f207
MD5 c846b9d602c80e272fd198b8609624f1
BLAKE2b-256 56a045d4e1370816de6e92472c89cff7eec785fe2462c30d4135962e8fb89cea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page