Skip to content

Test translate#1574

Open
slspencer wants to merge 16 commits into
developfrom
test-translate
Open

Test translate#1574
slspencer wants to merge 16 commits into
developfrom
test-translate

Conversation

@slspencer

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .ts files, 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 at scripts/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 \n to the .pro line instead of inserting a real newline, producing invalid qmake syntax such as tr_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-\n insertion bug for translations.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.py creates qtbase_${lang_code}.ts and translations.pri references qtbase_$${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 to test-translate would derive LANG_CODE from 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.py also creates share/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_CODE is written via $GITHUB_ENV, which is exposed to later shell steps as $LANG_CODE; it is not a statically defined workflow env value for expression interpolation. Using ${{ env.LANG_CODE }} here can expand to an empty argument—use the shell variable in run commands 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)
Comment on lines +47 to +51
- 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 }}
Comment on lines +22 to +23
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')
Comment on lines +32 to +39
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
Comment on lines +44 to +49
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants