Zend Framework

Can't load the language file correctly

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.0.2
  • Fix Version/s: 1.0.3
  • Component/s: Zend_Translate
  • Labels:
    None

Description

My codes is:

public function testGetTextTw()

{ $t = new Zend_Translate('gettext', './_locale/', 'zh_TW'); $this->assertEquals('n2', $t->_('New')); }

public function testGetTextCn()

{ $t = new Zend_Translate('gettext', './_locale/', 'zh_CN'); $this->assertEquals('n1', $t->_('New')); }

But, the testGetTextCn() go into fail: expected string 'n1' but got string 'n2'.

So, I read the codes in Zend_Translate_Adapter::__construct().
the param variable $local was covered by an other value.

I made this patch:

Index: Adapter.php

===================================================================

— Adapter.php (revision 6821)

+++ Adapter.php (working copy)

@@ -59,7 +59,7 @@

*/
protected $_options = array(
'clear' => false, // clear previous loaded translation data

  • 'scan' => null // where to find the locale
    + 'scan' => self::LOCALE_DIRECTORY, // where to find the locale
    );

/**
@@ -79,14 +79,14 @@

  • @param string|array $options Options for the adaptor
  • @throws Zend_Translate_Exception
    */
  • public function __construct($data, $locale = null, array $options = array())
    + public function __construct($data, $defaultLocale = null, array $options = array())
    {
  • if ($locale === null) {
  • $locale = new Zend_Locale();
    + if ($defaultLocale === null) { + $defaultLocale = new Zend_Locale(); }
  • if ($locale instanceof Zend_Locale) { - $locale = $locale->toString(); - }
    + if ($defaultLocale instanceof Zend_Locale) { + $defaultLocale = $defaultLocale->toString(); + }

$options = array_merge($this->_options, $options);
if (is_string($data) and is_dir($data)) {
@@ -96,7 +96,7 @@

if ($info->isDir()) {

$directory = $info->getPath();

  • // pathname as locale
    + // pathname as localeself::LOCALE_DIRECTORY
    if (($options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale((string) $info))) { $locale = (string) $info; }
    @@ -126,8 +126,8 @@

}
try {
$this->addTranslation((string) $info->getPathname(), $locale, $options);

  • if ((array_key_exists($locale, $this->_translate)) and (count($this->_translate[$locale]) > 0)) {
  • $this->setLocale($locale);
    + if ((array_key_exists($defaultLocale, $this->_translate)) and (count($this->_translate[$defaultLocale]) > 0)) { + $this->setLocale($defaultLocale); }
    } catch (Zend_Translate_Exception $e) { // ignore failed sources while scanning @@ -135,9 +135,9 @@ }
    }
    } else {
  • $this->addTranslation($data, $locale, $options);
  • if ((array_key_exists($locale, $this->_translate)) and (count($this->_translate[$locale]) > 0)) {
  • $this->setLocale($locale);
    + $this->addTranslation($data, $defaultLocale, $options);
    + if ((array_key_exists($defaultLocale, $this->_translate)) and (count($this->_translate[$defaultLocale]) > 0)) { + $this->setLocale($defaultLocale); }
    }
    $this->_automatic = true;

Now, it works fine!

Activity

Hide
Thomas Weidner added a comment -

Not able to reproduce the problem...

False initialisation and no translation file for verification given.
The given patch also introduces several other problems with tmx, xliff, array and others. Therefor we will not integrate it.

If you give all data we will look into the problem.

We need your default locale, the gettext files, the directory structure, the svn version, the OS, and 32/64bit?

Show
Thomas Weidner added a comment - Not able to reproduce the problem... False initialisation and no translation file for verification given. The given patch also introduces several other problems with tmx, xliff, array and others. Therefor we will not integrate it. If you give all data we will look into the problem. We need your default locale, the gettext files, the directory structure, the svn version, the OS, and 32/64bit?
Hide
Thomas Weidner added a comment -

Closing issue as there is no feedback.

The user just have to give the wished option instead of changing the class.

Show
Thomas Weidner added a comment - Closing issue as there is no feedback. The user just have to give the wished option instead of changing the class.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: