Пример #1
0
 function updateTranslations($argv)
 {
     $input = new lmbCliInput('t|test');
     $input->read($argv, false);
     $dry_run = $input->isOptionPresent('t');
     $input_dir = realpath($input->getArgument(0, '.'));
     if (!$input_dir) {
         $this->_error('Input directory is not valid');
     }
     $output_dir = realpath($input->getArgument(1, $input_dir . '/i18n/translations'));
     if (!$output_dir) {
         $this->_error('Output directory is not valid');
     }
     $qt = new lmbQtDictionaryBackend();
     $qt->setSearchPath($output_dir);
     $util = new lmbDictionaryUpdater($qt, $this->output);
     if ($dry_run) {
         $util->dryrun($input_dir);
     } else {
         $util->updateTranslations($input_dir);
     }
     return 0;
 }
    function testUpdateTranslationsForDefaultContext()
    {
        $translations_dir = LIMB_VAR_DIR . '/translations';
        $ru_file = $translations_dir . '/default.ru_RU.ts';
        $de_file = $translations_dir . '/default.de_DE.ts';
        $source_dir = LIMB_VAR_DIR . '/src/';
        $html_file = $source_dir . '/hourse.html';
        $php_file = $source_dir . '/cat.php';
        $xml = <<<EOD
<?xml version="1.0"?>
<!DOCTYPE TS><TS>
<context>
<message>
    <source>Dog</source>
    <translation>Dog</translation>
</message>
</context>
</TS>
EOD;
        file_put_contents($ru_file, $xml);
        file_put_contents($de_file, $xml);
        $php = <<<EOD
<?php
lmb_i18n('Cat');
?>
EOD;
        file_put_contents($php_file, $php);
        $html = <<<EOD
{\$'Horse'|i18n}
EOD;
        file_put_contents($html_file, $html);
        $cli_responce = new MockCliResponse();
        $backend = new lmbQtDictionaryBackend();
        $backend->setSearchPath($translations_dir);
        $updater = new lmbDictionaryUpdater($backend, $cli_responce);
        $updater->updateTranslations($source_dir);
        $ru_dictionary = $backend->loadFromFile($ru_file);
        $this->assertTrue($ru_dictionary->has('Horse'));
        $this->assertTrue($ru_dictionary->has('Cat'));
        $this->assertTrue($ru_dictionary->has('Dog'));
        $de_dictionary = $backend->loadFromFile($de_file);
        $this->assertTrue($de_dictionary->has('Horse'));
        $this->assertTrue($de_dictionary->has('Cat'));
        $this->assertTrue($de_dictionary->has('Dog'));
    }