Skip to main content

A Python library designed to simplify the management of multiple languages in projects that need to support internationalization.

Project description

PyLangs

PyLangs is a Python library designed to simplify the management of multiple languages in projects that need to support internationalization. Whether you're building a website, app, or any multilingual system, PyLangs makes it easy to store and retrieve messages in various languages with organized categories.


Features

  • Easy to Use: Simple API for adding and retrieving language-specific messages.
  • Category Support: Organize your messages by categories (e.g., general, support, etc.).
  • Flexible: Add messages for any language, and easily switch between them.
  • Fallback Support: Default fallback to a specified language if a message is missing in the current language.
  • Customizable: Supports adding, retrieving, and printing all messages or language-specific ones.

Installation

  • Install PyLangs via pip:
pip install pylangs

Usage

Initialize the language management system.

from pylangs import Langs

langs = Langs()

Simple Example

You can easily insert and retrieve messages in multiple languages.

# Insert Arabic and English welcome messages
langs.insert("ar", "WELCOME_MESSAGE", "السلام عليكم ورحمة الله, وبركاته")
langs.insert("ar", "SUPPORT_WELCOME_MESSAGE", "اهلًا بك في الدعم الفني!")
langs.insert("en", "WELCOME_MESSAGE", "Hi, How are you?")
langs.insert("en", "SUPPORT_WELCOME_MESSAGE", "Hi, This is Support, How can I help you?")

# Get messages in various scenarios
print(langs.get("ar", "WELCOME_MESSAGE"))  # Should print Arabic welcome message
print(langs.get("ar", "SUPPORT_WELCOME_MESSAGE"))  # Should print Arabic support welcome message
print(langs.get("en", "WELCOME_MESSAGE"))  # Should print English welcome message
print(langs.get("en", "SUPPORT_WELCOME_MESSAGE"))  # Should print English support welcome message

Using Categories

To further organize messages, you can assign them to categories, making it easier to handle messages for different contexts (e.g., general, support, etc.).

# Insert messages with categories
langs.insert("ar", "WELCOME_MESSAGE", "السلام عليكم ورحمة الله, وبركاته", category="GENERAL")
langs.insert("ar", "WELCOME_MESSAGE", "اهلًا بك في الدعم الفني!", category="SUPPORT")
langs.insert("en", "WELCOME_MESSAGE", "Hi, How are you?", category="GENERAL")
langs.insert("en", "WELCOME_MESSAGE", "Hi, Welcome to our support team, How can I help you today?", category="SUPPORT")

# Retrieve categorized messages
print(langs.get("ar", "WELCOME_MESSAGE", category="GENERAL"))  # Outputs: "السلام عليكم ورحمة الله, وبركاته"
print(langs.get("ar", "WELCOME_MESSAGE", category="SUPPORT"))  # Outputs: "اهلًا بك في الدعم الفني!"
print(langs.get("en", "WELCOME_MESSAGE", category="GENERAL"))  # Outputs: "Hi, How are you?"
print(langs.get("en", "WELCOME_MESSAGE", category="SUPPORT"))  # Outputs: "Hi, Welcome to our support team, How can I help you today?"

Printing All Messages

To print all messages across all languages:

print(langs)

To print messages for a specific language:

print(langs.en)  # Prints only English messages
print(langs.ar)  # Prints only Arabic messages

Example Output

Here’s an example of what the output might look like:

{
  "lang_code": "en",
  "categories": {
    "GENERAL": {
      "WELCOME_MESSAGE": "Hi, How are you?"
    },
    "SUPPORT": {
      "WELCOME_MESSAGE": "Hi, Welcome to our support team, How can I help you today?"
    }
  }
}

LICENSE

  • This project is licensed under the MIT License. See the LICENSE file for more information.

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

pylangs-0.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

pylangs-0.0.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pylangs-0.0.2.tar.gz.

File metadata

  • Download URL: pylangs-0.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pylangs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 93272c45534432d232dbbb5f75f660187463a6d3f9f7211de570bb523304b5d6
MD5 334fa5bfa6096c222cb6e1ad6b4e87b5
BLAKE2b-256 c06a428503c7d21d578bdc3ab7d140280e5d9bddf99a71988de5ee545c441dca

See more details on using hashes here.

Provenance

File details

Details for the file pylangs-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pylangs-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pylangs-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b54c393b45fd27bbaef0a4cefeeeacbcc0493456e6482f9ddab31513005d20ba
MD5 611ba1f1913827f38b95a343272be038
BLAKE2b-256 d3cdeb4f75a0d29897613365e5cd27b519259474c9d2cb4891cc76fc6e48de25

See more details on using hashes here.

Provenance

Supported by

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