Skip to main content

A simple language manager for Python projects.

Project description

Lang Custom v1.1.5

Lang Custom is a Python library for managing translations from JSON files, powered by SQLite for fast queries and low memory usage. Perfect for bots or multilingual apps needing high performance and easy maintenance.


🆕 What's New in v1.1.5?

  • Default Parameters: Set default language, group, and type to simplify calls to get and batch:
    await lang_custom.default(language="en", group="reply", type="text")
    text = await lang_custom.get(name="greeting")  # Uses defaults
    
  • Batch Retrieval: Fetch multiple values at once with a single query:
    result = await lang_custom.batch(language="en", group="error", type="text", names=["not_found", "invalid", "missing"])
    print(result)  # {'not_found': 'Resource not found', 'invalid': 'Invalid input', 'missing': ''}
    
  • Auto-initialization: Database and JSON files are loaded on import lang_custom. No need for language_setup().
  • ✅ Support for full reload or single-language reload from JSON.
  • ✅ Smart warnings: Suggests corrections for invalid group, name, or type (e.g., "Did you mean 'replies'?").
  • ✅ Unified API: Replaced old lang(), group(), get_text(), random_text() with a single function:
    await lang_custom.get(language="en", group="error", type="text", name="not_found")
    

📦 Installation

pip install lang_custom==1.1.4

🚀 Usage Guide

1. Import the library

import lang_custom

Database is automatically initialized, ready to use 🎉


2. Set default parameters (optional)

Simplify queries by setting defaults for language, group, and type:

await lang_custom.default(language="en", group="reply", type="text")

3. Query language data

# Using defaults
text = await lang_custom.get(name="greeting")  # Uses language="en", group="reply", type="text"
print(text)  # hello :D

# Override defaults
random_text = await lang_custom.get(type="random", name="greetings")
print(random_text)  # hello :D, hi :3, or hey there!

# Full parameters
error_text = await lang_custom.get(language="en", group="error", type="text", name="not_found")
print(error_text)  # Resource not found
  • type="text": Returns a fixed string.
  • type="random": Returns a random item from a list.

4. Batch query multiple values

Fetch multiple values in one call:

result = await lang_custom.batch(names=["greeting", "welcome", "missing"])  # Uses defaults
print(result)  # {'greeting': 'hello :D', 'welcome': 'hi :3', 'missing': ''}

# With full parameters
result = await lang_custom.batch(language="en", group="error", type="text", names=["not_found", "invalid"])
print(result)  # {'not_found': 'Resource not found', 'invalid': 'Invalid input'}

5. List available languages

langs = await lang_custom.get_lang()
print(langs)  # ['en', 'vi', 'jp']

6. Reload language data

await lang_custom.reload()  # Reload all from JSON
await lang_custom.reload_language("en")  # Reload only "en"

📁 Example _data_language/en.json

{
    "reply": {
        "text": {
            "greeting": "hello :D",
            "welcome": "hi :3"
        },
        "random": {
            "greetings": ["hello :D", "hi :3", "hey there!"]
        }
    },
    "error": {
        "text": {
            "not_found": "Resource not found",
            "invalid": "Invalid input"
        },
        "random": {
            "errors": ["Oops, something went wrong!", "Uh-oh, try again!"]
        }
    }
}

⚠️ Notes

  • Do not delete the _data_language/ folder or DO_NOT_DELETE.db file while the app is running.
  • To update translations, edit JSON files and call reload() or reload_language().

💬 Feedback & Issues

Join our Discord: 👉 https://discord.gg/pGcSyr2bcY


Thank you for using Lang Custom! 🚀
Thank you


Lang Custom v1.1.5

Lang Custom là thư viện Python quản lý bản dịch từ tệp JSON, dùng SQLite để truy vấn nhanh và tiết kiệm bộ nhớ. Lý tưởng cho bot hoặc ứng dụng đa ngôn ngữ cần hiệu suất cao và dễ bảo trì.


