feat(translations): spreadsheet workflow for translating theme labels

translations/labels.csv holds every translatable label (164 strings extracted
from config.xml: option titles, category names, optionlabels, dropdown
optgroup/option labels) with one column per language (default nl).
translations/sync_labels.php re-extracts labels from config.xml and merges:
new strings appended empty, existing translations preserved, removed strings
dropped; --check exits 1 when stale (run after config.xml changes).
translations/csv_to_sql.php turns a filled-in CSV column into idempotent SQL
for lime_source_message/lime_message. README i18n section documents the
workflow.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 15:11:23 +01:00
commit 7a758d807a
4 changed files with 464 additions and 5 deletions

View file

@ -92,6 +92,11 @@ Arguments for choosing Respondage Vanilla:
`.gitignore`): `variants/*.json` (client definitions with house-style
values), `variants/leak-patterns.txt` and `variants/tests/` — those live in
the private variants repo, not here.
- `translations/` — the translation spreadsheet workflow: `labels.csv` (all
theme labels, one row per source string, one column per language) plus
`sync_labels.php` (re-extracts labels from `config.xml`, keeps existing
translations) and `csv_to_sql.php` (CSV → SQL for the `lime_source_message`/
`lime_message` tables). See "Multiple languages in the theme options (i18n)".
## Multiple languages in the theme options (i18n)
@ -128,11 +133,30 @@ 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
LimeSurvey developers).
**Still to be done: translations.** The theme ships only the English source
strings — no translations of its own labels (option titles, category names,
dropdown labels) are bundled or pre-filled yet. Filling in translations (per
language, e.g. Dutch for the options page) via the message tables above is
open work; contributions of translations to this repository are welcome.
**Translating via a spreadsheet (recommended workflow).** All theme labels
live in `translations/labels.csv` — one row per source string
(`context,key,source,<language columns...>`, by default one `nl` column), ready
to open in Excel/LibreOffice. Keep it up to date during development with:
php translations/sync_labels.php # re-extract labels from config.xml:
# new strings are appended with empty
# translation cells, existing translations
# are preserved, removed strings are dropped
php translations/sync_labels.php --check # exit 1 when labels.csv is stale
# (run this after changing config.xml)
After editing translations in the spreadsheet, generate the SQL for the message
tables and run it in the installation's database:
php translations/csv_to_sql.php translations/labels.csv nl > nl.sql
mysql -h localhost -u <user> -p <database> < nl.sql
(`csv_to_sql.php` emits idempotent INSERTs — safe to re-run after each edit. Add
a language by adding a column to the CSV header, e.g. `de`.) To ship
translations with the theme itself, commit the filled-in `labels.csv` —
**still to be done:** no translations are filled in yet; the theme ships only
the English source strings. Contributions of translations to this repository
are welcome.
## Header logos (left / center / right)

View file

@ -0,0 +1,75 @@
<?php
/**
* Generate the SQL that loads the translations from translations/labels.csv
* into the LimeSurvey message tables (lime_source_message + lime_message) of
* one installation — the mechanism documented in README "Multiple languages in
* the theme options (i18n)".
*
* Usage:
* php translations/csv_to_sql.php <labels.csv> <language-code> > translations.sql
* e.g. php translations/csv_to_sql.php labels.csv nl > nl.sql
*
* Then run the generated SQL in the LimeSurvey database, e.g.:
* mysql -h localhost -u <user> -p <database> < translations.sql
*
* The generated SQL is idempotent: existing source messages are reused
* (INSERT IGNORE) and existing translations are updated (ON DUPLICATE KEY
* UPDATE), so re-running after editing the CSV is safe. Rows with an empty
* translation cell are skipped. Only strings whose source exactly matches a
* title/label in config.xml are translated by gT() — sync_labels.php keeps
* the CSV in sync with config.xml.
*/
if (PHP_SAPI !== 'cli') {
fwrite(STDERR, "This script must be run from the command line.\n");
exit(1);
}
$csvFile = $argv[1] ?? '';
$lang = $argv[2] ?? '';
if ($csvFile === '' || $lang === '' || !is_file($csvFile)) {
fwrite(STDERR, "Usage: php translations/csv_to_sql.php <labels.csv> <language-code>\n");
exit(1);
}
if (!preg_match('/^[a-z]{2}(_[A-Z]{2})?$/', $lang)) {
fwrite(STDERR, "Language code must look like 'nl' or 'pt_PT'\n");
exit(1);
}
$fh = fopen($csvFile, 'r');
$header = fgetcsv($fh);
if ($header === false || count($header) < 4) {
fwrite(STDERR, "CSV header must be context,key,source,<lang...>\n");
exit(1);
}
$langIndex = array_search($lang, array_slice($header, 3), true);
if ($langIndex === false) {
fwrite(STDERR, "No column '$lang' in $csvFile (header: " . implode(',', array_slice($header, 3)) . ")\n");
exit(1);
}
$langCol = 3 + $langIndex;
$sql = fn($s) => str_replace("'", "''", $s);
echo "-- Theme labels ($lang) generated from $csvFile by translations/csv_to_sql.php\n";
echo "-- Run in the LimeSurvey database. Idempotent: safe to re-run after editing the CSV.\n";
echo "SET NAMES utf8mb4;\n\n";
$n = 0;
while (($r = fgetcsv($fh)) !== false) {
if (count($r) <= $langCol) {
continue;
}
$source = $r[2] ?? '';
$translation = $r[$langCol] ?? '';
if (trim($source) === '' || trim($translation) === '') {
continue;
}
echo "INSERT IGNORE INTO lime_source_message (category, message) VALUES ('', '" . $sql($source) . "');\n";
echo "INSERT INTO lime_message (id, language, translation)\n";
echo " SELECT id, '$lang', '" . $sql($translation) . "' FROM lime_source_message WHERE category = '' AND message = '" . $sql($source) . "'\n";
echo " ON DUPLICATE KEY UPDATE translation = VALUES(translation);\n\n";
$n++;
}
fclose($fh);
echo "-- $n translation(s) for '$lang'\n";

