2

I've set up multiple translation files (de.php, fr.php, es.php etc.) in craft/translations/ to translate static text.

While my site is in development, I am trying to keep these lang.php files in sync, so that they all contain at least the strings of the primary locale as array keys.

But the more strings are added or changed, the more annoying this undertaking gets. Any idea on how I could make this more simple and efficient?

4

You could manage all your translations in one csv file. There's another Q/A about translation files, where @Bill Criswell explains how you can use csv files for translations. I added some variables to his script to make it well adaptable to multiple locales.

Set up your new csv file with a column for each locale. Then add the script to each of your lang.php files and configure $this_locale_column according to the file's locale.

<?php

$path = $_SERVER['DOCUMENT_ROOT'].'/../craft/translations/translations.csv';
$delimiter = ';';
$skip_rows = 1; //skip header rows
$primary_locale_column = 0; //set primary locale column
$this_locale_column = 1; //set secondary locale column for this `lang.php` file

$translations = array();
$translations_file = fopen($path, 'r');

if ($translations_file) {
    while(($translation = fgetcsv($translations_file, 1024, $delimiter)) !== FALSE) {
        if($skip_rows != 0) { $skip_rows--; continue; }
        $translations[$translation[$primary_locale_column]] = $translation[$this_locale_column];
    }
}

return $translations;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.