Esempio n. 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);
 }
Esempio n. 2
0
 /**
  * @group ZF-5568
  */
 public function testOptGroupTranslationsShouldWorkAfterPopulatingElement()
 {
     $translations = array('ThisIsTheLabel' => 'Optgroup label', 'ThisShouldNotShow' => 'Foo Value', 'ThisShouldNeverShow' => 'Bar Value');
     $translate = new Translator('ArrayAdapter', $translations, 'en');
     $translate->setLocale('en');
     $options = array('ThisIsTheLabel' => array('foovalue' => 'ThisShouldNotShow', 'barvalue' => 'ThisShouldNeverShow'));
     $this->element->setTranslator($translate)->addMultiOptions($options);
     $this->element->setValue('barValue');
     $html = $this->element->render($this->getView());
     $this->assertContains($translations['ThisIsTheLabel'], $html, $html);
 }
Esempio n. 3
0
 public function testErrorMessagesFromProcessAjaxAreLocalizedWhenTranslateAdapterPresent()
 {
     $translations = (include __DIR__ . '/TestAsset/locale/array.php');
     $translate = new Translator('ArrayAdapter', $translations, 'en');
     $translate->setLocale('en');
     $this->form->addElements(array('foo' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('NotEmpty'))), 'bar' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('Digits')))))->setTranslator($translate);
     $data = array('foo' => '');
     $return = $this->form->processAjax($data);
     $messages = Json::decode($return, Json::TYPE_ARRAY);
     $this->assertTrue(is_array($messages));
     $this->assertTrue(isset($messages['foo']));
     $this->assertFalse(isset($messages['bar']));
     foreach ($messages['foo'] as $key => $message) {
         if (array_key_exists($key, $translations)) {
             $this->assertEquals($translations[$key], $message);
         } else {
             $this->fail('Translation for ' . $key . ' does not exist?');
         }
     }
 }
Esempio n. 4
0
    public function testRetrievingLabelRetrievesLabelWithTranslationAndPrefixAndSuffix()
    {
        $translate = new Translator('ArrayAdapter', array('My Label' => 'Translation'), 'en');
        $translate->setLocale('en');

        $element = new Element('foo');
        $element->setView($this->getView())
                ->setLabel('My Label')
                ->setTranslator($translate);
        $this->decorator->setElement($element)
                        ->setOptions(array(
                            'optionalPrefix' => '> ',
                            'optionalSuffix' => ':',
                            'requiredPrefix' => '! ',
                            'requiredSuffix' => '*:',
                        ));
        $label = $this->decorator->getLabel();
        $this->assertEquals('> Translation:', $label);

        $element->setRequired(true);
        $label = $this->decorator->getLabel();
        $this->assertEquals('! Translation*:', $label);
    }
Esempio n. 5
0
 /**
  * Tests getting plurals from lowered locale
  */
 public function testGettingPluralsUsingOwnRule()
 {
     $lang = new Translator\Translator(Translator\Translator::AN_ARRAY, array('singular' => array('plural_0 (en)', 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), 'plural' => ''), 'en');
     $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'en_US');
     $lang->setLocale('en_US');
     Translator\Plural::setPlural(array($this, 'customPlural'), 'en_US');
     $this->assertEquals('plural_1 (en)', $lang->translate(array('singular', 'plural', 1)));
     $this->assertEquals('plural_1 (en)', $lang->plural('singular', 'plural', 1));
     $this->assertEquals('plural_1 (en)', $lang->translate(array('singular', 'plural', 0)));
     $this->assertEquals('plural_1 (en)', $lang->plural('singular', 'plural', 0));
 }
Esempio n. 6
0
 /** ZF-2568 */
 public function testTranslatedMessagesCanContainVariableSubstitution()
 {
     $localeFile = __DIR__ . '/TestAsset/locale/array.php';
     $translations = (include $localeFile);
     $translations['notDigits'] .= ' "%value%"';
     $translator = new Translator('ArrayAdapter', $translations, 'en');
     $translator->setLocale('en');
     $this->element->setAllowEmpty(false)->setTranslator($translator)->addValidator('digits');
     $this->element->isValid('abc');
     $messages = $this->element->getMessages();
     $found = false;
     foreach ($messages as $key => $message) {
         if ($key == 'notDigits') {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'String Empty message not found: ' . var_export($messages, 1));
     $this->assertContains(' "abc"', $message);
     $this->assertContains('Translating the notDigits string', $message);
 }
Esempio n. 7
0
 /**
  * ZF-6724
  */
 public function testTranslationWithPercent()
 {
     $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', "two %1\$s" => "zwei %1\$s", "three %1\$s %2\$s" => "drei %1\$s %2\$s", 'vier%ig' => 'four%'), 'de');
     $trans->setLocale('de');
     $this->helper->setTranslator($trans);
     $this->assertEquals("four%", $this->helper->direct("vier%ig"));
     $this->assertEquals("zwei 100", $this->helper->direct("two %1\$s", "100"));
 }
Esempio n. 8
0
 /**
  * @ZF-10051
  */
 public function testSettingLogPriorityForLog()
 {
     $stream = fopen('php://memory', 'w+');
     $writer = new Writer\Stream($stream);
     $log = new Log\Logger($writer);
     $lang = new Translator\Translator(array('adapter' => Translator\Translator::AN_CSV, 'content' => __DIR__ . '/../_files', 'locale' => 'en', 'delimiter' => ',', 'logPriority' => 3, 'log' => $log));
     $lang->setLocale('ru');
     rewind($stream);
     $this->assertContains('ERR (3)', stream_get_contents($stream));
     $lang->setOptions(array('logPriority' => 1));
     $lang->setLocale('sv');
     rewind($stream);
     $this->assertContains('ALERT (1)', stream_get_contents($stream));
 }
Esempio n. 9
0
 public function testMultiOptionsPassedToViewHelperAreTranslated()
 {
     $element = new SelectElement('foo');
     $options = array('foo' => 'This Foo Will Not Be Displayed', 'bar' => 'This Bar Will Not Be Displayed', 'baz' => 'This Baz Will Not Be Displayed');
     $element->setMultiOptions($options);
     $translations = array('This Foo Will Not Be Displayed' => 'This is the Foo Value', 'This Bar Will Not Be Displayed' => 'This is the Bar Value', 'This Baz Will Not Be Displayed' => 'This is the Baz Value');
     $translate = new Translator('ArrayAdapter', $translations, 'en');
     $translate->setLocale('en');
     $element->setTranslator($translate);
     $test = $element->render($this->getView());
     foreach ($options as $key => $value) {
         $this->assertNotContains($value, $test);
         $this->assertContains($translations[$value], $test);
     }
 }