diff --git a/README.md b/README.md index 93ad308..983d03b 100644 --- a/README.md +++ b/README.md @@ -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,`, 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 -p < 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) diff --git a/translations/csv_to_sql.php b/translations/csv_to_sql.php new file mode 100644 index 0000000..5bd2399 --- /dev/null +++ b/translations/csv_to_sql.php @@ -0,0 +1,75 @@ + > 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 -p < 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 \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,\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"; diff --git a/translations/labels.csv b/translations/labels.csv new file mode 100644 index 0000000..fb71cba --- /dev/null +++ b/translations/labels.csv @@ -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", diff --git a/translations/sync_labels.php b/translations/sync_labels.php new file mode 100644 index 0000000..da6cbd8 --- /dev/null +++ b/translations/sync_labels.php @@ -0,0 +1,194 @@ +/ title="..." (context "option ") + * - every distinct category="..." name (context "category") + * - every optionlabels="A|B|..." entry (context "option optionlabel") + * - every dropdown (context "option optgroup") + * - every dropdown