Mô tả dự án
translate_ai là một tập hợp script Python nhỏ dùng để trích xuất, chuyển đổi và gộp nội dung file văn bản định dạng .fmg.txt (thường là file văn bản dùng cho các trò chơi) sang định dạng JSON dễ xử lý. Mục tiêu chính là chuẩn hóa dữ liệu văn bản để phục vụ việc dịch thuật, chỉnh sửa nội dung hoặc tái sử dụng trong các công cụ khác.
Tính năng chính
- Đọc các file
.fmg.txttừ các thư mục đầu vào (ví dụ:item/,menu/). - Chuyển đổi nội dung thành JSON có cấu trúc (ví dụ:
extracted/talk_messages.json). - Gộp nhiều nguồn đầu vào vào một file JSON hợp nhất (ví dụ:
merged/talk_messages.json).
Sơ đồ thư mục (mô tả các file quan trọng)
main.py— (giả định) entrypoint chính của dự án để chạy luồng xử lý chính.merge_fmg_text_to_json.py— script để gộp các file.fmg.txt/thành JSON (tên file có thể biểu thị chức năng gộp).item/,menu/— thư mục chứa các file.fmg.txtthô (dữ liệu nguồn).extracted/talk_messages.json— kết quả trích xuất định dạng JSON (một ví dụ có sẵn trong repo).merged/talk_messages.json— kết quả sau khi gộp nhiều nguồn (ví dụ đầu ra hợp nhất).
Ghi chú và giả định
Một vài giả định hợp lý (vì repo không kèm tài liệu chi tiết về CLI nội bộ):
main.pyvàmerge_fmg_text_to_json.pylà script Python có thể chạy trực tiếp bằngpython3.- Kết quả đầu ra được lưu trong thư mục
extracted/hoặcmerged/như đã thấy trong repo.
Nếu những giả định trên không chính xác, hãy cho biết cách gọi cụ thể và mình sẽ cập nhật README tương ứng.
Yêu cầu
- Python 3.8+ (khuyến nghị). Nếu script sử dụng thư viện ngoài, hãy thêm
requirements.txt. Hiện tại README này giả định không có phụ thuộc ngoài.
Hướng dẫn nhanh — chạy các script
Mở terminal (shell mặc định của bạn) và chạy:
python3 main.py
# hoặc (nếu bạn chỉ muốn gộp file .fmg.txt thành JSON)
python3 merge_fmg_text_to_json.pyKết quả mong đợi
- Các file JSON mới sẽ xuất hiện trong
extracted/hoặcmerged/. - Kiểm tra nội dung JSON (ví dụ:
extracted/talk_messages.json) để đảm bảo các key/giá trị phù hợp.
Cách hoạt động (tổng quan)
- Script đọc từng file
.fmg.txttrong các thư mục nguồn. - Phân tích cú pháp (parser) để tách các entry/ID/nội dung.
- Chuyển mỗi entry thành object JSON với các trường phù hợp.
- Ghi các object này vào file JSON đầu ra (có thể gộp nhiều file vào một danh sách lớn hoặc map theo ID).
Ví dụ nhanh
- Nguồn:
menu/1.fmg.txt,item/20.fmg.txt→ - Chạy
python3 merge_fmg_text_to_json.py→ - Đầu ra:
merged/talk_messages.json
Đóng góp
- Muốn thêm tính năng (ví dụ: hỗ trợ charset khác, xuất CSV, cờ CLI), hãy mở issue hoặc gửi pull request.
- Nếu thêm phụ thuộc, bổ sung
requirements.txtvà cập nhật README.
Các bước tiếp theo đề xuất
- Thêm mô tả từng script (CLI flags, ví dụ sử dụng) trực tiếp trong README.
- Thêm
requirements.txtnếu cần thư viện ngoài (ví dụ:regex,click). - Viết test nhỏ để kiểm tra parser hoạt động với vài file
.fmg.txtmẫu.
English
Project description
translate_ai is a small collection of Python scripts for extracting, converting, and merging text files in the .fmg.txt format (commonly used for game text) into JSON that is easier to process. The main goal is to normalize text data for translation, content editing, or reuse in other tools.
Key features
- Read
.fmg.txtfiles from input folders (for example:item/,menu/). - Convert content into structured JSON (for example:
extracted/talk_messages.json). - Merge multiple input sources into a single unified JSON file (for example:
merged/talk_messages.json).
Repository layout (important files)
main.py— (assumed) the primary entrypoint to run the main processing flow.merge_fmg_text_to_json.py— script for merging.fmg.txtfiles into JSON (file name suggests merge functionality).item/,menu/— folders containing raw.fmg.txtsource files.extracted/talk_messages.json— an example extraction output in JSON format.merged/talk_messages.json— an example of merged output from multiple sources.
Notes and assumptions
A few reasonable assumptions (since the repo doesn't include detailed CLI docs):
main.pyandmerge_fmg_text_to_json.pyare runnable Python scripts executed withpython3.- Output files are written to
extractedormergedas seen in the repository.
If these assumptions are incorrect, please tell me how the scripts are intended to be run and I'll update the README accordingly.
Requirements
- Python 3.8+ (recommended). If the scripts rely on external libraries, add a
requirements.txt. This README assumes there are no external dependencies.
Quick start — run the scripts
Open a terminal and run:
python3 main.py
# or (if you only want to merge .fmg.txt files into JSON)
python3 merge_fmg_text_to_json.pyExpected output
- New JSON files will be created under
extracted/ormerged/. - Inspect the JSON content (for example:
extracted/talk_messages.json) to ensure keys/values match expectations.
How it works (overview)
- The scripts read each
.fmg.txtfile in the source folders. - A parser extracts entries/IDs and their text content.
- Each entry is converted into a JSON object with appropriate fields.
- The objects are written to an output JSON file (either combined into a list or mapped by ID).
Quick example
- Sources:
menu/1.fmg.txt,item/20.fmg.txt→ - Run
python3 merge_fmg_text_to_json.py→ - Output:
merged/talk_messages.json
Contributing
- To add features (for example: support for additional encodings, CSV output, CLI flags), open an issue or submit a pull request.
- If adding dependencies, update
requirements.txtand the README.
Suggested next steps
- Add detailed script documentation (CLI flags and usage examples) directly in the README.
- Add
requirements.txtif external libraries are needed (for example:regex,click). - Create small tests to validate the parser with a few sample
.fmg.txtfiles.