-
Notifications
You must be signed in to change notification settings - Fork 87
chore(Makefile): create targets to update and build translations #18821
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
#!/usr/bin/python | ||
|
||
import xml.etree.ElementTree as ET | ||
import sys | ||
|
||
def main(): | ||
# Relative paths from project root | ||
base_file = "../../ui/i18n/qml_base_en.ts" | ||
plural_file = "../../ui/i18n/qml_en.ts" | ||
output_file = "../../ui/i18n/qml_base_lokalise_en.ts" | ||
|
||
# Parse the base TS file | ||
try: | ||
base_tree = ET.parse(base_file) | ||
base_root = base_tree.getroot() | ||
except ET.ParseError as e: | ||
print(f"Error parsing {base_file}: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
# Parse the plural TS file | ||
try: | ||
plural_tree = ET.parse(plural_file) | ||
plural_root = plural_tree.getroot() | ||
except ET.ParseError as e: | ||
print(f"Error parsing {plural_file}: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
# Create a dictionary for quick lookup of plural translations by source | ||
plural_lookup = {} | ||
for context in plural_root.findall('context'): | ||
for message in context.findall('message'): | ||
source = message.find('source') | ||
if source is not None and source.text: | ||
plural_lookup[source.text] = message.find('translation') | ||
|
||
# Process each message in the base file | ||
for context in base_root.findall('context'): | ||
for message in context.findall('message'): | ||
numerus = message.get('numerus') | ||
source = message.find('source') | ||
translation = message.find('translation') | ||
|
||
if numerus == 'yes' and source is not None and source.text in plural_lookup: | ||
# Copy translation from plural file | ||
plural_translation = plural_lookup[source.text] | ||
if plural_translation is not None: | ||
# Clear existing translation content | ||
translation.clear() | ||
# Copy attributes and subelements | ||
for attr, value in plural_translation.attrib.items(): | ||
translation.set(attr, value) | ||
for child in plural_translation: | ||
translation.append(child) | ||
# Remove unfinished if present | ||
if 'type' in translation.attrib and translation.attrib['type'] == 'unfinished': | ||
del translation.attrib['type'] | ||
else: | ||
# For non-numerus or unmatched, set translation to source | ||
if translation is not None and source is not None: | ||
translation.text = source.text | ||
# Remove unfinished | ||
if 'type' in translation.attrib and translation.attrib['type'] == 'unfinished': | ||
del translation.attrib['type'] | ||
|
||
# Fixup the "language" attribute | ||
base_root.set('language', 'en') | ||
|
||
# Write the modified XML to output file | ||
try: | ||
base_tree.write(output_file, encoding='utf-8', xml_declaration=True) | ||
print(f"Successfully transformed {base_file} to {output_file}") | ||
except Exception as e: | ||
print(f"Error writing to {output_file}: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
|
@@ -14,10 +14,11 @@ type | |
|
||
let localeDescriptionTable* = { | ||
"ar": Description(name: "Arabic", native: "العربية", flag: "", state: State.Alpha), | ||
"bn": Description(name: "Bengali", native: "বাংলা", flag: "X", state: State.Alpha), | ||
"bn": Description(name: "Bengali", native: "বাংলা", flag: "X", state: State.Alpha), | ||
"cs": Description(name: "Czech", native: "čeština", flag: "🇨🇿", state: State.Alpha), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this should be done on the fly, and not hardcoded here. Will be tackled in a separate issue #18330 |
||
"de": Description(name: "German", native: "Deutsch", flag: "🇩🇪", state: State.Alpha), | ||
"el": Description(name: "Greek", native: "Ελληνικά", flag: "🇬🇷", state: State.Alpha), | ||
"en": Description(name: "English", native: "English", flag: "🏴", state: State.Stable), | ||
"en": Description(name: "English", native: "English", flag: "🇬🇧", state: State.Stable), | ||
"en_US": Description(name: "English (United States)", native: "English (United States)", flag: "🇺🇸", state: State.Alpha), | ||
"es": Description(name: "Spanish", native: "Español", flag: "🇪🇸", state: State.Alpha), | ||
"es_419": Description(name: "Spanish (Latin America)", native: "Español (Latinoamerica)", flag: "", state: State.Alpha), | ||
|
This file contains hidden or 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,49 @@ | ||
cmake_minimum_required(VERSION 3.19) | ||
|
||
project(status-app-i18n) # dummy project to silence warnings, TBD at the toplevel | ||
|
||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) | ||
find_package(Qt6 REQUIRED COMPONENTS LinguistTools) | ||
|
||
#qt6_standard_project_setup(I18N_TRANSLATED_LANGUAGES cs) | ||
|
||
set(QT_NO_MISSING_CATALOG_LANGUAGE_WARNING ON) | ||
|
||
file(GLOB_RECURSE | ||
COLLECTED_SOURCE_FILES | ||
${CMAKE_SOURCE_DIR}/../*.qml | ||
) | ||
|
||
qt6_add_lupdate( | ||
LUPDATE_TARGET update_application_translations # name of the cmake target | ||
OPTIONS -locations none -no-obsolete -source-language en # options passed to 'lupdate' | ||
TS_FILES | ||
${CMAKE_SOURCE_DIR}/qml_base_en.ts #empty base file, for manual translations | ||
${CMAKE_SOURCE_DIR}/qml_cs.ts | ||
PLURALS_TS_FILE | ||
${CMAKE_SOURCE_DIR}/qml_en.ts | ||
SOURCES ${COLLECTED_SOURCE_FILES} | ||
) | ||
|
||
qt6_add_lrelease( | ||
LRELEASE_TARGET compile_application_translations # name of the cmake target | ||
OPTIONS -removeidentical -compress -nounfinished # options passed to 'lrelease' | ||
TS_FILES | ||
${CMAKE_SOURCE_DIR}/qml_en.ts | ||
${CMAKE_SOURCE_DIR}/qml_cs.ts | ||
QM_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../../bin/i18n | ||
MERGE_QT_TRANSLATIONS | ||
QT_TRANSLATION_CATALOGS qtbase qtmultimedia qtwebengine | ||
) | ||
|
||
# Ideally at the toplevel it could be done sth like this in one pass/target: | ||
#qt6_add_translations( | ||
# TS_FILE_BASE qml_ | ||
# SOURCES ${COLLECTED_SOURCE_FILES} | ||
# LUPDATE_TARGET update_application_translations | ||
# LUPDATE_OPTIONS "-locations none -no-obsolete" | ||
# LRELEASE_TARGET compile_application_translations | ||
# LRELEASE_OPTIONS "-removeidentical -compress -nounfinished" | ||
# QM_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../../bin/i18n | ||
# MERGE_QT_TRANSLATIONS | ||
#) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a manual step (for now) as it requires Python; no change here. We probably don't want or need this to be run everywhere (mac, Windows), can be done only on CI