How to translate Magento using OmegaT software

Last modified by Jimmy Rittenborg on Wed, June 23, 2010 17:32
Source|Old Revisions  

This is an old revision of the document!


This article explains using OmegaT CAT (Computer Aided Translation) software to translate Magento into your language. Main benefit is re-using existing translations to improve consistency across all translated files.

Note: all steps below were tested on a Linux.

Requirments:

  • OmegaT software (download from http://www.omegat.org)
  • PO source files (explained below)
  • Translation memory made of existing translation (optional, explained below)

Preparation

Create a directory for your translation project and two subdirectories, source/ and target/. Copy Magento en_US csv files to source/. The languages files can be found in app/locale/en_US/ directory of your Magento installation.

OmegaT

This software requires Java. Download version with JRE if you don’t have Java installed alread. Install it.

PO source files

OmegaT cannot work with CSV files directly. They need to be converted to PO files. You can use either Translate Tools - csv2po, but it requires working Python installation (note: the csv needs to have 3 columns, comment,source,target - just open file in spreadsheet editor and duplicate first column), or place the php script below in directory containing source/ and run it.

  1. <?php
  2. /*
  3. Tool to convert source language files to PO files
  4. */
  5.  
  6. $src = 'source';
  7.  
  8. $dir = scandir($src);
  9. for($i=0;$i<count($dir);$i++) {
  10.     if(is_file($src . '/' . $dir[$i])) {
  11.         $src_list = array();
  12.         $f_src = fopen($src . '/' . $dir[$i],"r");
  13.         while($r = fgetcsv($f_src,1000)) {
  14.             $src_list[(string)$r[0]] = $r[1];
  15.         }
  16.         fclose($f_src);
  17.         $f_out = fopen($src . '/' . $dir[$i] . '.po','w');
  18.         reset($src_list);
  19.         while(list($k,$v)=each($src_list)) {
  20.             $k = str_replace('"','"',$k);
  21.             $v = str_replace('"','"',$v);
  22.             $str = "#: $knmsgid "$k"nmsgstr "$v"nn";
  23.             fwrite($f_out,$str);
  24.         }
  25.         fclose($f_out);
  26.     }
  27. }

This will create a .po file corresponding to each .csv file. Those files contain string to be translated. Remove csv files from source/ directory.

Translation memory (optional)

As there are quite a lot of translations already started it is good to reuse existing translations. This means we have to prepare translation memory in TMX format out of already translated csv files. I couldn’t get po2tmx to work so i made a simple script. First concatenate all translated files into one file named all.csv, for example using the command cat *.csv > all.csv. Modify the script to have proper target language, then run it.

  1. <?php
  2. /*
  3. Tool to convert translated csv file to translation memory (TMX)
  4. */
  5.  
  6. $dest_lang = 'PL';
  7. $src = 'all.csv';
  8.  
  9. $src_list = array();
  10. $f_src = fopen($src,"r");
  11. while($r = fgetcsv($f_src,1000)) {
  12.     $src_list[(string)$r[0]] = $r[1];
  13. }
  14. fclose($f_src);
  15. $f_out = fopen('all.tmx','w');
  16. $str = <<<EOT
  17. <?xml version="1.0" encoding="UTF-8"?>
  18. <!DOCTYPE tmx SYSTEM "tmx11.dtd">
  19. <tmx version="1.1">
  20.   <header
  21.     creationtool="OmegaT"
  22.     creationtoolversion="1.7.3_1"
  23.     segtype="sentence"
  24.     o-tmf="OmegaT TMX"
  25.     adminlang="EN-US"
  26.     srclang="EN"
  27.     datatype="plaintext"
  28.   >
  29.   </header>
  30.   <body>
  31. EOT;
  32.  
  33. fwrite($f_out,$str);
  34. reset($src_list);
  35. while(list($k,$v)=each($src_list)) {
  36.     $k = strip_tags($k);
  37.     $v = strip_tags($v);
  38.     $str = <<<EOT
  39.     <tu>
  40.       <tuv lang="EN">
  41.         <seg>$k</seg>
  42.       </tuv>
  43.       <tuv lang="$dest_lang">
  44.         <seg>$v</seg>
  45.       </tuv>
  46.     </tu>
  47. EOT;
  48.  
  49.     fwrite($f_out,$str . "n");
  50. }
  51. $str = "</body>n</tmx>";
  52. fwrite($f_out,$str);
  53. fclose($f_out);

As a result you will get all.tmx file.

Create project

Run OmegaT application. Create a new project, input proper source, project and target directory, add source files (point to source/ directory). Set options: Options→Editing Behaviours to:

  • Source text: yes
  • Insert the best fuzzy match: yes
  • Allow translation to be equal to source: yes

Options→File Filters→PO Files→Edit to:

  • Set input and output encoding to UTF-8 for .po files (very important!)

Save project. Notice a new directory created when saving the project. Copy the all.tmx file to tm/ under project’s directory. Reload the project in OmegaT. If there are any errors reading the tmx file, note line number and fix the tmx file by hand (it is plain XML), errors may include tags or html entities. You can just remove the whole <tu> </tu> block. Reload until there are no translation memory errors. Now you can start translating.

Basic shortcuts are Ctrl+R to replace current segment with most matching translation memory item, Enter to accept current translation.

Back to Magento

When your translation is ready or you want to test it, use File→Create Translated Documents. This will cause translated PO files to appear in target/ directory. Info how to convert PO files back to csv will be added later...

Happy translating!

Questions: PM me piotrekkaminski

Comment

Hi piotrekkaminski Unfortunately some dump ass in here has switched off the personal messaging system at the moment so that we can PAY for support.. damn.. what a loss..

So now i have to edit your tutorial.. (nice isn’t it?)

I can see that you last wrote Thu, April 3, 2008 02:13 which now is quite a wile ago... i would just know how long i have to wait before i can convert a full finished 100% danish translating to CSV again.. it would be soo nice maybe also for others than me :)

-or was it really stupid, of me to trust this half-finished translation method maybe? :)

Regards from Jimmy Rittenborg (-which is totally un-useful at the moment.. tsss)




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs