Ejemplo n.º 1
0
 public function testLoadEmptyTranslation()
 {
     $loader = new PoFileLoader();
     $resource = __DIR__ . '/../fixtures/empty-translation.po';
     $catalogue = $loader->load($resource, 'en', 'domain1');
     $this->assertEquals(array('foo' => ''), $catalogue->all('domain1'));
     $this->assertEquals('en', $catalogue->getLocale());
     $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
 }
 public function testExtractNoTranslations()
 {
     $extractor = new Extractor($this->twig);
     $extractor->addTemplate(__DIR__ . '/Fixtures/twig/empty.twig');
     $extractor->setGettextParameters($this->getGettextParameters());
     $extractor->extract();
     $catalog = $this->loader->load($this->getPotFile(), null);
     $this->assertEmpty($catalog->all('messages'));
 }
Ejemplo n.º 3
0
 public function testLoadDoesNothingIfEmpty()
 {
     $loader = new PoFileLoader();
     $resource = __DIR__ . '/../fixtures/empty.po';
     $catalogue = $loader->load($resource, 'en', 'domain1');
     $this->assertEquals(array(), $catalogue->all('domain1'));
     $this->assertEquals('en', $catalogue->getLocale());
     $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
 }
Ejemplo n.º 4
0
 public function testSkipFuzzyTranslations()
 {
     $loader = new PoFileLoader();
     $resource = __DIR__ . '/../fixtures/fuzzy-translations.po';
     $catalogue = $loader->load($resource, 'en', 'domain1');
     $messages = $catalogue->all('domain1');
     $this->assertArrayHasKey('foo1', $messages);
     $this->assertArrayNotHasKey('foo2', $messages);
     $this->assertArrayHasKey('foo3', $messages);
 }
 public function testEscapedIdPlurals()
 {
     $loader = new PoFileLoader();
     $resource = __DIR__ . '/../fixtures/escaped-id-plurals.po';
     $catalogue = $loader->load($resource, 'en', 'domain1');
     $messages = $catalogue->all('domain1');
     $this->assertArrayHasKey('escaped "foo"', $messages);
     $this->assertArrayHasKey('escaped "foos"', $messages);
     $this->assertEquals('escaped "bar"', $messages['escaped "foo"']);
     $this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']);
 }
 private function __construct($lang)
 {
     if ($lang == '') {
         throw new \BadMethodCallException('Language is missing');
     }
     $translations_path = realpath(__DIR__ . '/../../../translations');
     $dir_iterator = new \RecursiveDirectoryIterator($translations_path);
     $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $file) {
         if (basename($file, '.po') == $lang) {
             $loader = new PoFileLoader();
             $loader->load(realpath($file), $lang);
             $this->translator = new Translator($lang);
             $this->translator->addLoader('pofile', $loader);
             $this->translator->addResource('pofile', realpath($file), $lang);
         }
     }
     if (is_null($this->translator)) {
         throw new \BadMethodCallException('No translation file for this language available.');
     }
 }
Ejemplo n.º 7
0
/**
 * Read and parse locale file.
 *
 * @param string $path Locale file path
 * @return array Associative array with following keys:
 *  - 'messages': associative array of localized strings. The keys of the array
 *    are localization keys and the values of the array are localized strings.
 *    All localized strings are encoded in UTF-8.
 */
function read_locale_file($path)
{
    $loader = new PoFileLoader();
    // At this point locale name (the second argument of the "load" method) has
    // no sense, so an empty string is passed in.
    $messages = $loader->load($path, '');
    return array('messages' => $messages->all('messages'));
}