# 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//.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. `...`. - 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 -p < 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.