Pootle exports invalid PHP array files

I recently used Pootle to translate a small PHP project. Our i18n files are php arrays, for example:

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

So, I created a project in the Pootle admin panel and installed the source files in PHP arrays. After that I can upload and translate files.

The problem occurs when I try to export , the rendered file 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 afaic is not a valid PHP syntax.

I read the Pootle documentation and the Translation Toolkit, and I found that it goes through some kind of “template” to create this crappy output.

, PHP- , ? !

+4
1

, PHP- , ?

return, , - .

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

$arrayExport.. :

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

... Pootle ...

, , $_SESSIONS .

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

..

$exportedArray = unserialize($_SESSION['exportedArray']);
0

Source: https://habr.com/ru/post/1533508/


All Articles