5

I've been using Pootle recently for translating a small PHP project. Our i18n files are as php arrays, example:

return array(
    'word.in' => 'en',
    'word.yes' => 'Sí',
    'word.no' => 'No',
    'word.with' => 'con',
);

So I created a Project in Pootle's admin panel and set the source files are PHP arrays. I can upload and translate files perfectly fine afterwards.

The problem comes when I try to export, the file rendered has the following syntax:

return array->'word.in'='for';
return array->'word.yes'='Yes';
return array->'word.no'='No';
return array->'word.with'='with';

Which afaik isn't even valid PHP syntax.

I've read through the Pootle and Translation Toolkit's documentations and I've found that it passes through some sort of 'template' to generate that crappy output.

Any ideas how I can fix this and be able to export my PHP array with exactly the same syntax I uploaded it? Any help greatly appreciated!

Rikesh
  • 26,156
  • 14
  • 79
  • 87
Pesho P.
  • 51
  • 1
  • There were quite a lot of bugs in PHP handling in earlier translate-toolkit versions, so ensure you are using latest one. – Michal Čihař Mar 28 '14 at 10:41
  • I'm using latest Pootle 2.5.1, with Translate Toolkit 1.11.0. Maybe I skipped something from their docs on how I want php files to be exported? – Pesho P. Mar 28 '14 at 14:22
  • I don't know much about Pootle's support for PHP files, sorry. But good that you are using latest Translate Toolkit, the older versions were really broken in regard to PHP files. – Michal Čihař Mar 31 '14 at 07:25

1 Answers1

0

Any ideas how I can fix this and be able to export my PHP array with exactly the same syntax I uploaded it?

Before return statement, if You need to actually write that array to file and read it later again, I would do something like this ..

$arrayExport = var_export(
array(
    'word.in' => 'en',
    'word.yes' => 'Sí',
    'word.no' => 'No',
    'word.with' => 'con',
), true);

Than write down $arrayExport .. for example:

file_put_contents($filePathName, 
'<?php $exportedArrayName = '.$arrayExport.";\n ?>", 
LOCK_EX);

...than goes the rest of weird Pootle and translation ...

But if You need to read it again after a while without storing it, use $_SESSIONS and serialization.

$_SESSION['exportedArray'] = serialize(array(
        'word.in' => 'en',
        'word.yes' => 'Sí',
        'word.no' => 'No',
        'word.with' => 'con',
    ));

To read from session ..

$exportedArray = unserialize($_SESSION['exportedArray']);
Spooky
  • 1,235
  • 15
  • 17