docs(translations): step-by-step tutorial for the labels spreadsheet

translations/README.md walks through opening labels.csv in a spreadsheet,
translating, adding languages, keeping the CSV in sync with config.xml
(sync_labels.php / --check), generating SQL (csv_to_sql.php), loading it into
lime_source_message/lime_message and verifying in the admin UI.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 15:13:49 +01:00
commit 07f70bd00c
2 changed files with 80 additions and 1 deletions

View file

@ -133,7 +133,8 @@ language — the message tables are the right mechanism for that (a feature
request to expose the current language to twig has been prepared for the request to expose the current language to twig has been prepared for the
LimeSurvey developers). LimeSurvey developers).
**Translating via a spreadsheet (recommended workflow).** All theme labels **Translating via a spreadsheet (recommended workflow).** See the step-by-step
tutorial in `translations/README.md`. All theme labels
live in `translations/labels.csv` — one row per source string live in `translations/labels.csv` — one row per source string
(`context,key,source,<language columns...>`, by default one `nl` column), ready (`context,key,source,<language columns...>`, by default one `nl` column), ready
to open in Excel/LibreOffice. Keep it up to date during development with: to open in Excel/LibreOffice. Keep it up to date during development with:

78
translations/README.md Normal file
View file

@ -0,0 +1,78 @@
# Translating the theme labels — tutorial
The custom theme options page (`options/options.twig`) shows every label through
LimeSurvey's `gT()` translation function. LimeSurvey merges translations from two
sources: the core gettext catalogs (`locale/<lang>/<lang>.mo`, ~60 languages, core
strings only) and the database tables `lime_source_message` + `lime_message`
(merged at DBVersion >= 480). The theme's own labels are translated per installation
through those database tables — pure data, no core change needed.
This directory makes that easy with a spreadsheet:
- `labels.csv` — every translatable theme label, one row per source string
- `sync_labels.php` — keeps `labels.csv` in sync with `config.xml`
- `csv_to_sql.php` — turns a filled-in language column into SQL for the DB tables
## 1. Open the spreadsheet
Open `translations/labels.csv` in Excel, LibreOffice Calc or Google Sheets
(import as CSV, comma-separated, UTF-8). Layout:
| column | meaning |
|----------|----------------------------------------------------------------|
| `context`| where the string appears (option key / category / dropdown) |
| `key` | the config.xml option key (or `(category name)`) |
| `source` | the exact English source string — this is the gT() lookup key |
| `nl` | the Dutch translation (one column per language) |
Do not edit the `source` column: the source string must match the `title=` /
label in `config.xml` exactly, or the translation is not picked up.
## 2. Translate
Fill in the translation cells for the languages you need. Add another language
by adding a column to the header row, e.g. `de`, `fr`, `pt_PT`.
Notes:
- HTML in labels is intentional and must be kept, e.g. `<strong>...</strong>`.
- Some labels contain a line break (`XLarge\n(20 px)`) — keep it.
- Strings like `Yes` / `No` / `Inherit` are core strings and already translated
by the gettext catalogs; translating them here only overrides them for this
installation.
## 3. Keep the spreadsheet up to date during development
Whenever `config.xml` changes (new option, renamed title, new dropdown entry),
re-run:
php translations/sync_labels.php
This re-extracts all labels from `config.xml` and merges them into `labels.csv`:
new strings are appended with empty translation cells, your existing translations
are preserved, strings that disappeared from `config.xml` are removed (and
reported on screen). To check staleness without writing (e.g. in a dev check):
php translations/sync_labels.php --check # exit 1 when out of sync
## 4. Generate the SQL and load it into the database
php translations/csv_to_sql.php translations/labels.csv nl > nl.sql
mysql -h localhost -u <dbuser> -p <dbname> < nl.sql
The generated SQL is idempotent (`INSERT IGNORE` + `ON DUPLICATE KEY UPDATE`), so
re-run it after every edit of the CSV. Repeat per language (`... labels.csv de >
de.sql`, etc.). Empty translation cells are skipped.
The admin sees the translations as soon as their UI language matches — no theme
reset or asset flush is needed (the message tables are read at runtime). To ship
translations with the theme itself, commit the filled-in `labels.csv` to this
repository; other installations can then load them the same way.
## 5. Verify
Log into LimeSurvey with the target UI language (e.g. Nederlands), open
Theme options of a survey that uses this theme, and check the labels on the custom
options page. If a label still shows English, its `source` cell in the CSV does
not exactly match the `title=`/label in `config.xml` — re-run `sync_labels.php`
and compare.