A simple language manager for Python projects.
Project description
Lang Custom v1.0.14
Lang Custom is a simple Python library that helps manage and load translations from JSON files.
Why did I create Lang Custom?
One day, I decided to make my bot support multiple languages. However, when searching for translation libraries, I realized that most of them were quite bad. So, I decided to create my own language files with customizable tones.
Initially, managing language files seemed simple, but then I realized that without a standard library, everything became very messy. Even though they were all JSON files, different code segments loaded language data in their own way—especially if you use AI tools like ChatGPT for assistance. There was no common standard.
Looking back at my source code, I could only exclaim: "It's amazing it doesn't crash :v" I wasn't sure if my code was working as expected, and every time I made changes, I was always worried that some parts would still work fine, but others might encounter errors due to inconsistent handling.
So, I created Lang Custom—a library that helps manage the language system more easily, consistently, and without headaches.
Installation
You can install this library using pip:
pip install lang_custom
What's new
Updated output structure:
lang_custom.get()
Version 1.0.14:
languages = lang_custom.get()
print(languages)
Console output will be in the format:
['en', 'vi', 'jp',..]
instead of version 1.0.11:
en,vi,jp,..
Usage Guide
1. Import the library
import lang_custom
2. Get the list of available language files
The library will automatically detect all JSON files in the Lang_data directory in your source code. To list the available language files, use:
languages = lang_custom.get()
print(languages) # Example: ['en', 'vi', 'jp',..] depending on the number of JSON files in the Lang_Data directory
console example
['en', 'vi', 'jp']
Each element in the list represents a JSON file in the language directory.
3. Select language and data group
Before retrieving text data, you need to select a language and data group from the JSON file:
lang_custom.lang("en").group("bot_random", cache=True)
Where:
"en"is the language you want to use."bot_random"is the group you want to access in the JSON structure.cache=Trueis an option to use cache to help the bot retrieve data faster (the downside is that it does not update in real-time, the default if not specified isTrue). You must use thereloadmethod to update if needed.
4. Retrieve text data
After selecting the language and group, you can retrieve the text using:
text = lang_custom.lang("en").group("bot_reply", cache=True).get_text("text1")
print(text) # Displays the value corresponding to the key "text1" in the group "bot_random" from en.json
console example
hello :D
Or retrieve random text from a list:
random_text = lang_custom.lang("en").group("bot_random").random_text("text_random")
print(random_text) # Displays a random value from the list "text_random" in the group "bot_random" from en.json
console example
text1 or text2 or 3
5. Clear and update cache
If you want to clear and update all cache, you can use the reload method:
lang_custom.reload()
This method will clear all cache and update data from the JSON files.
Language file structure
Each language file is stored in the Lang_Custom directory (default translations) or Lang_data directory (user-added translations). Example of Lang_Custom/en.json:
{
"bot_reply": {
"text1": "hello :D",
"text2": "hi :3"
},
"bot_random": {
"instruct": "use square brackets to random",
"text_random": ["text1", "text2", "text.."]
}
}
Users can add their own language JSON files in the Lang_data directory, as long as they follow the valid structure.
Feedback & Issues
If you have feedback or encounter issues, please contact me: Discord me
Thank you for using Lang_Custom!
Lang Custom v1.0.14
Lang Custom là một thư viện Python đơn giản giúp quản lý và tải bản dịch từ các tệp JSON.
Tại sao tôi tạo ra Lang Custom?
Một ngày nọ, tôi quyết định làm cho bot của mình hỗ trợ nhiều ngôn ngữ. Tuy nhiên, khi tìm kiếm các thư viện dịch thuật, tôi nhận ra rằng hầu hết chúng đều khá tệ. Vì vậy, tôi quyết định tự tạo các tệp ngôn ngữ với ngữ điệu có thể tùy chỉnh.
Ban đầu, việc quản lý các tệp ngôn ngữ có vẻ đơn giản, nhưng sau đó tôi nhận ra rằng nếu không có một thư viện chuẩn, mọi thứ trở nên rất lộn xộn. Dù tất cả đều là tệp JSON, nhưng các đoạn mã khác nhau lại tải dữ liệu ngôn ngữ theo cách riêng—đặc biệt nếu bạn dùng các công cụ AI như ChatGPT để hỗ trợ. Không có một tiêu chuẩn chung nào cả.
Nhìn lại mã nguồn của mình, tôi chỉ có thể thốt lên: "Tởm vl nó ko crash được cũng hay đấy :v" không chắc liệu đoạn mã của mình có hoạt động đúng như mong muốn không, và mỗi khi chỉnh sửa, lúc nào cũng lo sợ rằng một số phần vẫn hoạt động tốt, nhưng những phần khác có thể gặp lỗi do xử lý không đồng nhất.
Vì vậy, tôi đã tạo ra Lang Custom—một thư viện giúp quản lý hệ thống ngôn ngữ dễ dàng hơn, nhất quán hơn và không còn gây đau đầu nữa.
Cài đặt
Bạn có thể cài đặt thư viện này bằng pip:
pip install lang_custom
Có gì mới
Sửa lại cấu trúc xuất ra:
lang_custom.get()
Phiên bản 1.0.14:
languages = lang_custom.get()
print(languages)
Console sẽ có dạng:
['en', 'vi', 'jp',..]
thay vì như 1.0.11:
en,vi,jp,..
Hướng dẫn sử dụng
1. Nhập thư viện
import lang_custom
2. Lấy danh sách các tệp ngôn ngữ có sẵn
Thư viện sẽ tự động phát hiện tất cả các tệp JSON trong thư mục Lang_data trong mã nguồn của bạn. Để liệt kê các tệp ngôn ngữ có sẵn, sử dụng:
languages = lang_custom.get()
print(languages) # Ví dụ: ['en', 'vi', 'jp',..] tùy vào số lượng file json trong thư mục Lang_Data
console example
['en', 'vi', 'jp']
Mỗi phần tử trong danh sách đại diện cho một tệp JSON có trong thư mục ngôn ngữ.
3. Chọn ngôn ngữ và nhóm dữ liệu
Trước khi lấy dữ liệu văn bản, bạn cần chọn ngôn ngữ và nhóm dữ liệu từ tệp JSON:
lang_custom.lang("en").group("bot_random", cache=True)
Trong đó:
"en"là ngôn ngữ bạn muốn sử dụng."bot_random"là nhóm bạn muốn truy cập trong cấu trúc JSON.cache=Truelà tùy chọn để sử dụng cache giúp bot truy xuất dữ liệu nhanh hơn (nhược điểm không cập nhật nóng được, mặc định nếu bạn không đề cập làTrue). Bạn phải sử dụng phương thứcreloadđể cập nhật lại nếu muốn.
4. Lấy dữ liệu văn bản
Sau khi chọn ngôn ngữ và nhóm, bạn có thể lấy văn bản bằng cách sử dụng:
text = lang_custom.lang("en").group("bot_reply", cache=True).get_text("text1")
print(text) # Hiển thị giá trị tương ứng với khóa "text1" trong nhóm "bot_random" từ en.json
console example
hello :D
Hoặc lấy văn bản ngẫu nhiên từ danh sách:
random_text = lang_custom.lang("en").group("bot_random").random_text("text_random")
print(random_text) # Hiển thị một giá trị ngẫu nhiên từ danh sách "text_random" trong nhóm "bot_random" từ en.json
console example
text1 or text2 or 3
5. Xóa và cập nhật lại cache
Nếu bạn muốn xóa và cập nhật lại tất cả cache, bạn có thể sử dụng phương thức reload:
lang_custom.reload()
Phương thức này sẽ xóa toàn bộ cache và cập nhật lại dữ liệu từ các tệp JSON.
Cấu trúc tệp ngôn ngữ
Mỗi tệp ngôn ngữ được lưu trong thư mục Lang_Custom (bản dịch mặc định) hoặc Lang_data (bản dịch do người dùng thêm vào). Ví dụ về Lang_Custom/en.json:
{
"bot_reply": {
"text1": "hello :D",
"text2": "hi :3"
},
"bot_random": {
"instruct": "use square brackets to random",
"text_random": ["text1", "text2", "text.."]
}
}
Người dùng có thể thêm các tệp JSON ngôn ngữ của riêng mình trong thư mục Lang_data, miễn là tuân theo cấu trúc hợp lệ.
Phản hồi & Báo lỗi
Nếu bạn có phản hồi hoặc gặp vấn đề, vui lòng liên hệ tôi: Discord me
Cảm ơn bạn đã sử dụng Lang_Custom!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lang_custom-1.0.14.tar.gz.
File metadata
- Download URL: lang_custom-1.0.14.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dd5d144af97466bc448894eab716cf480c8fa2d1b6cc32a473cd1391fd8163a
|
|
| MD5 |
0725a18b9817fcf5d2703a50e7887033
|
|
| BLAKE2b-256 |
7b89f1d47ca304c3b9743e3c41d19fd749d361cb6463760442cab52b7dfb29e1
|
File details
Details for the file lang_custom-1.0.14-py3-none-any.whl.
File metadata
- Download URL: lang_custom-1.0.14-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38c0b882497000821bf6dddeb814ff4472c166b9623966b32174f47221a9db3f
|
|
| MD5 |
367284f8734c7c274523f538013b06dd
|
|
| BLAKE2b-256 |
323902df19718634ef1925df323e19054c0902e58166a6c531b485d4e5511a61
|