166
translations/labels.csv Normal file
View file

@ -0,0 +1,166 @@
context,key,source,nl
category,"(category name)","Default font and colors",
category,"(category name)",Header,
category,"(category name)","Page background",
category,"(category name)",Groups,
category,"(category name)",Questions,
category,"(category name)",Buttons,
category,"(category name)","Other options",
"option font (Default font and colors)",font,"Default font (body text)",
"option font optgroup",font,"Bundled open source fonts",
"option font dropdown option",font,"Atkinson Hyperlegible (sans-serif, accessibility)",
"option font dropdown option",font,"Inter (sans-serif)",
"option font dropdown option",font,"Noto Sans (sans-serif, multilingual fallback)",
"option font dropdown option",font,"Noto Serif (serif)",
"option font optgroup",font,"Custom (this theme)",
"option font optgroup",font,"User browser",
"option font dropdown option",font,Arial,
"option font dropdown option",font,"Arial Black",
"option font dropdown option",font,"Comic Sans",
"option font dropdown option",font,"Courier New",
"option font dropdown option",font,Georgia,
"option font dropdown option",font,Impact,
"option font dropdown option",font,"Lucida Console",
"option font dropdown option",font,"Lucida Sans",
"option font dropdown option",font,"Palatino Linotype",
"option font dropdown option",font,"Times New Roman",
"option font dropdown option",font,Trebuchet,
"option fontsize (Default font and colors)",fontsize,"Base font size (body text)",
"option fontsize optionlabel",fontsize,"Small (14px)",
"option fontsize optionlabel",fontsize,"Normal (16px)",
"option fontsize optionlabel",fontsize,"Large (18px)",
"option fontsize optionlabel",fontsize,"XLarge
(20 px)",
"option fontcolor (Default font and colors)",fontcolor,"Default font color (body text)",
"option fontcolor optionlabel",fontcolor,Yes,
"option fontcolor optionlabel",fontcolor,No,
"option defaultbackgroundcolor (Default font and colors)",defaultbackgroundcolor,"Default background color",
"option primarycolor (Default font and colors)",primarycolor,"Color 1 (primary)",
"option secondarycolor (Default font and colors)",secondarycolor,"Color 2",
"option tertiarycolor (Default font and colors)",tertiarycolor,"Color 3",
"option headerfont (Header)",headerfont,"Font for the header / top menu",
"option navbarfontcolor (Header)",navbarfontcolor,"Font color for the header menu",
"option navbarfontcolor optionlabel",navbarfontcolor,"Default font color",
"option navbarfontcolor optionlabel",navbarfontcolor,"Color 1",
"option navbarfontcolor optionlabel",navbarfontcolor,"Other ...",
"option navbarfontcolorcustom (Header)",navbarfontcolorcustom,"Custom font color for the header menu (for 'Other ...')",
"option headerbackgroundcolor (Header)",headerbackgroundcolor,"Header background color",
"option headerbackgroundcolorcustom (Header)",headerbackgroundcolorcustom,"Custom header background color (for 'Other ...')",
"option headersticky (Header)",headersticky,"Make header sticky",
"option headerstickycomputer (Header)",headerstickycomputer,"Computer screen",
"option headerstickytablet (Header)",headerstickytablet,Tablet,
"option headerstickymobile (Header)",headerstickymobile,"Mobile phone",
"option headerheight (Header)",headerheight,"Header bar height, in px",
"option brandlogofile (Header)",brandlogofile,"Logo file (left)",
"option brandlogotopmargin (Header)",brandlogotopmargin,"Margin between logo and top of screen (left), in px (0-100)",
"option centerlogofile (Header)",centerlogofile,"Logo file (center)",
"option centerlogotopmargin (Header)",centerlogotopmargin,"Margin between logo and top of screen (center), in px (0-100)",
"option rightlogofile (Header)",rightlogofile,"Logo file (right)",
"option rightlogotopmargin (Header)",rightlogotopmargin,"Margin between logo and top of screen (right), in px (0-100)",
"option progressbarposition (Header)",progressbarposition,"Position of the progress bar",
"option progressbarposition optionlabel",progressbarposition,"In header",
"option progressbarposition optionlabel",progressbarposition,"Under header",
"option progressbarfont (Header)",progressbarfont,"Font for the progress bar",
"option progressbarcolor (Header)",progressbarcolor,"Progress bar color",
"option progressbarcolorcustom (Header)",progressbarcolorcustom,"Custom progress bar color (for 'Other ...')",
"option progressbarbackgroundcolor (Header)",progressbarbackgroundcolor,"Progress bar background color",
"option progressbarbackgroundcolorcustom (Header)",progressbarbackgroundcolorcustom,"Custom progress bar background color (for 'Other ...')",
"option progressbarfontcolor (Header)",progressbarfontcolor,"Font color for the progress bar",
"option progressbarfontcolorcustom (Header)",progressbarfontcolorcustom,"Custom font color for the progress bar (for 'Other ...')",
"option bodybackgroundcolor (Page background)",bodybackgroundcolor,"Overall background color",
"option bodybackgroundcolorcustom (Page background)",bodybackgroundcolorcustom,"Custom overall background color (for 'Other ...')",
"option backgroundimage (Page background)",backgroundimage,"Background image (behind body of page)",
"option backgroundimagefile (Page background)",backgroundimagefile,"Background image file",
"option backgroundimagefixed (Page background)",backgroundimagefixed,"Background image fixed or scroll",
"option backgroundimagefixed optionlabel",backgroundimagefixed,Fixed,
"option backgroundimagefixed optionlabel",backgroundimagefixed,Scroll,
"option backgroundimagedisplay (Page background)",backgroundimagedisplay,"Background image display",
"option backgroundimagedisplay optionlabel",backgroundimagedisplay,Tile,
"option backgroundimagedisplay optionlabel",backgroundimagedisplay,Cover,
"option privacybackgroundcolor (Page background)",privacybackgroundcolor,"Privacy background color",
"option grouptitlefont (Groups)",grouptitlefont,"Font for group title",
"option grouptitletextcolor (Groups)",grouptitletextcolor,"Font color for group titles",
"option grouptitletextcolorcustom (Groups)",grouptitletextcolorcustom,"Custom font color for group titles (for 'Other ...')",
"option grouptitlefontsize (Groups)",grouptitlefontsize,"Group title font size",
"option grouptitlefontsize optionlabel",grouptitlefontsize,"Same as Base Font Size(BFS)",
"option grouptitlefontsize optionlabel",grouptitlefontsize,"1.2 BFS",
"option grouptitlefontsize optionlabel",grouptitlefontsize,"1.5 BFS",
"option grouptitlefontsize optionlabel",grouptitlefontsize,"2.0 BFS",
"option grouptitlefontsize optionlabel",grouptitlefontsize,20px,
"option grouptitlefontsize optionlabel",grouptitlefontsize,24px,
"option grouptitlefontoptions (Groups)",grouptitlefontoptions,"Group title font options",
"option grouptitlefontoptions optionlabel",grouptitlefontoptions,Normal,
"option grouptitlefontoptions optionlabel",grouptitlefontoptions,Bold,
"option grouptitlefontoptions optionlabel",grouptitlefontoptions,Italic,
"option grouptitlefontoptions optionlabel",grouptitlefontoptions,"Bold italic",
"option groupdescriptionfont (Groups)",groupdescriptionfont,"Font for group description",
"option groupdescriptiontextcolor (Groups)",groupdescriptiontextcolor,"Font color for group descriptions",
"option groupdescriptiontextcolorcustom (Groups)",groupdescriptiontextcolorcustom,"Custom font color for group descriptions (for 'Other ...')",
"option groupdescriptionfontsize (Groups)",groupdescriptionfontsize,"Group description font size",
"option groupdescriptionfontoptions (Groups)",groupdescriptionfontoptions,"Group description font options",
"option questiondistance (Questions)",questiondistance,"Distance between two questions (px or rem)",
"option questiondistancebottom (Questions)",questiondistancebottom,"Distance between last question and buttons at bottom of page (px or rem)",
"option questiontitlefont (Questions)",questiontitlefont,"Font for question titles",
"option questiontitletextcolor (Questions)",questiontitletextcolor,"Font color for question titles",
"option questiontitletextcolorcustom (Questions)",questiontitletextcolorcustom,"Custom font color for question titles (for 'Other ...')",
"option questiontitlefontsize (Questions)",questiontitlefontsize,"Question title font size",
"option questiontitlefontoptions (Questions)",questiontitlefontoptions,"Question title font options",
"option questiontitlefontcolor (Questions)",questiontitlefontcolor,"Font color for question titles (legacy picker)",
"option questiontitlebackgroundcolor (Questions)",questiontitlebackgroundcolor,"Question title background color",
"option questiontitlebackgroundcolorcustom (Questions)",questiontitlebackgroundcolorcustom,"Custom question title background color (for 'Other ...')",
"option questionbackgroundcolor (Questions)",questionbackgroundcolor,"Question body background color",
"option questionbackgroundcolorcustom (Questions)",questionbackgroundcolorcustom,"Custom question body background color (for 'Other ...')",
"option answersfont (Questions)",answersfont,"Font for answers and subquestions",
"option answerstextcolor (Questions)",answerstextcolor,"Font color for answers and subquestions",
"option answerstextcolorcustom (Questions)",answerstextcolorcustom,"Custom font color for answers and subquestions (for 'Other ...')",
"option checkboxcolor (Questions)",checkboxcolor,"Checkbox/radio button color (when checked)",
"option checkboxcolorcustom (Questions)",checkboxcolorcustom,"Custom checkbox/radiobutton color (for 'Other ...')",
"option sliderhandlecolor (Questions)",sliderhandlecolor,"Slider handle color",
"option sliderhandlecolorcustom (Questions)",sliderhandlecolorcustom,"Custom slider handle color (for 'Other ...')",
"option questionhelpfont (Questions)",questionhelpfont,"Font for question help text",
"option questionhelpfontcolor (Questions)",questionhelpfontcolor,"Font color for question help text",
"option questionhelpfontcolorcustom (Questions)",questionhelpfontcolorcustom,"Custom font color for question help text (for 'Other ...')",
"option questionhelpbackgroundcolor (Questions)",questionhelpbackgroundcolor,"Question help background color",
"option questionhelpbackgroundcolorcustom (Questions)",questionhelpbackgroundcolorcustom,"Custom question help background color (for 'Other ...')",
"option questionhelptextposition (Questions)",questionhelptextposition,"Question help text position",
"option questionhelptextposition optionlabel",questionhelptextposition,Top,
"option questionhelptextposition optionlabel",questionhelptextposition,Bottom,
"option questionborder (Questions)",questionborder,"Question border",
"option questionborder optionlabel",questionborder,"Box around",
"option questionborder optionlabel",questionborder,"Top and bottom",
"option questionborder optionlabel",questionborder,None,
"option questionbordercolor (Questions)",questionbordercolor,"Question border color",
"option questionbordercolorcustom (Questions)",questionbordercolorcustom,"Custom question border color (for 'Other ...')",
"option questionborderstyle (Questions)",questionborderstyle,"Question border line style",
"option questionborderstyle optionlabel",questionborderstyle,Solid,
"option questionborderstyle optionlabel",questionborderstyle,Dotted,
"option questionborderstyle optionlabel",questionborderstyle,Dashed,
"option questiondropdown (Questions)",questiondropdown,"Question dropdown shadow",
"option questiondropdown optionlabel",questiondropdown,Always,
"option questiondropdown optionlabel",questiondropdown,"On hover only",
"option questionborderradiusTL (Questions)",questionborderradiusTL,"Border radius top left",
"option questionborderradiusTR (Questions)",questionborderradiusTR,"Border radius top right",
"option questionborderradiusBL (Questions)",questionborderradiusBL,"Border radius bottom left",
"option questionborderradiusBR (Questions)",questionborderradiusBR,"Border radius bottom right",
"option buttonsfont (Buttons)",buttonsfont,"Font for the buttons (Previous/Next/Submit)",
"option previousbuttonbackgroundcolor (Buttons)",previousbuttonbackgroundcolor,"Previous button background color",
"option previousbuttonbackgroundcolor optionlabel",previousbuttonbackgroundcolor,"Default button color",
"option previousbuttonbackgroundcolorcustom (Buttons)",previousbuttonbackgroundcolorcustom,"Custom previous button background color (for 'Other ...')",
"option previousbuttontextcolor (Buttons)",previousbuttontextcolor,"Font color for the Previous button",
"option previousbuttontextcolorcustom (Buttons)",previousbuttontextcolorcustom,"Custom font color for the Previous button (for 'Other ...')",
"option nextbuttonbackgroundcolor (Buttons)",nextbuttonbackgroundcolor,"Next button background color",
"option nextbuttonbackgroundcolorcustom (Buttons)",nextbuttonbackgroundcolorcustom,"Custom next button background color (for 'Other ...')",
"option nextbuttontextcolor (Buttons)",nextbuttontextcolor,"Font color for the Next button",
"option nextbuttontextcolorcustom (Buttons)",nextbuttontextcolorcustom,"Custom font color for the Next button (for 'Other ...')",
"option submitbuttonbackgroundcolor (Buttons)",submitbuttonbackgroundcolor,"Submit button background color",
"option submitbuttonbackgroundcolorcustom (Buttons)",submitbuttonbackgroundcolorcustom,"Custom submit button background color (for 'Other ...')",
"option submitbuttontextcolor (Buttons)",submitbuttontextcolor,"Font color for the Submit button",
"option submitbuttontextcolorcustom (Buttons)",submitbuttontextcolorcustom,"Custom font color for the Submit button (for 'Other ...')",
"option hideprivacyinfo (Other options)",hideprivacyinfo,"Hide privacy info",
"option container (Other options)",container,"Survey container",
"option showpopups (Other options)",showpopups,"Show popups",
"option showpopups optionlabel",showpopups,Popup,
"option showpopups optionlabel",showpopups,"On page",
"option showclearall (Other options)",showclearall,"Show Clear All button",
"option fixnumauto (Other options)",fixnumauto,"Fix automatically numeric value",
"option fixnumauto optionlabel",fixnumauto,"For expression",
1 context key source nl
2 category (category name) Default font and colors
3 category (category name) Header
4 category (category name) Page background
5 category (category name) Groups
6 category (category name) Questions
7 category (category name) Buttons
8 category (category name) Other options
9 option font (Default font and colors) font Default font (body text)
10 option font optgroup font Bundled open source fonts
11 option font dropdown option font Atkinson Hyperlegible (sans-serif, accessibility)
12 option font dropdown option font Inter (sans-serif)
13 option font dropdown option font Noto Sans (sans-serif, multilingual fallback)
14 option font dropdown option font Noto Serif (serif)
15 option font optgroup font Custom (this theme)
16 option font optgroup font User browser
17 option font dropdown option font Arial
18 option font dropdown option font Arial Black
19 option font dropdown option font Comic Sans
20 option font dropdown option font Courier New
21 option font dropdown option font Georgia
22 option font dropdown option font Impact
23 option font dropdown option font Lucida Console
24 option font dropdown option font Lucida Sans
25 option font dropdown option font Palatino Linotype
26 option font dropdown option font Times New Roman
27 option font dropdown option font Trebuchet
28 option fontsize (Default font and colors) fontsize Base font size (body text)
29 option fontsize optionlabel fontsize Small (14px)
30 option fontsize optionlabel fontsize Normal (16px)
31 option fontsize optionlabel fontsize Large (18px)
32 option fontsize optionlabel fontsize XLarge (20 px)
33 option fontcolor (Default font and colors) fontcolor Default font color (body text)
34 option fontcolor optionlabel fontcolor Yes
35 option fontcolor optionlabel fontcolor No
36 option defaultbackgroundcolor (Default font and colors) defaultbackgroundcolor Default background color
37 option primarycolor (Default font and colors) primarycolor Color 1 (primary)
38 option secondarycolor (Default font and colors) secondarycolor Color 2
39 option tertiarycolor (Default font and colors) tertiarycolor Color 3
40 option headerfont (Header) headerfont Font for the header / top menu
41 option navbarfontcolor (Header) navbarfontcolor Font color for the header menu
42 option navbarfontcolor optionlabel navbarfontcolor Default font color
43 option navbarfontcolor optionlabel navbarfontcolor Color 1
44 option navbarfontcolor optionlabel navbarfontcolor Other ...
45 option navbarfontcolorcustom (Header) navbarfontcolorcustom Custom font color for the header menu (for 'Other ...')
46 option headerbackgroundcolor (Header) headerbackgroundcolor Header background color
47 option headerbackgroundcolorcustom (Header) headerbackgroundcolorcustom Custom header background color (for 'Other ...')
48 option headersticky (Header) headersticky Make header sticky
49 option headerstickycomputer (Header) headerstickycomputer Computer screen
50 option headerstickytablet (Header) headerstickytablet Tablet
51 option headerstickymobile (Header) headerstickymobile Mobile phone
52 option headerheight (Header) headerheight Header bar height, in px
53 option brandlogofile (Header) brandlogofile Logo file (left)
54 option brandlogotopmargin (Header) brandlogotopmargin Margin between logo and top of screen (left), in px (0-100)
55 option centerlogofile (Header) centerlogofile Logo file (center)
56 option centerlogotopmargin (Header) centerlogotopmargin Margin between logo and top of screen (center), in px (0-100)
57 option rightlogofile (Header) rightlogofile Logo file (right)
58 option rightlogotopmargin (Header) rightlogotopmargin Margin between logo and top of screen (right), in px (0-100)
59 option progressbarposition (Header) progressbarposition Position of the progress bar
60 option progressbarposition optionlabel progressbarposition In header
61 option progressbarposition optionlabel progressbarposition Under header
62 option progressbarfont (Header) progressbarfont Font for the progress bar
63 option progressbarcolor (Header) progressbarcolor Progress bar color
64 option progressbarcolorcustom (Header) progressbarcolorcustom Custom progress bar color (for 'Other ...')
65 option progressbarbackgroundcolor (Header) progressbarbackgroundcolor Progress bar background color
66 option progressbarbackgroundcolorcustom (Header) progressbarbackgroundcolorcustom Custom progress bar background color (for 'Other ...')
67 option progressbarfontcolor (Header) progressbarfontcolor Font color for the progress bar
68 option progressbarfontcolorcustom (Header) progressbarfontcolorcustom Custom font color for the progress bar (for 'Other ...')
69 option bodybackgroundcolor (Page background) bodybackgroundcolor Overall background color
70 option bodybackgroundcolorcustom (Page background) bodybackgroundcolorcustom Custom overall background color (for 'Other ...')
71 option backgroundimage (Page background) backgroundimage Background image (behind body of page)
72 option backgroundimagefile (Page background) backgroundimagefile Background image file
73 option backgroundimagefixed (Page background) backgroundimagefixed Background image fixed or scroll
74 option backgroundimagefixed optionlabel backgroundimagefixed Fixed
75 option backgroundimagefixed optionlabel backgroundimagefixed Scroll
76 option backgroundimagedisplay (Page background) backgroundimagedisplay Background image display
77 option backgroundimagedisplay optionlabel backgroundimagedisplay Tile
78 option backgroundimagedisplay optionlabel backgroundimagedisplay Cover
79 option privacybackgroundcolor (Page background) privacybackgroundcolor Privacy background color
80 option grouptitlefont (Groups) grouptitlefont Font for group title
81 option grouptitletextcolor (Groups) grouptitletextcolor Font color for group titles
82 option grouptitletextcolorcustom (Groups) grouptitletextcolorcustom Custom font color for group titles (for 'Other ...')
83 option grouptitlefontsize (Groups) grouptitlefontsize Group title font size
84 option grouptitlefontsize optionlabel grouptitlefontsize Same as Base Font Size(BFS)
85 option grouptitlefontsize optionlabel grouptitlefontsize 1.2 BFS
86 option grouptitlefontsize optionlabel grouptitlefontsize 1.5 BFS
87 option grouptitlefontsize optionlabel grouptitlefontsize 2.0 BFS
88 option grouptitlefontsize optionlabel grouptitlefontsize 20px
89 option grouptitlefontsize optionlabel grouptitlefontsize 24px
90 option grouptitlefontoptions (Groups) grouptitlefontoptions Group title font options
91 option grouptitlefontoptions optionlabel grouptitlefontoptions Normal
92 option grouptitlefontoptions optionlabel grouptitlefontoptions Bold
93 option grouptitlefontoptions optionlabel grouptitlefontoptions Italic
94 option grouptitlefontoptions optionlabel grouptitlefontoptions Bold italic
95 option groupdescriptionfont (Groups) groupdescriptionfont Font for group description
96 option groupdescriptiontextcolor (Groups) groupdescriptiontextcolor Font color for group descriptions
97 option groupdescriptiontextcolorcustom (Groups) groupdescriptiontextcolorcustom Custom font color for group descriptions (for 'Other ...')
98 option groupdescriptionfontsize (Groups) groupdescriptionfontsize Group description font size
99 option groupdescriptionfontoptions (Groups) groupdescriptionfontoptions Group description font options
100 option questiondistance (Questions) questiondistance Distance between two questions (px or rem)
101 option questiondistancebottom (Questions) questiondistancebottom Distance between last question and buttons at bottom of page (px or rem)
102 option questiontitlefont (Questions) questiontitlefont Font for question titles
103 option questiontitletextcolor (Questions) questiontitletextcolor Font color for question titles
104 option questiontitletextcolorcustom (Questions) questiontitletextcolorcustom Custom font color for question titles (for 'Other ...')
105 option questiontitlefontsize (Questions) questiontitlefontsize Question title font size
106 option questiontitlefontoptions (Questions) questiontitlefontoptions Question title font options
107 option questiontitlefontcolor (Questions) questiontitlefontcolor Font color for question titles (legacy picker)
108 option questiontitlebackgroundcolor (Questions) questiontitlebackgroundcolor Question title background color
109 option questiontitlebackgroundcolorcustom (Questions) questiontitlebackgroundcolorcustom Custom question title background color (for 'Other ...')
110 option questionbackgroundcolor (Questions) questionbackgroundcolor Question body background color
111 option questionbackgroundcolorcustom (Questions) questionbackgroundcolorcustom Custom question body background color (for 'Other ...')
112 option answersfont (Questions) answersfont Font for answers and subquestions
113 option answerstextcolor (Questions) answerstextcolor Font color for answers and subquestions
114 option answerstextcolorcustom (Questions) answerstextcolorcustom Custom font color for answers and subquestions (for 'Other ...')
115 option checkboxcolor (Questions) checkboxcolor Checkbox/radio button color (when checked)
116 option checkboxcolorcustom (Questions) checkboxcolorcustom Custom checkbox/radiobutton color (for 'Other ...')
117 option sliderhandlecolor (Questions) sliderhandlecolor Slider handle color
118 option sliderhandlecolorcustom (Questions) sliderhandlecolorcustom Custom slider handle color (for 'Other ...')
119 option questionhelpfont (Questions) questionhelpfont Font for question help text
120 option questionhelpfontcolor (Questions) questionhelpfontcolor Font color for question help text
121 option questionhelpfontcolorcustom (Questions) questionhelpfontcolorcustom Custom font color for question help text (for 'Other ...')
122 option questionhelpbackgroundcolor (Questions) questionhelpbackgroundcolor Question help background color
123 option questionhelpbackgroundcolorcustom (Questions) questionhelpbackgroundcolorcustom Custom question help background color (for 'Other ...')
124 option questionhelptextposition (Questions) questionhelptextposition Question help text position
125 option questionhelptextposition optionlabel questionhelptextposition Top
126 option questionhelptextposition optionlabel questionhelptextposition Bottom
127 option questionborder (Questions) questionborder Question border
128 option questionborder optionlabel questionborder Box around
129 option questionborder optionlabel questionborder Top and bottom
130 option questionborder optionlabel questionborder None
131 option questionbordercolor (Questions) questionbordercolor Question border color
132 option questionbordercolorcustom (Questions) questionbordercolorcustom Custom question border color (for 'Other ...')
133 option questionborderstyle (Questions) questionborderstyle Question border line style
134 option questionborderstyle optionlabel questionborderstyle Solid
135 option questionborderstyle optionlabel questionborderstyle Dotted
136 option questionborderstyle optionlabel questionborderstyle Dashed
137 option questiondropdown (Questions) questiondropdown Question dropdown shadow
138 option questiondropdown optionlabel questiondropdown Always
139 option questiondropdown optionlabel questiondropdown On hover only
140 option questionborderradiusTL (Questions) questionborderradiusTL Border radius top left
141 option questionborderradiusTR (Questions) questionborderradiusTR Border radius top right
142 option questionborderradiusBL (Questions) questionborderradiusBL Border radius bottom left
143 option questionborderradiusBR (Questions) questionborderradiusBR Border radius bottom right
144 option buttonsfont (Buttons) buttonsfont Font for the buttons (Previous/Next/Submit)
145 option previousbuttonbackgroundcolor (Buttons) previousbuttonbackgroundcolor Previous button background color
146 option previousbuttonbackgroundcolor optionlabel previousbuttonbackgroundcolor Default button color
147 option previousbuttonbackgroundcolorcustom (Buttons) previousbuttonbackgroundcolorcustom Custom previous button background color (for 'Other ...')
148 option previousbuttontextcolor (Buttons) previousbuttontextcolor Font color for the Previous button
149 option previousbuttontextcolorcustom (Buttons) previousbuttontextcolorcustom Custom font color for the Previous button (for 'Other ...')
150 option nextbuttonbackgroundcolor (Buttons) nextbuttonbackgroundcolor Next button background color
151 option nextbuttonbackgroundcolorcustom (Buttons) nextbuttonbackgroundcolorcustom Custom next button background color (for 'Other ...')
152 option nextbuttontextcolor (Buttons) nextbuttontextcolor Font color for the Next button
153 option nextbuttontextcolorcustom (Buttons) nextbuttontextcolorcustom Custom font color for the Next button (for 'Other ...')
154 option submitbuttonbackgroundcolor (Buttons) submitbuttonbackgroundcolor Submit button background color
155 option submitbuttonbackgroundcolorcustom (Buttons) submitbuttonbackgroundcolorcustom Custom submit button background color (for 'Other ...')
156 option submitbuttontextcolor (Buttons) submitbuttontextcolor Font color for the Submit button
157 option submitbuttontextcolorcustom (Buttons) submitbuttontextcolorcustom Custom font color for the Submit button (for 'Other ...')
158 option hideprivacyinfo (Other options) hideprivacyinfo Hide privacy info
159 option container (Other options) container Survey container
160 option showpopups (Other options) showpopups Show popups
161 option showpopups optionlabel showpopups Popup
162 option showpopups optionlabel showpopups On page
163 option showclearall (Other options) showclearall Show Clear All button
164 option fixnumauto (Other options) fixnumauto Fix automatically numeric value
165 option fixnumauto optionlabel fixnumauto For expression

