Exemple #1
0
 /**
  * Setup test
  *
  * @return void
  */
 public function setUp()
 {
     // Backup server array
     $this->_server = $_SERVER;
     // Clean host env
     unset($_SERVER['HTTP_HOST'], $_SERVER['HTTPS'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
     // Set translator
     $translator = new Translator\Translator('arrayAdapter', array('foo' => 'en_foo', 'bar' => 'en_bar'), 'en');
     $translator->addTranslation(array('foo' => 'de_foo', 'bar' => 'de_bar'), 'de');
     $translator->setLocale('en');
     \Zend\Registry::set('Zend_Translate', $translator);
 }
Exemple #2
0
 /**
  * @group ZF-2736
  */
 public function testDoubleReroutingForTranslations()
 {
     $translate = new Translator\Translator(array('adapter' => Translator\Translator::AN_ARRAY, 'content' => __DIR__ . '/Adapter/_files/testarray/', 'locale' => 'auto', 'scan' => Translator\Translator::LOCALE_FILENAME, 'ignore' => array('.', 'ignoreme', 'LC_TEST'), 'route' => array('ja' => 'en_US', 'en_US' => 'ja')));
     $translate2 = new Translator\Translator(array('adapter' => Translator\Translator::AN_CSV, 'content' => __DIR__ . '/Adapter/_files/translation_en.csv', 'locale' => 'en_US'));
     $translate->addTranslation($translate2);
     $langs = $translate->getList();
     $this->assertFalse(array_key_exists('de_DE', $langs));
     $this->assertTrue(array_key_exists('ja', $langs));
     $this->assertTrue(array_key_exists('en_US', $langs));
     $this->assertEquals('Message 5 (en)', $translate->translate('Message 5', 'ja'));
     $this->assertEquals('Message 5 (en)', $translate->translate('Message 5', 'ja'));
 }
Exemple #3
0
 public function testCanTranslateWithOptions()
 {
     $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', "two %1\$s" => "zwei %1\$s", "three %1\$s %2\$s" => "drei %1\$s %2\$s"), 'de');
     $trans->addTranslation(array('one' => 'uno', "two %1\$s" => "duo %2\$s", "three %1\$s %2\$s" => "tre %1\$s %2\$s"), 'it');
     $trans->setLocale('de');
     $this->helper->setTranslator($trans);
     $this->assertEquals("drei 100 200", $this->helper->direct("three %1\$s %2\$s", "100", "200"));
     $this->assertEquals("tre 100 200", $this->helper->direct("three %1\$s %2\$s", "100", "200", 'it'));
     $this->assertEquals("drei 100 200", $this->helper->direct("three %1\$s %2\$s", array("100", "200")));
     $this->assertEquals("tre 100 200", $this->helper->direct("three %1\$s %2\$s", array("100", "200"), 'it'));
 }
    /**
     * @group ZF-10911
     */
    public function testRoutingOnHttpHeader()
    {
        $translate = new Translator\Translator(
            array(
                'adapter'   => Translator\Translator::AN_ARRAY,
                'content'   => __DIR__ . '/Adapter/_files/testarray/',
                'locale'    => 'auto',
                'scan'      => Translator\Translator::LOCALE_FILENAME,
                'ignore'    => array('.', 'ignoreme', 'LC_OTHER'),
                // needed because browser settings can not be simulated in phpunit
                'route'     => array('ja' => 'de_AT', 'de_AT' => 'de_DE', 'de_DE' => 'en_US'),
                'routeHttp' => true,
            )
        );

        $translate2 = new Translator\Translator(
            array(
                'adapter' => Translator\Translator::AN_CSV,
                'content' => __DIR__ . '/Adapter/_files/translation_en.csv',
                'locale'  => 'en_US',
            )
        );

        $translate->addTranslation($translate2);

        $langs = $translate->getList();
        $this->assertFalse(array_key_exists('de_AT', $langs));
        $this->assertTrue(array_key_exists('ja', $langs));
        $this->assertTrue(array_key_exists('en_US', $langs));
        $this->assertEquals('Message 5 (en)', $translate->translate('Message 5', 'ja'));
    }
Exemple #5
0
 /**
  * @group ZF-9489
  */
 public function testAddingAdapterToSourcealsUsingOwnRule()
 {
     $translate = new Translator\Translator(Translator\Translator::AN_ARRAY, array('singular' => array('plural_0 (en)', 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), 'plural' => ''), 'en');
     $this->assertFalse($translate->isTranslated('Message 1'));
     $adapter = new Adapter\Gettext(dirname(__FILE__) . '/Adapter/_files/translation_en.mo', 'en');
     $translate->addTranslation($adapter);
     $this->assertTrue($adapter->isTranslated('Message 1'));
     $adapter2 = new Adapter\Gettext(dirname(__FILE__) . '/Adapter/_files/testmo/de_AT/LC_TEST/translation-de_DE.mo', 'de_AT');
     $adapter2->addTranslation(dirname(__FILE__) . '/Adapter/_files/translation_en2.mo', 'fr');
     $translate->addTranslation($adapter2, 'fr');
     $languages = $translate->getList();
     $this->assertFalse(array_key_exists('de_AT', $languages));
     $this->assertTrue(array_key_exists('fr', $languages));
 }