JGecko-XML-Translator
This is a Python script that reads an input XML file and translates the Japanese text found in the name
, comment
, and author
tags to English using the Googletrans API. The translated XML file is saved as output.xml
.
Example of input / output XMLs can be found here
Dependencies
This script requires the following dependencies:
- re
- sys
- time
- colorama
- googletrans
- xml.etree.ElementTree
Usage
- Make sure that all dependencies are installed.
- Place the input XML file that needs to be translated in the same directory as the script. The input XML file should have the name
input.xml
. - Run the script using the command
python Gecko-XML-Translator.py
. - The translated XML file will be saved as
output.xml
. - The script will log all translation activity and errors to the console output.
Graceful Exit Handling
This script includes graceful exit handling using signal.SIGINT
on Unix-based systems and ctypes.windll.kernel32
on Windows systems. This enables the user to exit the script using CTRL + C
without the risk of data corruption.
Script Description
- The script first removes the encoding statement from the input XML file, if it exists. This is done to avoid encoding statement errors.
- The script then creates a translator object using the Googletrans API.
- The script parses the input XML file using xml.etree.ElementTree.
- The script loops through each entry in the input XML file.
- For each entry, the script checks if the
name
,comment
, andauthor
tags contain Japanese text. - If any of these tags contain Japanese text, the script translates the text to English using the Googletrans API.
- The translated text is then saved to the corresponding tag in the output XML file.
- If the Googletrans API encounters an error during translation, the script logs the error to the console output and continues with the next entry.
Error Handling
If the Googletrans API encounters an error during translation, the script logs the error to the console output and continues with the next entry. The script also logs a message to the console output if it fails to set up signal handling.
README generated by ChatGPT AI