Skip to content

Add opt-in internationalization and translated user manuals - #6386

Closed
Globgor wants to merge 29 commits into
solgenomics:masterfrom
Globgor:fix/i18n-current-ui
Closed

Globgor wants to merge 29 commits into
solgenomics:masterfrom
Globgor:fix/i18n-current-ui

Conversation

@Globgor

@Globgor Globgor commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds optional Ukrainian, Spanish and Arabic translations to the
registered SGN/Breedbase interface and all 29 user-manual chapters. It is
related to #5915. The aim is to let users work in their language while keeping
release preparation, translation editing and site installation straightforward.

Fixes #5915.

What this adds

  • Interface translations: shared Perl, Mason, JavaScript and R presentation
    helpers, context-aware messages, plural forms and Arabic right-to-left layout.
    The current catalog has 15,398 registered message identities.
  • A language selector in the site header, to the left of Login. The user
    chooses a language and clicks the adjacent button. The current page, query and
    section are preserved.
  • English by default and as fallback. Translation is opt-in. Missing or
    unfinished translations use the whole English message. Stored trial/accession
    names, identifiers, measurements, scientific formulas, import/export fields
    and access rules remain unchanged.
  • Release-based language packs: gettext PO files for editing, a frozen
    message list for each release, validated JSON packs for the application, and
    installation/rollback tools.
  • Translated user manuals: 29 chapters in each language, language links that
    preserve the chapter/section, Arabic layout, HTML builds and PDF export
    instructions.

What changed after review, and why

The
review comments
and
header placement request
led to these changes:

Change What it makes easier
Short SGN.t / SGN.tn browser helpers Developers write one translation call instead of repeating a long fallback expression.
Tools under bin/i18n, with one command entry point Each task has its own --help; matching tools are included in the delivered folders.
prepare once per release, then Poedit editing and package Translators receive editable copies; operators receive ready files. Source parsers are needed only on the source builder. Ordinary code PRs do not require completed translations in every language.
install --activate The tool validates the pack and reads its language/hash itself. Administrators do not copy a long hash between commands.
Read-only doctor and retained rollback Administrators can check local files and optional site language headers, then return to the previous pack if needed.
One build.R all command The manual builder gets English and all three translated readers together. The final folder appears only after all four builds succeed.
Task-based guides and instructions inside generated folders Each person sees prerequisites, the folder to open, commands to run and the expected output.

The proposed
developer-guide chapter
explains adding messages, extraction, debugging and fallback. Moving catalogs or
manuals into separate repositories remains a maintainer decision; this PR keeps
them together and supports handing off release files independently.

How to use it

Release builder: from the clean SGN source checkout, with the
source tools
installed:

python3 bin/i18n/sgn-i18n prepare \
  --application-version "$(git rev-parse HEAD)" \
  --output "$HOME/sgn-translation-v1"

This creates an editable workspace and leaves the original PO/POT files
unchanged. Give the whole folder to the translator.

Translator: install Poedit, choose File →
Open
, open translations/uk.po, edit the Translation field and save. Keep
values such as %{name} unchanged. Return the whole folder to the builder.
Editing needs no SGN, Python or translation server.

Release builder: after review, build the ready bundle on Linux/POSIX with
Python 3.9+ and GNU gettext:

cd "$HOME/sgn-translation-v1"
python3 tools/sgn-i18n package --workspace . --output "$HOME/sgn-ready-v1"

The bundle includes language packs, operator tools, notices and the exact saved
release/PO inputs. See the
full translator and builder guide
for corrections and new releases.

Site administrator: from the unpacked ready folder, as the SGN server
account:

READY_DIR="$PWD"
python3 "$READY_DIR/operator-tools/sgn-i18n" install --activate \
  --pack "$READY_DIR/uk-pack" --root /srv/sgn-languages

Ready-pack operations need Linux/POSIX and Python 3.9+, with no Node, Perl, R or
gettext. Apply the three site settings and, for Docker, the whole-folder mount
once. The
installation guide
gives the exact settings, Docker steps, diagnostics, updates and rollback.
Installing files alone does not configure the running site.

Manual builder: from the SGN source folder in the Bookdown environment:

Rscript --vanilla docs/r_markdown_docs/build.R all "$HOME/sgn-manual-v1"

Open ~/sgn-manual-v1/index.html. The
manual guide
covers dependencies, editing, English/translated PDFs and publication.
Installing a UI pack does not publish manuals.

Validation and remaining work

Local qualification passed: 145 Python checks, 61 native files / 2,312
checks
, 133 R checks, an actual Poedit edit/save/package cycle, four
manual builds and four browser navigation cases. Tests cover package integrity,
interrupted operations, read-only diagnostics, rollback and saved-input
consistency. All 90 catalog JSON/index files and the three complete package
hashes stayed unchanged. See
validation details and limits
and the PR checks.

Translations are machine-generated drafts and still need native-speaker and
breeder review. Coverage is defined by the source registry, not every route or
background email. doctor does not prove an exact remote pack version or every
authenticated/scientific workflow. Full authenticated target-site acceptance
remains separate. This PR stays Draft.

