Example #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'));
    }
    function testTranslateSubstituteParametersDefaultContext()
    {
        $toolkit = lmbToolkit::save();
        $back = new lmbQtDictionaryBackend();
        $back->setSearchPath($translations_dir = LIMB_VAR_DIR . '/translations');
        $toolkit->setDictionaryBackend($back);
        $xml = <<<EOD
<?xml version="1.0"?>
<!DOCTYPE TS><TS>
<context>
<message>
    <source>Hello {name}</source>
    <translation>Привет {name}</translation>
</message>
</context>
</TS>
EOD;
        file_put_contents($translations_dir . '/default.ru_RU.ts', $xml);
        $toolkit->setLocale('ru_RU');
        $this->assertEqual(lmb_i18n('Hello {name}', array('{name}' => 'Bob')), 'Привет Bob');
        lmbToolkit::restore();
    }
 function testUnfinishedTranslations()
 {
     $d = new lmbI18NDictionary();
     $back = new lmbQtDictionaryBackend();
     $d->add('Foo');
     $d->add('Bar', 'Бар');
     $dom = $back->getDOMDocument($d);
     $translations = $dom->getElementsByTagName('translation');
     $this->assertEqual($translations->item(0)->getAttribute('type'), 'unfinished');
     $this->assertFalse($translations->item(1)->hasAttribute('type'));
 }