-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
17,292 additions
and
16,860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Translation Update Script | ||
|
||
This folder contains scripts to automate the process of updating Qt `.ts` translation files and generating `.qm` files for MediaInfo's Qt GUI. The process involves using `lupdate` to update the `.ts` files, a Python script to apply custom translations from MediaInfo's `Languages` CSV file, and `lrelease` to generate the final `.qm` files. | ||
|
||
## Prerequisites | ||
|
||
1. **Qt Tools**: Ensure you have `lupdate` and `lrelease` installed and available in your system's PATH. | ||
2. **Python**: Ensure you have Python installed and available in your system's PATH. | ||
|
||
## Files | ||
|
||
### `update_Qt_translations.cmd` | ||
|
||
This Windows Command Script automates the process of updating `.ts` files and generating `.qm` files. | ||
|
||
### `update_Qt_translations.py` | ||
|
||
This Python script updates the `.ts` files with translations from the CSV file and handles special cases. | ||
|
||
## Usage | ||
|
||
1. **Run the Windows Command Script**: | ||
- Double-click `update_Qt_translations.cmd` or execute it from the command line. | ||
- The script will: | ||
- Run `lupdate` to update the `.ts` files. | ||
- Use `update_Qt_translations.py` to apply custom translations from `Languages.csv`. | ||
- Run `lrelease` to generate the `.qm` files. | ||
|
||
2. **Verify the Output**: | ||
- Check the `Source\Resource\Translations` folder to ensure that the `.ts` files have been generated/updated. | ||
- Verify that the `.qm` files have been generated/updated in the same directory as above. |
58 changes: 58 additions & 0 deletions
58
Source/GUI/Qt/Qt_Translations_Updater/update_Qt_translations.cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@echo off | ||
setlocal | ||
|
||
REM Enable ANSI escape sequences | ||
setlocal enableextensions | ||
setlocal enabledelayedexpansion | ||
|
||
REM ANSI escape codes for colors | ||
set GREEN=[92m | ||
set YELLOW=[33m | ||
set RED=[91m | ||
set RESET=[0m | ||
|
||
REM Set paths | ||
set PROJECT_FILE=%~dp0\..\..\..\..\Project\QMake\GUI\MediaInfoQt.pro | ||
set TS_FILES_FOLDER=%~dp0\..\..\..\Resource\Translations | ||
set CSV_FILE=%~dp0\..\..\..\Resource\Language.csv | ||
set PYTHON_SCRIPT=%~dp0\update_Qt_translations.py | ||
|
||
REM Step 1: Run lupdate to update .ts files | ||
echo. | ||
echo !YELLOW!Running lupdate...!RESET! | ||
lupdate -noobsolete %PROJECT_FILE% | ||
if %errorlevel% neq 0 ( | ||
echo. | ||
echo !RED!lupdate failed!%RESET% | ||
exit /b %errorlevel% | ||
) | ||
echo. | ||
echo !GREEN!lupdate completed successfully!%RESET% | ||
echo. | ||
|
||
REM Step 2: Run the Python script to update .ts files | ||
echo !YELLOW!Updating .ts files with translations...!RESET! | ||
python %PYTHON_SCRIPT% %TS_FILES_FOLDER% %CSV_FILE% | ||
if %errorlevel% neq 0 ( | ||
echo. | ||
echo !RED!Python script failed!%RESET% | ||
exit /b %errorlevel% | ||
) | ||
echo. | ||
echo !GREEN!.ts files updated successfully!%RESET% | ||
echo. | ||
|
||
REM Step 3: Run lrelease to generate .qm files | ||
echo !YELLOW!Running lrelease...!RESET! | ||
lrelease %PROJECT_FILE% | ||
if %errorlevel% neq 0 ( | ||
echo. | ||
echo !RED!lrelease failed!%RESET% | ||
exit /b %errorlevel% | ||
) | ||
echo. | ||
echo !GREEN!lrelease completed successfully!%RESET% | ||
echo. | ||
|
||
echo !GREEN!All steps completed successfully!%RESET! | ||
endlocal |
105 changes: 105 additions & 0 deletions
105
Source/GUI/Qt/Qt_Translations_Updater/update_Qt_translations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Update Qt translations .ts files with translations from MediaInfo's Languages.csv | ||
# Script generated with Qwen2.5-Coder-32B-Instruct | ||
|
||
import os | ||
import csv | ||
import xml.etree.ElementTree as ET | ||
import sys | ||
|
||
def load_translations(csv_file): | ||
translations = {} | ||
with open(csv_file, mode='r', encoding='utf-8') as file: | ||
reader = csv.DictReader(file, delimiter=';') | ||
for row in reader: | ||
source = row[' Language_ISO639'] | ||
translations[source] = {lang: row[lang] for lang in row if lang != ' Language_ISO639'} | ||
return translations | ||
|
||
def clean_translation(translation): | ||
if translation is not None: | ||
return translation.replace('\\r\\n', '\n') | ||
return translation | ||
|
||
def update_ts_file(ts_file, translations, lang_code): | ||
tree = ET.parse(ts_file) | ||
root = tree.getroot() | ||
|
||
# Update the TS tag with language and sourcelanguage attributes | ||
root.set('language', lang_code.replace('-', '_')) | ||
root.set('sourcelanguage', 'en') | ||
|
||
for context in root.findall('context'): | ||
for message in context.findall('message'): | ||
source = message.find('source').text | ||
translation_tag = message.find('translation') | ||
|
||
if source in translations: | ||
lang_translation = translations[source].get(lang_code, '') | ||
if not lang_translation: | ||
lang_translation = translations[source].get('en', '') | ||
|
||
lang_translation = clean_translation(lang_translation) | ||
|
||
if translation_tag is None: | ||
translation_tag = ET.SubElement(message, 'translation') | ||
translation_tag.text = lang_translation | ||
|
||
# Remove type="unfinished" if present | ||
if 'type' in translation_tag.attrib and translation_tag.attrib['type'] == 'unfinished': | ||
del translation_tag.attrib['type'] | ||
elif source == 'MediaInfo v%1\nCopyright (C) 2002-2025 MediaArea.net SARL\n': | ||
# Special case handling for Copyright | ||
copyright_translation = translations['Copyright'].get(lang_code, '') | ||
if not copyright_translation: | ||
copyright_translation = translations['Copyright'].get('en', '') | ||
|
||
copyright_translation = clean_translation(copyright_translation) | ||
|
||
if translation_tag is None: | ||
translation_tag = ET.SubElement(message, 'translation') | ||
|
||
# Replace only the word "Copyright" with the translated version | ||
translation_text = source.replace('Copyright', copyright_translation) | ||
translation_tag.text = translation_text | ||
|
||
# Remove type="unfinished" if present | ||
if 'type' in translation_tag.attrib and translation_tag.attrib['type'] == 'unfinished': | ||
del translation_tag.attrib['type'] | ||
elif source == 'Translator : Zen': | ||
# Special case handling for Translator | ||
translator_translation = translations['Translator'].get(lang_code, '') | ||
if not translator_translation: | ||
translator_translation = translations['Translator'].get('en', '') | ||
|
||
author_name = translations[' Author_Name'].get(lang_code, 'Zen') | ||
author_name = clean_translation(author_name) | ||
|
||
if translation_tag is None: | ||
translation_tag = ET.SubElement(message, 'translation') | ||
|
||
# Replace "Translator" and "Zen" with the translated versions | ||
translation_text = f'{translator_translation} : {author_name}' | ||
translation_tag.text = translation_text | ||
|
||
# Remove type="unfinished" if present | ||
if 'type' in translation_tag.attrib and translation_tag.attrib['type'] == 'unfinished': | ||
del translation_tag.attrib['type'] | ||
|
||
tree.write(ts_file, encoding='utf-8', xml_declaration=True) | ||
|
||
def process_ts_files(folder, csv_file): | ||
translations = load_translations(csv_file) | ||
for filename in os.listdir(folder): | ||
if filename.endswith('.ts'): | ||
lang_code = filename[:-3] # Remove '.ts' extension | ||
ts_file = os.path.join(folder, filename) | ||
update_ts_file(ts_file, translations, lang_code) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 3: | ||
print("Usage: python update_translations.py <ts_files_folder> <csv_file>") | ||
sys.exit(1) | ||
|
||
ts_files_folder = sys.argv[1] | ||
csv_file_path = sys.argv[2] | ||
process_ts_files(ts_files_folder, csv_file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.