Checklist

  • Refactoring only
  • Documentation only
  • Fixture update only
  • Bug fix
    • The relevant issue has been closed.
    • Further work is required.
  • New feature
    • Relevant tests have been created and run.
    • Data was added to the fixture
      • Data was added via a patch in /t/data/fixture/patches/.
    • User-Facing Change
      • The user manual in /docs has been updated.
    • Any new Perl has been documented using perldoc.
    • Any new JavaScript has been documented using JSDoc.
    • Any new legacy JavaScript has been moved from /js to /js/source/legacy.

Preserve current upstream data and authorization flows, use English fallback, and escape plain translated labels at their presentation sinks.

AI-Tool: Codex
Document machine translation and activation, preserve source attribution, and run JavaScript source and DOM regressions through the native unit entry point.

AI-Tool: Codex
Register 1759 current sources and 15399 active messages with named placeholders, plural rules, English fallback and machine-translation attribution.

AI-Tool: Codex
Add 29 chapters per language, machine-translation notices, isolated Bookdown builds, offline PDF export and source-contract checks. Preserve English chapters, scientific examples, figures, formulas and numeric values.

AI-Tool: Codex
Use independent unit fixtures, preserve strict JSON validation and data identifiers, correct English prose with existing translated forms, and validate fork documentation without publishing contributor branches.

AI-Tool: Codex
Keep the checked rules and move their files to .github/linters so fork jobs and notebook aliases resolve them consistently.

AI-Tool: Codex
Keep English prose checks enabled while treating generated catalogs and immutable registries consistently for local and CI path forms.

AI-Tool: Codex
Preserve numeric bit masks and controlled source fixtures while naming the exact Bangs and Lax policies used by Super-linter. Mark the test main package explicitly.

AI-Tool: Codex
Keep the existing recipient and token security assertions intact.

AI-Tool: Codex
Decode the controller-escaped field before interpolating and escaping the complete title once. Cover real Mason output, literal entities and hostile text in all four locales; preserve the existing HTTP security assertions.

AI-Tool: Codex
Preserve legacy generic-folder values for the strict translator and cover the real parent page and typed dialogs in four locales. Require the exact singular duplicate notice for the fixed one-accession Selenium fixture; keep list membership and added-count assertions intact.

AI-Tool: Codex
@isaak

isaak commented Oct 28, 2026

Copy link
Copy Markdown
Member

related to #5915?

@Globgor

Globgor commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

related to #5915?

Hi @isaak — yes, this is related to #5915. To be transparent: I started this work before I had looked at the translation issue #5915, so I didn't know it was already assigned to you and Lukas. Sorry about that — I don't want to step on your work.

Here is what the PR currently contains:

1. Core (Perl)

  • SGN::I18N — a translator that reads gettext catalogs compiled to JSON. Supports message context, named placeholders (%{name}), plural forms and right-to-left languages.
  • SGN::Role::Site::I18N — picks one language per request: ?lang=, sgn_locale cookie, browser Accept-Language, configured default, then English.
  • SGN::Controller::I18N + mason/i18n/language_selector.mas — a language selector in the header and catalog delivery to the browser.
  • Disabled by default (i18n_enabled 0 in sgn.conf). With it off, the site stays in English; no database schema or permission changes.

2. Interface strings

  • About 15,400 strings extracted into locale/sgn.pot, each with a key such as auth.login.title.
  • Strings wrapped in about 750 Mason templates, 320 Perl modules and 100 JavaScript files, plus an R helper (R/lib/sgn_i18n.R).
  • static/js/sgn-i18n.js — the same API in the browser.
  • Not translated: stored data, identifiers, API keys; solGS background emails stay in English.

3. Translations

  • Ukrainian, Spanish and Arabic catalogs (locale/{uk,es,ar}/LC_MESSAGES/sgn.po). They are machine-generated and need review by native speakers and breeders.
  • Country names come from the iso-codes project (LGPL-2.1); sources are listed in docs/i18n/TRANSLATION_SOURCES.md.

4. Tooling — script/i18n/: string extraction from Perl/Mason, JavaScript and R, catalog build and validation, with tests.

5. Tests and docs — about 36 new unit tests under t/unit/; setup, migration and translator guides under docs/i18n/.

6. User manuals — 29 chapters per language (87 Rmd files) in docs/r_markdown_docs/i18n/, with language navigation, RTL styling, and Bookdown/PDF builds.

7. Unrelated fixes that got mixed in — escaping goto_url in mason/user/login.mas, typo fixes in sgn.conf, a change to the docs workflow test_static.yml, and lint configs. I can move these into separate PRs.

I realize the PR is too large to review as it is. I'm happy to redo it in whatever form works best for you — smaller, larger, or a different approach. For example:

Just let me know which direction you and Lukas prefer, and I'll rework it.

@ryan-preble

ryan-preble commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

My thoughts so far, as I am going through this:

  • Should we put the user manual in its own repo?
  • Should translation catalogs get their own repo? I ask this because the developer workflow would get slightly annoying if for every single PR, there needed to be a step that included rebuilding the catalog so no edited text would get left untranslated. New catalogs could get published on new releases, so it happens a little less often and only needs to happen when production sites get updates. No need to install acorn or specific R dependencies on every target machine, just the machine building the releases
  • JS internationalization function ought to get a helper function to keep it less wordy. The following could be condensed down quite a lot
