Skip to main content

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.

Metadata

Release files for pylangs 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylangs 0.0.2
File Size Uploaded
pylangs-0.0.2.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylangs 0.0.2
File Interpreter ABI Platform
pylangs-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / pylangs-0.0.2.tar.gz

Download URL pylangs-0.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
93272c45534432d232dbbb5f75f660187463a6d3f9f7211de570bb523304b5d6
BLAKE2b-256 checksum
How to use checksums
c06a428503c7d21d578bdc3ab7d140280e5d9bddf99a71988de5ee545c441dca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / pylangs-0.0.2-py3-none-any.whl

Download URL pylangs-0.0.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b54c393b45fd27bbaef0a4cefeeeacbcc0493456e6482f9ddab31513005d20ba
BLAKE2b-256 checksum
How to use checksums
d3cdeb4f75a0d29897613365e5cd27b519259474c9d2cb4891cc76fc6e48de25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page