コード例 #1
0
    function testLoadFromFile()
    {
        $back = new lmbQtDictionaryBackend();
        $xml = <<<EOD
<?xml version="1.0"?>
<!DOCTYPE TS><TS>
<context>
<message>
    <source>Hello</source>
    <translation>Привет</translation>
</message>
<message>
    <source>Hi</source>
    <translation>Привет</translation>
</message>
<message>
    <source>Dog</source>
    <translation>Собака</translation>
</message>
</context>
</TS>
EOD;
        file_put_contents($file = LIMB_VAR_DIR . '/dictionary.xml', $xml);
        $d = $back->loadFromFile($file);
        $this->assertEqual($d->translate('Hello'), 'Привет');
        $this->assertEqual($d->translate('Hi'), 'Привет');
        $this->assertEqual($d->translate('Dog'), 'Собака');
    }
コード例 #2
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'));
    }