Jump to content

Export translations to csv


Recommended Posts

Hello guys,
 
This is more of a "How to" and "Let's share" thread. I tried installing the Czech language pack recently but there were no front office translations there. Since I have a friend that is fluent in Czech I decided to get things translated with his help. So far so good...
 
The problem was that I did not find a decent export to csv option so I can send him an excel file with the texts and he can do the translation (I would not like to give him access to the admin area).
 
So... Here is how I did it:
 
1. Open <admin-folder>/themes/<admin-theme-name>/template/controllers/translations/helpers/view/translation_form.tpl.
2. Add the following code

<pre>{$tabsArray|@serialize}</pre>

right after

{block name="override_tpl"}

on line 28.
3. Go to admin Localization -> Translations.
4. Choose proper type, theme and language and click Modify.
5. You should see a strange text at the top of the page that starts with something like this

a:67:{s:5:"debug";a:0:{}s:10:"javascript";a:0:{}s:9:"live_edit";a:11:{s:21:"Module position saved";

6. Copy the whole strange text (be really careful with the brackets, if something is missing the export will not work).

7. Save the strange text (a serialized php array actually) into a data.txt file.

8. Create an export.php file next to the saved data.txt with the following content:

<?php

// load translations
$fileContent = file_get_contents('data.txt');
$translations = unserialize($fileContent);

// format data
$texts = array();
foreach ($translations as $key => $translation) {
    if (0 === count($translation)) {
        continue;
    }
    
    // add translation group
    $texts[] = array($key);
    
    // add translations
    foreach ($translation as $en => $template) {
        $texts[] = array($en, $template['trad']);
    }
}

// save csv output
$output = fopen('output.csv', 'w');
foreach ($texts as $text) {
    fputcsv($output, $text);
}
fclose($output);

9. You need PHP installed (Google it if you don't have it).

10. Navigate to the folder / path where you've saved your files in your terminal / console and run the following command:

php export.php

11. Voala - you should now have an output.csv file that you can put in excel or use for whatever purposes you want...

 

I hope this helps :)

Link to comment
Share on other sites

  • 2 months later...

Could you build a module out of it? Exporting and Importing.

I'd be interested for 3 sites.

Even better if it can handle product data too.

 

There are people who want their store professionally translated not by google ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...