Test translate#1574
Conversation
There was a problem hiding this comment.
Pull request overview
Adds automation for creating, registering, and machine-translating new Seamly2D Qt translation files, including helper scripts, flag asset handling, and a GitHub Actions workflow.
Changes:
- Adds scripts to create
.tsfiles, auto-translate them, add flag resources, and trigger the workflow. - Adds a translation workflow intended to generate translation branches and PRs.
- Wires generated translations into project metadata and supported locale lists.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/translations/start_translation_workflow.sh |
CLI helper to dispatch the translation workflow. |
scripts/translations/create_new_ts.py |
Creates new translation files and updates project/locale registration files. |
scripts/translations/auto_translate_ts.py |
Auto-translates empty Qt TS translation entries. |
scripts/translations/add_flag.py |
Downloads/registers flag icons for language locales. |
.github/workflows/translations/create-and-auto-translate.yml |
GitHub Actions workflow for translation generation, build/test, commit, and PR creation. |
Comments suppressed due to low confidence (7)
.github/workflows/translations/create-and-auto-translate.yml:64
- This step invokes
scripts/auto_translate_ts.py, but the script is added atscripts/translations/auto_translate_ts.py; the auto-translation step will fail once reached.
python -u scripts/auto_translate_ts.py $LANG_SHORT share/translations/measurements_${LANG_CODE}.ts share/translations/seamly2d_${LANG_CODE}.ts
scripts/translations/create_new_ts.py:62
- This appends the literal characters
\nto the.proline instead of inserting a real newline, producing invalid qmake syntax such astr_TR \ \n <lang>rather than a separate language entry.
if line.strip().endswith('tr_TR') and not added:
new_lines.append(line.rstrip() + ' \\n ' + lang_code + '\n')
added = True
scripts/translations/create_new_ts.py:97
- This has the same literal-
\ninsertion bug fortranslations.pri, so the generated LANGUAGES block is written on one malformed line and will break qmake parsing.
while j+1 < len(lines) and lines[j+1].strip().startswith('') and '\\' in lines[j]:
j += 1
# Insert after last LANGUAGES line
lines[j] = lines[j].rstrip() + ' \\n ' + lang_code + '\n'
added = True
.github/workflows/translations/create-and-auto-translate.yml:105
create_new_ts.pycreatesqtbase_${lang_code}.tsandtranslations.prireferencesqtbase_$${lang}.ts, but this workflow only commits the measurements and seamly2d files. The generated PR will therefore reference a missing qtbase translation file and break subsequent builds.
git add share/translations/measurements_${{ github.event.inputs.lang_code }}.ts
git add share/translations/seamly2d_${{ github.event.inputs.lang_code }}.ts
.github/workflows/translations/create-and-auto-translate.yml:12
- The push trigger has no
github.event.inputs.lang_code, so a push totest-translatewould deriveLANG_CODEfrom the branch name (test-translate) and later use an empty input for branch/file names. This makes the workflow create invalid paths/branches on every push to the test branch.
push:
branches:
- 'test-translate'
.github/workflows/translations/create-and-auto-translate.yml:64
create_new_ts.pyalso createsshare/translations/qtbase_${LANG_CODE}.ts, but this auto-translate command only processes measurements and seamly2d. If the qtbase file is included later, it will remain with empty translations.
python -u scripts/auto_translate_ts.py $LANG_SHORT share/translations/measurements_${LANG_CODE}.ts share/translations/seamly2d_${LANG_CODE}.ts
.github/workflows/translations/create-and-auto-translate.yml:51
LANG_CODEis written via$GITHUB_ENV, which is exposed to later shell steps as$LANG_CODE; it is not a statically defined workflowenvvalue for expression interpolation. Using${{ env.LANG_CODE }}here can expand to an empty argument—use the shell variable inruncommands after the setup step.
run: python -u scripts/add_flag.py ${{ env.LANG_CODE }}
- name: Create new .ts files for language (on virtual server, not in code branch)
run: python scripts/create_new_ts.py ${{ env.LANG_CODE }}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,122 @@ | |||
| name: Create and Auto-Translate New Language | |||
| exit 1 | ||
| fi | ||
|
|
||
| gh workflow run .github/workflows/create-and-auto-translate.yml --ref test-translate --field "lang_code=$LANG_CODE" No newline at end of file |
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --lang-code) |
| - name: Ensure flag icon for language | ||
| run: python -u scripts/add_flag.py ${{ env.LANG_CODE }} | ||
|
|
||
| - name: Create new .ts files for language (on virtual server, not in code branch) | ||
| run: python scripts/create_new_ts.py ${{ env.LANG_CODE }} |
| FLAGS_QRC = os.path.join(os.path.dirname(__file__), '../src/libs/vmisc/share/resources/flags.qrc') | ||
| FLAGS_DIR = os.path.join(os.path.dirname(__file__), '../src/libs/vmisc/share/resources/flags') |
| def get_country_from_lang_code(lang_code): | ||
| """Extract country code and name from lang_code (e.g., pt_BR -> (BR, Brazil)).""" | ||
| parts = lang_code.split('_') | ||
| if len(parts) == 2: | ||
| code = parts[1].upper() | ||
| country_map = get_country_map() | ||
| country = country_map.get(code) | ||
| return code, country |
| try: | ||
| translated = translator.translate(source.text, dest=dest_lang).text | ||
| except Exception as e: | ||
| print(f"[ERROR] Failed to translate '{source.text}' to '{dest_lang}': {e}") | ||
| translated = source.text # fallback to original | ||
| translation.text = translated |
| if len(sys.argv) < 2: | ||
| print("Usage: python create_new_ts.py <lang_code>") | ||
| sys.exit(1) | ||
| lang_code = sys.argv[1] |
| git add share/translations/measurements.pro | ||
| git add share/translations/translations.pro | ||
| git add src/app/translations.pri | ||
| git add src/libs/vmisc/def.cpp |
| lang_code: | ||
| description: 'language code parameter (e.g., pl_PL for Polish)' | ||
| required: true | ||
| default: 'pl_PL' |
No description provided.