🆕 Có gì mới trong v1.1.5?

  • Thiết lập mặc định: Đặt language, group, và type mặc định để đơn giản hóa getbatch:
    await lang_custom.default(language="en", group="reply", type="text")
    text = await lang_custom.get(name="greeting")  # Dùng giá trị mặc định
    
  • Lấy hàng loạt: Lấy nhiều giá trị cùng lúc trong một truy vấn:
    result = await lang_custom.batch(language="en", group="error", type="text", names=["not_found", "invalid", "missing"])
    print(result)  # {'not_found': 'Resource not found', 'invalid': 'Invalid input', 'missing': ''}
    
  • Tự động khởi tạo: Database và JSON được load ngay khi import lang_custom. Không cần gọi language_setup().
  • ✅ Hỗ trợ reload toàn bộ hoặc reload một ngôn ngữ từ JSON.
  • ✅ Cảnh báo thông minh: Gợi ý khi group, name, hoặc type sai (ví dụ: "Did you mean 'replies'?").
  • ✅ Gộp hàm cũ (lang(), group(), get_text(), random_text()) thành một hàm duy nhất:
    await lang_custom.get(language="en", group="error", type="text", name="not_found")
    

📦 Cài đặt

pip install lang_custom==1.1.4

🚀 Hướng dẫn sử dụng

1. Nhập thư viện

import lang_custom

Database tự động khởi tạo, sẵn sàng sử dụng 🎉


2. Thiết lập tham số mặc định (tùy chọn)

Đơn giản hóa truy vấn bằng cách đặt mặc định cho language, group, và type:

await lang_custom.default(language="en", group="reply", type="text")

3. Truy vấn dữ liệu ngôn ngữ

# Sử dụng mặc định
text = await lang_custom.get(name="greeting")  # Dùng language="en", group="reply", type="text"
print(text)  # hello :D

# Ghi đè mặc định
random_text = await lang_custom.get(type="random", name="greetings")
print(random_text)  # hello :D, hi :3, hoặc hey there!

# Đầy đủ tham số
error_text = await lang_custom.get(language="en", group="error", type="text", name="not_found")
print(error_text)  # Resource not found
  • type="text": Lấy chuỗi cố định.
  • type="random": Lấy ngẫu nhiên từ danh sách.

4. Truy vấn hàng loạt

Lấy nhiều giá trị trong một lần gọi:

result = await lang_custom.batch(names=["greeting", "welcome", "missing"])  # Dùng mặc định
print(result)  # {'greeting': 'hello :D', 'welcome': 'hi :3', 'missing': ''}

# Với đầy đủ tham số
result = await lang_custom.batch(language="en", group="error", type="text", names=["not_found", "invalid"])
print(result)  # {'not_found': 'Resource not found', 'invalid': 'Invalid input'}

5. Lấy danh sách ngôn ngữ

langs = await lang_custom.get_lang()
print(langs)  # ['en', 'vi', 'jp']

6. Tải lại dữ liệu ngôn ngữ

await lang_custom.reload()  # Tải lại toàn bộ từ JSON
await lang_custom.reload_language("en")  # Tải lại ngôn ngữ "en"

📁 Ví dụ file _data_language/en.json

{
    "reply": {
        "text": {
            "greeting": "hello :D",
            "welcome": "hi :3"
        },
        "random": {
            "greetings": ["hello :D", "hi :3", "hey there!"]
        }
    },
    "error": {
        "text": {
            "not_found": "Resource not found",
            "invalid": "Invalid input"
        },
        "random": {
            "errors": ["Oops, something went wrong!", "Uh-oh, try again!"]
        }
    }
}

⚠️ Lưu ý

  • Không xóa thư mục _data_language/ hoặc file DO_NOT_DELETE.db khi ứng dụng đang chạy.
  • Cập nhật bản dịch? Chỉnh file JSON và gọi reload() hoặc reload_language().

💬 Góp ý & Báo lỗi

Tham gia Discord: 👉 https://discord.gg/pGcSyr2bcY


Cảm ơn bạn đã sử dụng Lang Custom! 🚀
Cảm ơn

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

lang_custom-1.1.5.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

lang_custom-1.1.5-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file lang_custom-1.1.5.tar.gz.

File metadata

  • Download URL: lang_custom-1.1.5.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for lang_custom-1.1.5.tar.gz
Algorithm Hash digest
SHA256 b5f9e458e281754f1652913911488fa00697ff9d0695bdc447c29e2a609685a9
MD5 9db78e3b52318695d738f86a28b2015b
BLAKE2b-256 84e291ef24910fdb55427a68db1cf796f4b759cdb2b646d17170b1e3968d3b1a

See more details on using hashes here.

File details

Details for the file lang_custom-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: lang_custom-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for lang_custom-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f1ee93d62ab0a418709cc4fd06b3e0d6a6ec562a732a0306132d4e683a9a25cf
MD5 61f21be1dfeaa3ae025ad94f4b47f5e6
BLAKE2b-256 33cebcdd8054e59b426389c04cebb6bf3b56c3da6abaa0d451e620bd3c29f8b1

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