Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt GUI: Implement translations + monospaced font customization #1032

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/MediaInfo-Qt_Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ on:
paths:
- 'Project/QMake/GUI/**'
- 'Source/GUI/Qt/**'
- 'Source/Resource/**'

pull_request:
paths:
- 'Project/QMake/GUI/**'
- 'Source/GUI/Qt/**'
- 'Source/Resource/**'

jobs:

Expand Down
39 changes: 39 additions & 0 deletions Project/QMake/GUI/MediaInfoQt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,45 @@ FORMS += ../../../Source/GUI/Qt/mainwindow.ui \
../../../Source/GUI/Qt/editsheet.ui \
../../../Source/GUI/Qt/editconfigtreetext.ui

TRANSLATIONS = ../../../Source/Resource/Translations/ar.ts \
../../../Source/Resource/Translations/be.ts \
../../../Source/Resource/Translations/bg.ts \
../../../Source/Resource/Translations/ca.ts \
../../../Source/Resource/Translations/cs.ts \
../../../Source/Resource/Translations/da.ts \
../../../Source/Resource/Translations/de.ts \
../../../Source/Resource/Translations/en.ts \
../../../Source/Resource/Translations/es.ts \
../../../Source/Resource/Translations/eu.ts \
../../../Source/Resource/Translations/fa.ts \
../../../Source/Resource/Translations/fr.ts \
../../../Source/Resource/Translations/gl.ts \
../../../Source/Resource/Translations/gr.ts \
../../../Source/Resource/Translations/hr.ts \
../../../Source/Resource/Translations/hu.ts \
../../../Source/Resource/Translations/hy.ts \
../../../Source/Resource/Translations/id.ts \
../../../Source/Resource/Translations/it.ts \
../../../Source/Resource/Translations/ja.ts \
../../../Source/Resource/Translations/ka.ts \
../../../Source/Resource/Translations/ko.ts \
../../../Source/Resource/Translations/lt.ts \
../../../Source/Resource/Translations/nl.ts \
../../../Source/Resource/Translations/pl.ts \
../../../Source/Resource/Translations/pt-BR.ts \
../../../Source/Resource/Translations/pt.ts \
../../../Source/Resource/Translations/ro.ts \
../../../Source/Resource/Translations/ru.ts \
../../../Source/Resource/Translations/sk.ts \
../../../Source/Resource/Translations/sq.ts \
../../../Source/Resource/Translations/sv.ts \
../../../Source/Resource/Translations/th.ts \
../../../Source/Resource/Translations/tr.ts \
../../../Source/Resource/Translations/uk.ts \
../../../Source/Resource/Translations/zh-CN.ts \
../../../Source/Resource/Translations/zh-HK.ts \
../../../Source/Resource/Translations/zh-TW.ts

RESOURCES += ../../../Source/Resource/Resources.qrc

OBJECTS_DIR = _Automated
Expand Down
31 changes: 31 additions & 0 deletions Source/GUI/Qt/Qt_Translations_Updater/README.md
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 Source/GUI/Qt/Qt_Translations_Updater/update_Qt_translations.cmd
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=
set YELLOW=
set RED=
set RESET=

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 Source/GUI/Qt/Qt_Translations_Updater/update_Qt_translations.py
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)
3 changes: 1 addition & 2 deletions Source/GUI/Qt/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* be found in the License.html file in the root of the source tree.
*/

#include "translate.h"
#include "about.h"
#include "ui_about.h"
#include <QCoreApplication>
Expand All @@ -18,7 +17,7 @@ About::About(QWidget *parent) :
ui->setupUi(this);

#if !defined(_WIN32) || !defined(WINAPI_FAMILY) || (WINAPI_FAMILY!=WINAPI_FAMILY_APP) // Workaround render bug
setWindowTitle("About");
setWindowTitle(tr("About"));
#endif

#if defined(_WIN32) && defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_APP) // Remove donate button
Expand Down
Loading