_langDir = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'languages'; if (!is_readable($this->_langDir)) { throw new Exception('Language resource directory "'.$this->_langDir.'" not readable.'); } // detect languages foreach (new DirectoryIterator($this->_langDir) as $entry) { if (!$entry->isDir()) { continue; } // skip "." or ".." or ".svn" $fname = $entry->getFilename(); if ($fname[0] == '.') { continue; } // add all languages for testIsLocale $this->_languages[] = $fname; // include Zend_Validate translation tables $translationFile = $entry->getPathname() . DIRECTORY_SEPARATOR . 'Zend_Validate.php'; if (file_exists($translationFile)) { $translation = include $translationFile; if (!is_array($translation)) { $this->fail("Invalid or empty translation table found for language '{$fname}'"); } $this->_translations[$fname] = $translation; } } } public function testIsLocale() { foreach ($this->_languages as $lang) { if (!Zend_Locale::isLocale($lang, true, false)) { $this->fail("Language directory '{$lang}' not a valid locale"); } } } public function testEnglishKeySameAsValue() { foreach ($this->_translations['en'] as $k => $v) { $this->assertEquals($k, $v); } } public function testTranslationAvailableInEnglish() { foreach ($this->_translations as $lang => $translation) { if ($lang == 'en') { continue; } foreach ($translation as $k => $v) { $this->assertTrue( isset($this->_translations['en'][$k]), $lang . ': The key "' . $k . '" isn\'t available within english translation file' ); } } } public function testTranslationDiffersFromEnglish() { foreach ($this->_translations as $lang => $translation) { if ($lang == 'en') { continue; } foreach ($translation as $k => $v) { $this->assertTrue( ($k != $v), $lang . ': The translated message "' . $v . '" is the same the english version' ); } } } public function testPlaceholder() { foreach ($this->_translations as $lang => $translation) { if ($lang == 'en') { // not needed to test - see testEnglishKeySameAsValue continue; } foreach ($translation as $k => $v) { if (preg_match_all('/(\%.+\%)/U', $k, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $this->assertContains($match[1], $v, $lang . ': Missing placeholder "' . $match[1] . '" within "' . $v . '"'); } } } } } public function testAllTranslated() { foreach ($this->_translations['en'] as $enK => $enV) { foreach ($this->_translations as $lang => $translation) { if ($lang == 'en') { continue; } $this->assertTrue(isset($translation[$enK]), $lang . ': Message "' . $enK . '" not translated'); } } } }