-alert('Please give weights!');
+alert((window.SGN && window.SGN.i18n ? window.SGN.i18n.p("accession.forms.please_give_weights", "Please give weights!") : "Please give weights!"));
  • i18n scripts folder should get moved into bin, or into the i18n repo if we make a separate repo
  • We should DEFINITLY add a chapter to the developer manual discussing how to apply and debug internationalization

These are preliminary thoughts; I will write more as I look into this further

@ryan-preble

Copy link
Copy Markdown
Contributor
  • language select should go in the site header bar to the left of the login button

Add short browser helpers, frozen release inputs and transactional partitioned language packages. Preserve language navigation, isolate unavailable packs and document developer and translator workflows.

Assisted-by: Codex
Preserve upstream missing-phenotype marker semantics, stock-property error responses and existing translated presentation.

Assisted-by: Codex
Keep the changed upstream import explanation fuzzy, retain native English without optional locale assets, and provide bounded terminology review batches.

Assisted-by: Codex
Exercise frozen message contracts with standard gettext in normal CI; retain separately qualified source extraction and full-corpus freeze evidence.

Assisted-by: Codex
Include print alternatives in Bookdown output and qualify all three translated PDF exports and page layouts.

Assisted-by: Codex
Keep the legacy English workflow explicit and document the isolated English builder required by the multilingual release.

Assisted-by: Codex
Keep ready operators independent of source extractors, remove unused plural checks and ignored arguments, use standard argparse help, and select exact messages for bounded terminology review.

Assisted-by: Codex
Select validated forms without a second dictionary, hash partitions once, read the single runtime directly, and keep disabled English independent of catalog files.

Assisted-by: Codex
Refresh chapter and section links, declare the actual reader language, use explicit Bookdown namespaces, and test the manual independently with its existing Playwright dependency.

Assisted-by: Codex
Explain the PEP 20 maintenance principles, two-step installation and current validation evidence without adding configuration or new dependencies.

Assisted-by: Codex
Preserve upstream POST-only account actions, seedlot status/filter behavior and the maintenance upload endpoint while retaining localized presentation. Refresh source references without changing message identities or package bytes.

Assisted-by: Codex
Prepare frozen editor workspaces, package saved snapshots, activate validated packs without copying hashes, diagnose read-only state and build all manual readers together.

Assisted-by: Codex
Explain roles, prerequisites, commands and outputs in source guides and generated workspace and ready-pack instructions.

Assisted-by: Codex
@Globgor

Globgor commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the feedback in the lab meeting. Here is how I restructured this work:

  1. Translations are in a separate repository: https://github.com/Globgor/sgn-translations. It holds the PO files split by section (one file per language per section), the translated user manuals and CI checks (same messages as the template, placeholders, plural forms, msgfmt --check). Adding or fixing a translation is a PR there only; sgn is not touched. All translations are machine-generated drafts; native speakers still need to review them. @lukasmueller, when you create the solgenomics repository, I can push this content there or transfer mine, whichever you prefer.
  2. Standard gettext instead of my own tools, as suggested in Use internationalization techniques in Breedbase #5915: xgettext extracts the strings, msgfmt builds .mo files, and SGN reads them with libintl-perl (Locale::Messages, the package that also provides Locale::TextDomain). The custom pack format and install tools from this PR are gone. A site needs only i18n_enabled 1 and i18n_enabled_locales en,uk.
  3. sgn keeps only the code, in small PRs, one at a time. First the core (Add opt-in interface translation core #6446): language choice per request, selector left of Login, short SGN.t / SGN.tn helpers, off by default, English unchanged. Then one PR per section (accessions, trials, lists, …).
  4. Sites get the translations like the other cxgn repos: one more submodule in breedbase_dockerfile (cxgn/sgn-translations), built with make during the image build, plus the Debian package libintl-perl (Add interface translations (sgn-translations) breedbase_dockerfile#62).
  5. I am closing this PR now that the core PR is open. The discussion here stays for reference.

@ryan-preble, this covers your points: catalogs and tools moved to the new repository, only the image build needs gettext, SGN.t / SGN.tn replace the long expression, the selector is in the header, and I have a developer-manual (wiki) page ready for the core PR.

Two questions:

  • Is libintl-perl in the breedbase image OK? It is the only new dependency. Without it SGN stays English.
  • Should the translated user manuals stay in the same repository (my proposal) or move to their own?

@Globgor Globgor closed this Nov 11, 2026
@ryan-preble

Copy link
Copy Markdown
Contributor

Two questions:

  • Is libintl-perl in the breedbase image OK? It is the only new dependency. Without it SGN stays English.
  • Should the translated user manuals stay in the same repository (my proposal) or move to their own?

I would say yes to both. @lukasmueller can comment on adding libintl-perl to the dockerfile. And it seems alright if the translated manuals stay in the translations repository.

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.

Use internationalization techniques in Breedbase

3 participants