kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Extract i18n strings from python_packages/ kolibri plugins

Open rtibbles opened this issue 5 months ago • 4 comments

Overview

Kolibri's i18n recipes scan and compile only kolibri/ and packages/, writing to kolibri/locale/. Kolibri plugins migrated to python_packages/* carry their own user-facing strings that no recipe handles.

Complexity: Medium · Target branch: develop

Context

  • i18n-extract-frontend runs pnpm run makemessages, which calls kolibri-i18n extract-messages.
    • It passes --pluginFile build_tools/build_plugins.txt.
    • It adds --namespace/--searchPath pairs for kolibri-core and kolibri-common.
    • Output goes to --localeDataFolder, default kolibri/locale.
    • That default is set in [tool.kolibri.i18n] in pyproject.toml.
  • i18n-extract-backend runs Django makemessages from cd kolibri.
    • Strings therefore land in kolibri/locale.
  • i18n-upload uploads via crowdin.yml's source/translation pairs.
    • Every pair points under kolibri/locale.
  • i18n-download-translations downloads translations from Crowdin.
    • It then runs i18n-django-compilemessages (.po → .mo).
    • It then runs create-message-files (CSV → <namespace>-messages.json).
  • build_plugins.txt lists only kolibri.core and kolibri.plugins.*.
    • So python_packages/* plugins are excluded from extraction and message-file generation.
  • webpack_json.py computes the correct per-plugin path (plugin_path/locale for non-kolibri. modules).
    • But the CLI discards it and writes to the single --localeDataFolder.
  • Django's makemessages never consults webpack_json.py.
    • It routes by app-level locale/ existence.
    • Missing that, it falls back to LOCALE_PATHS (kolibri/locale).

The change

Discover the plugins once by iterating python_packages/* and resolving each inner module. Both passes reuse that list.

CLI routing. Make extract-messages and create-message-files (and the other commands taking --localeDataFolder) honor each bundle's locale_data_folder instead of flattening to one folder.

  • _generatePathInfo carries bundle.locale_data_folder onto each bundle-derived path entry.
    • Strip the en/LC_MESSAGES suffix that webpack_json.py appends.
  • Each namespace writes to its entry's folder.
  • --namespace/--searchPath entries fall back to --localeDataFolder.
    • These are the non-plugin kolibri-core/kolibri-common packages.

Frontend — loop per plugin.

  • --pluginFile and --plugins can't be combined.
  • --pluginFile takes precedence; the --plugins list is ignored.
  • So each plugin needs its own call, separate from the Kolibri --pluginFile run.
  • For each discovered module with a buildConfig.js, run extract-messages --plugins <module>.
  • Per-bundle routing sends each to its own locale/.
  • Skip modules without a buildConfig.js.
    • --plugins on a backend-only plugin errors in webpack_json.py.
  • Don't add these plugins to build_plugins.txt.
    • It also drives the webpack build.

Backend — loop per plugin.

  • For each discovered module: mkdir -p <module>/locale, then cd <module> && kolibri manage makemessages -- -l en ….
  • The mkdir is load-bearing.
    • Without a pre-existing locale/, Django writes the plugin's strings into kolibri/locale.

crowdin.yml.

  • Add per-plugin source/translation entries pointing at each plugin's locale/.
  • Cover both CSV (frontend) and PO (backend).

Download.

  • i18n-django-compilemessages: add a cd <module> && compilemessages pass per plugin.
  • create-message-files: run per plugin to generate each plugin's <namespace>-messages.json.

Out of scope

platforms/* packages (kolibri-app, kolibri-installer-gnome, …) carry their own gettext-based i18n, not Kolibri's createTranslator/makemessages recipes. Handled once some platforms migrate in.

Acceptance criteria

  • [ ] extract-messages/create-message-files write each bundle's strings to that bundle's locale_data_folder.
  • [ ] --localeDataFolder applies only as the fallback for --searchPath/--namespace entries.
  • [ ] i18n-extract-frontend writes each buildConfig.js-bearing plugin's frontend strings to that plugin's own locale/.
  • [ ] build_plugins.txt is unchanged.
  • [ ] i18n-extract-backend creates each plugin's locale/ before running makemessages.
  • [ ] Each plugin's backend strings land in its own locale/.
  • [ ] No plugin strings land in kolibri/locale.
  • [ ] i18n-upload uploads plugin en strings via per-plugin crowdin.yml entries.
  • [ ] i18n-download-translations writes downloaded plugin translations into each plugin's locale/.
  • [ ] i18n-download-translations generates each plugin's <namespace>-messages.json.
  • [ ] i18n-download-translations compiles each plugin's .mo.

Verified against the tree

  • kolibri-sentry-plugin is the only python_packages/* member with a buildConfig.js.
    • The frontend pass covers it today.
  • kolibri-oidc-client-plugin has a backend string: gettext_lazy("Sign in with OpenID Connect").
    • It has no frontend bundle.
    • The backend pass covers it today.
  • With a pre-existing locale/, cd <module> && makemessages writes to <module>/locale/…/django.po.
    • Without it, the string leaks into kolibri/locale/…/django.po.

AI usage

Used Claude Code to draft this issue. I drove scope and decisions.

Claude grounded each criterion by reading:

  • the i18n Makefile recipes
  • the kolibri-i18n CLI
  • webpack_json.py
  • crowdin.yml

Claude also verified empirically:

  • the backend makemessages routing
  • the frontend locale_data_folder plumbing

rtibbles avatar Jul 05 '26 01:07 rtibbles

Plan: Make Kolibri's i18n extract/compile/upload/download recipes route each python_packages/* plugin's user-facing strings to that plugin's own locale/ folder instead of flattening everything into kolibri/locale.

  • [ ] stripEnLcMessages helper in utils.js
  • [ ] Per-namespace routing in ExtractMessages.js
  • [ ] Per-namespace routing in csvToJSON.js
  • [ ] Carry locale_data_folder through cli.js _generatePathInfo
  • [ ] Phase 1 simplify pass
  • [ ] Makefile plugin-discovery variables
  • [ ] i18n-extract-frontend loops buildConfig plugins
  • [ ] i18n-extract-backend loops all plugins with pre-created locale/
  • [ ] Phase 2 simplify pass
  • [ ] crowdin.yml per-plugin source/translation entries
  • [ ] Compile and generate message files per plugin
  • [ ] Phase 3 simplify pass

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jul 09 '26 23:07 rtibblesbot

Blocking decision needed on Task 10 (crowdin.yml per-plugin entries) before I can add the backend PO entry.

Done and unblocked: the sentry-plugin CSV entry is added. Frontend CSVs are namespace-prefixed (kolibri_sentry_plugin.main-messages.csv), so their basenames stay unique under preserve_hierarchy: false.

Blocked — the django.po basename collision. crowdin.yml sets preserve_hierarchy: false, so Crowdin keys each source by basename only. Django makemessages always emits django.po, so the oidc-client plugin's .../kolibri_oidc_client_plugin/locale/en/LC_MESSAGES/django.po would collide with kolibri's /kolibri/locale/en/LC_MESSAGES/django.po — one Crowdin file, strings merged on upload, both pulling the merged content on download. This corrupts both the plugin and kolibri backend catalogs. Config-level crowdin config validation cannot catch this (it validates YAML, not runtime dedup-by-basename).

Recommended mitigation (from the plan) — give the plugin PO a unique Crowdin filename via an explicit (non-wildcard) source + dest:

{"source": "/python_packages/kolibri-oidc-client-plugin/kolibri_oidc_client_plugin/locale/en/LC_MESSAGES/django.po", "dest": "/kolibri_oidc_client_plugin.django.po", "update_option": "update_as_unapproved", "translation": "/python_packages/kolibri-oidc-client-plugin/kolibri_oidc_client_plugin/locale/%locale_with_underscore%/LC_MESSAGES/django.po", "languages_mapping": *language_mapping}

dest renames the file in the Crowdin project only; the translation template still writes downloads back to the real local django.po, so compile/message-file steps are unaffected. (dest and wildcard sources are mutually exclusive, hence the explicit source.)

This introduces a new file name visible to translators in the live Crowdin project (kolibri_oidc_client_plugin.django.po) — a translation-infra decision, not a code one. Please confirm before I ship:

  1. Is dest the accepted approach?
  2. If not, do you prefer an alternative (Crowdin project-side path settings, a different dest naming scheme, etc.)?
  3. Or does the Crowdin project already handle same-basename files in a way that makes this moot?

Holding Task 10 Steps 2–3 (and the dependent Task 11 download verification) until this is resolved.

rtibblesbot avatar Jul 09 '26 23:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 10 '26 01:07 rtibblesbot

I think your dest approach is an excellent way forward. Let's use that.

rtibbles avatar Jul 10 '26 19:07 rtibbles