4

It is beautifully described in the docs how to translate static text using translation files.

As the client has no access to that file and managing a php array is not what I want them to do, I am looking for a way to make edits to the translation file feasible directly in the Control Panel.

This would allow me to set things up in the template and then hand off the actual translation work to someone else.

Yes, you probably have to write a plugin for that. But can you edit the files from a plugin? Is there any API or service available that might help?

2 Answers 2

5

I'm pretty new to Craft but I'll tell you what I'd try anyway for fun.

I'd create a "Translations" assets source that would hold files like es.csv.

Then, in craft/translations/es.php, I'd run through that CSV and build the array Craft wants and return it.

<?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;

This is totally untested.

8
  • Wow Bill, this is what I'd call a creative answer! :) Thanks. Will definitely try that (so you don't have to, hehe). A csv is without a doubt better then a php-array, but actually I was hoping for some nice html form or sth. Thanks again!
    – carlcs
    Jun 15, 2014 at 2:52
  • No problem! Hopefully it can help you get to a solution you want. Jun 15, 2014 at 3:10
  • That's a very clever solution! I'm curious to hear if this works... Please let us know @ChristianSeelbach!
    – Lindsey D
    Jun 15, 2014 at 3:14
  • Just tested this and it works like a charm, Bill & @Lindsey!
    – carlcs
    Aug 6, 2014 at 8:43
  • 1
    Very nice side effect of this technique is, that you can now manage all your translations in one csv file. Made some edits to the code to make this more easy. Hope you didn't mind, Bill!
    – carlcs
    Aug 6, 2014 at 9:40
0

I assume this is for a language that the CP hasn't been translated into, yet?

If so, maybe the better solution here is to help us get the CP translated into that language at which point we'll officially start supporting it in future releases. We're currently managing our translations on PhraseApp (http://phraseapp.com) and gladly accept contributions.

5
  • Ouups Brad, didn't talk about stings of the CP but static stings in the template being translated with |translate filter. Added a link to make this clearer. Sometimes having trouble to articulate what I want in english O.o !
    – carlcs
    Jun 15, 2014 at 2:35
  • Ahh... no worries. I can guarantee you that your English is far superior my attempt at your native language.
    – Brad Bell
    Jun 15, 2014 at 2:38
  • lol you speak german?
    – carlcs
    Jun 15, 2014 at 2:41
  • 2
    Ich bin ein Berliner!
    – Brad Bell
    Jun 15, 2014 at 2:48
  • definitely a bun -- though I had a quite educated man assure me that what John Kennedy said was 'perfectly fine'. For the spirit of it, unquestionably. We forget too easily, under our own propaganda -- of certain parties. Jun 15, 2014 at 3:26

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.