Home » Internationalization » Translation2 » Bug #4002
fallbackLang does not work with gettext container
Details
| Submitted | 2005-03-30 13:34 UTC |
|---|---|
| From | pear at colin dot guthri dot ie |
| Assigned | mike |
| Status | Closed |
| Package | Translation2 |
| PHP Version | 4.3.10 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-03-30 13:34 UTC] pear at colin dot guthri dot ie
Description:
------------
I am using the Translation2 2.0.0beta6 beta module.
It would appear that I cannot use the fallbackLang decorator (and presumably other empty($str) dependant decorators like ErrorText) as the Gettext container replaces empty strings with their key name to replicate standard get text behaviour. I actually do not want this behaviour at all, so ideally a config option to disable it would be ideal.
I've put together a quick patch that solves the proplem for me which I would love to see in the next beta.
Thanks.
## Start ##
--- Translation2/Container/gettext.php.orig 2005-03-30 14:24:23.000000000 +0100
+++ Translation2/Container/gettext.php 2005-03-30 14:28:51.000000000 +0100
@@ -120,6 +120,7 @@ class Translation2_Container_gettext ext
$this->options['file_type'] = 'mo';
$this->options['default_lang'] = 'en';
$this->options['default_encoding'] = 'iso-8859-1';
+ $this->options['blank_on_missing'] = false;
}
// }}}
@@ -262,10 +263,12 @@ class Translation2_Container_gettext ext
$page = $this->getPage($pageID, $langID);
// return original string if there's no translation available
- if (isset($page[$stringID]) && strlen($page[$stringID])) {
+ if (!empty($page[$stringID])) {
return $page[$stringID];
- } else {
+ } else if (false == $this->options['blank_on_missing']) {
return $stringID;
+ } else {
+ return '';
}
}
## End ##
Reproduce code:
---------------
Use a gettext container and try and setup fallbackLang
Expected result:
----------------
It should fallback properly.
Actual result:
--------------
If the most preferred language does not have a translation, the key is returned and no fall back is attempted.
[2005-03-30 14:08 UTC] pear at colin dot guthr dot ie
I've realised that this will only work with .po and File_Gettext.... bumdeal.
Perhaps I'll have to use something else...
[2005-03-30 14:33 UTC] pear at colin dot guthr dot ie
OK, I've put in a few more changes and here is a new patch. If you specify the option that you want empty strings rather than keys it forces non-native mode.
Also getPage has bugs in which it fails to restore the current Language when the domain is cached or on error.
Here is a full patch.
Appologies for wrapped lines but I can't seem to attach a patch with this version of this bug tracker thing (I'm used to bugzilla personally).
## START ##
--- Translation2/Container/gettext.php.orig 2005-03-30 14:24:23.000000000 +0100
+++ Translation2/Container/gettext.php 2005-03-30 15:30:38.000000000 +0100
@@ -79,7 +79,8 @@ class Translation2_Container_gettext ext
$this->_parseOptions($options);
$this->_native = (
function_exists('gettext') &&
- ($this->options['file_type'] != 'po')
+ ($this->options['file_type'] != 'po') &&
+ ($this->options['blank_on_missing'] == false)
);
$this->_domains = @parse_ini_file($this->options['domains_path_file']);
@@ -120,6 +121,7 @@ class Translation2_Container_gettext ext
$this->options['file_type'] = 'mo';
$this->options['default_lang'] = 'en';
$this->options['default_encoding'] = 'iso-8859-1';
+ $this->options['blank_on_missing'] = false;
}
// }}}
@@ -190,10 +192,12 @@ class Translation2_Container_gettext ext
}
if (isset($this->cachedDomains[$curLang][$pageID])) {
+ $this->_switchLang($oldLang);
return $this->cachedDomains[$curLang][$pageID];
}
if (!isset($this->_domains[$pageID])) {
+ $this->_switchLang($oldLang);
return $this->raiseError(sprintf(
'The domain "%s" was not specified in the domains INI '.
'file "%s" [%s on line %d]', $pageID,
@@ -211,12 +215,14 @@ class Translation2_Container_gettext ext
if (PEAR::isError($e = $gtFile->load($file))) {
if (is_file($file)) {
+ $this->_switchLang($oldLang);
return $this->raiseError(sprintf(
'%s [%s on line %d]', $e->getMessage(), __FILE__, __LINE__
),
TRANSLATION2_ERROR
);
}
+ $this->_switchLang($oldLang);
return $this->raiseError(sprintf(
'Cannot find file "%s" [%s on line %d]',
$file, __FILE__, __LINE__
@@ -262,10 +268,12 @@ class Translation2_Container_gettext ext
$page = $this->getPage($pageID, $langID);
// return original string if there's no translation available
- if (isset($page[$stringID]) && strlen($page[$stringID])) {
+ if (!empty($page[$stringID])) {
return $page[$stringID];
- } else {
+ } else if (false == $this->options['blank_on_missing']) {
return $stringID;
+ } else {
+ return '';
}
}
## END ##