View file

@ -0,0 +1,194 @@
<?php
/**
* Extract every translatable label of this theme from config.xml into a
* spreadsheet-friendly CSV (translations/labels.csv) and keep that CSV up to
* date during development.
*
* What is extracted (all of it is shown to the admin through gT() on the
* custom options page, so the English source string is the translation key):
* - every <options>/<key> title="..." (context "option <key>")
* - every distinct category="..." name (context "category")
* - every optionlabels="A|B|..." entry (context "option <key> optionlabel")
* - every dropdown <optgroup label="..."> (context "option <key> optgroup")
* - every dropdown <option> label text (context "option <key> dropdown option")
*
* Usage:
* php translations/sync_labels.php update labels.csv (merge, preserve translations)
* php translations/sync_labels.php --check exit 1 when labels.csv is stale (for dev/CI checks)
*
* CSV layout: context,key,source,<language columns...>
* The language columns are whatever the header row has after "source"
* (default: "nl"). Add a language by adding a column in a spreadsheet editor;
* existing translations are never overwritten, new strings are appended with
* empty translation cells, strings that disappeared from config.xml are removed
* (and reported). Rows are keyed by the source string, because gT() translates
* by message text.
*
* After editing translations in the CSV, generate the SQL for the LimeSurvey
* message tables with:
* php translations/csv_to_sql.php translations/labels.csv nl > nl.sql
* and run that SQL in the installation's database (see README "Multiple
* languages in the theme options (i18n)").
*/
if (PHP_SAPI !== 'cli') {
fwrite(STDERR, "This script must be run from the command line.\n");
exit(1);
}
$here = __DIR__;
$themeDir = dirname($here);
$configFile = $themeDir . DIRECTORY_SEPARATOR . 'config.xml';
$csvFile = $here . DIRECTORY_SEPARATOR . 'labels.csv';
$check = in_array('--check', $argv, true);
if (!is_file($configFile)) {
fwrite(STDERR, "config.xml not found: $configFile\n");
exit(1);
}
$doc = new DOMDocument();
if (!$doc->load($configFile)) {
fwrite(STDERR, "Could not parse $configFile\n");
exit(1);
}
$xpath = new DOMXPath($doc);
$strings = []; // source => [context, key] (first occurrence wins)
$add = function (string $context, string $key, string $source) use (&$strings) {
$source = trim($source);
if ($source === '' || isset($strings[$source])) {
return;
}
$strings[$source] = [$context, $key];
};
// categories
foreach ($xpath->query('//options/*[@category]') as $opt) {
$add('category', '(category name)', (string) $opt->getAttribute('category'));
}
// option titles + optionlabels + dropdown labels
foreach ($xpath->query('//options/*') as $opt) {
$key = $opt->nodeName;
$cat = $opt->getAttribute('category');
$ctx = $cat !== '' ? "option $key ($cat)" : "option $key";
if ($opt->hasAttribute('title')) {
$add($ctx, $key, (string) $opt->getAttribute('title'));
}
if ($opt->hasAttribute('optionlabels') && $opt->hasAttribute('options')) {
$labels = explode('|', (string) $opt->getAttribute('optionlabels'));
foreach ($labels as $label) {
$add("option $key optionlabel", $key, $label);
}
}
foreach ($xpath->query('./dropdownoptions/optgroup', $opt) as $og) {
if ($og->hasAttribute('label')) {
$add("option $key optgroup", $key, (string) $og->getAttribute('label'));
}
foreach ($xpath->query('./option', $og) as $o) {
$add("option $key dropdown option", $key, (string) $o->textContent);
}
}
}
// --- read existing CSV (if any) ---
$langs = ['nl']; // default language column
$rows = []; // source => [context, key, [lang => translation]]
if (is_file($csvFile)) {
$fh = fopen($csvFile, 'r');
$header = fgetcsv($fh);
if ($header === false || count($header) < 3 || $header[0] !== 'context' || $header[1] !== 'key' || $header[2] !== 'source') {
fwrite(STDERR, "Existing $csvFile has an unexpected header (expected context,key,source,...). Fix or remove it.\n");
exit(1);
}
$langs = array_slice($header, 3);
if (empty($langs)) {
$langs = ['nl'];
}
while (($r = fgetcsv($fh)) !== false) {
if (count($r) < 3 || $r[2] === '') {
continue;
}
$trans = [];
foreach ($langs as $i => $lang) {
$trans[$lang] = $r[3 + $i] ?? '';
}
$rows[$r[2]] = [$r[0], $r[1], $trans];
}
fclose($fh);
}
// --- merge: keep translations, append new strings, drop stale ones ---
$order = array_keys($rows); // preserve existing order
$new = 0;
foreach ($strings as $source => [$context, $key]) {
if (!isset($rows[$source])) {
$trans = array_fill_keys($langs, '');
$rows[$source] = [$context, $key, $trans];
$order[] = $source;
$new++;
} else {
// keep context/key up to date with config.xml
$rows[$source][0] = $context;
$rows[$source][1] = $key;
// a language column added later gets an empty cell
foreach ($langs as $lang) {
if (!array_key_exists($lang, $rows[$source][2])) {
$rows[$source][2][$lang] = '';
}
}
}
}
$removed = 0;
foreach (array_keys($rows) as $source) {
if (!isset($strings[$source])) {
unset($rows[$source]);
$order = array_values(array_diff($order, [$source]));
$removed++;
}
}
// --- serialize ---
$out = fopen('php://temp', 'r+');
fputcsv($out, array_merge(['context', 'key', 'source'], $langs));
foreach ($order as $source) {
[$context, $key, $trans] = $rows[$source];
fputcsv($out, array_merge([$context, $key, $source], array_map(fn($l) => $trans[$l] ?? '', $langs)));
}
rewind($out);
$csv = stream_get_contents($out);
fclose($out);
// normalize to LF line endings
$csv = str_replace("\r\n", "\n", $csv);
if ($check) {
$current = is_file($csvFile) ? str_replace("\r\n", "\n", file_get_contents($csvFile)) : '';
if ($current !== $csv) {
fwrite(STDERR, "STALE: $csvFile is not in sync with config.xml — run: php translations/sync_labels.php\n");
fwrite(STDERR, " ($new new string(s), $removed removed string(s), " . count($strings) . " strings total)\n");
exit(1);
}
echo "labels.csv in sync with config.xml (" . count($strings) . " strings, languages: " . implode(', ', $langs) . ")\n";
exit(0);
}
file_put_contents($csvFile, $csv);
$filled = [];
foreach ($langs as $lang) {
$n = 0;
foreach ($rows as $r) {
if (($r[2][$lang] ?? '') !== '') {
$n++;
}
}
$filled[$lang] = $n;
}
echo "Wrote $csvFile: " . count($strings) . " strings, languages: " . implode(', ', $langs) . "\n";
echo " new strings appended (empty translations): $new\n";
echo " strings removed from config.xml: $removed\n";
foreach ($filled as $lang => $n) {
echo " translated [$lang]: $n / " . count($strings) . "\n";
}
echo "Next: edit the translations in a spreadsheet editor (CSV), then generate SQL with:\n";
echo " php translations/csv_to_sql.php " . basename($csvFile) . " nl > nl.sql\n";