简体   繁体   中英

Pootle exports incorrect PHP array files

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!

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']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM