History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-2205
Type: Bug Bug
Status: Resolved Resolved
Resolution: Not an Issue
Priority: Major Major
Assignee: Thomas Weidner
Reporter: Xing Xing
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Can't load the language file correctly

Created: 14/Nov/07 07:58 PM   Updated: 21/Nov/07 07:06 AM
Component/s: Zend_Translate
Affects Version/s: 1.0.2
Fix Version/s: 1.0.3

Time Tracking:
Not Specified

Tags:
Participants: Thomas Weidner and Xing Xing


 Description  « Hide
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!



 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Thomas Weidner - 15/Nov/07 03:14 AM
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?


Thomas Weidner - 21/Nov/07 07:06 AM
Closing issue as there is no feedback.

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