Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shiertier-i18n

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shiertier-i18n

A simple internationalization (i18n) library for Python.

  • 0.0.6
  • PyPI
  • Socket score

Maintainers
1

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-utils/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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc