Bug #2248 [NEW]: Translation2 Missing Language Index
| From: | matthewh at meta-bit dot com | Date: | Mon, 30 Aug 2004 01:05:30 +0000 |
| Subject: | Bug #2248 [NEW]: Translation2 Missing Language Index | ||
| Groups: | php.pear.webmaster | ||
| Request: | Send a blank email to pear-webmaster+get-3037@lists.php.net to get a copy of this message | ||
From: matthewh at meta-bit dot com
Operating system: WinXP
PHP version: 4.3.6
Package: Bug System
Bug Type: Bug
Bug description: Translation2 Missing Language Index
Description:
------------
If you have additional languages registered in the available languages
database table, and the corresponding language doesn't appear within the
'strings_tables' attribute of Translation2 the configuration array, then
calls to Admin::remove will generate an index not found error.
Reproduce code:
---------------
-----This erroneously contains only 3 language codes ------
$I18NPARAMS = array(
'langs_avail_table' => TABLE_PREFIX.'languages',
'lang_id_col' => 'locale',
'lang_name_col' => 'name',
'lang_meta_col' => 'meta',
'lang_errmsg_col' => 'error_text',
'strings_tables' => array(
'en' => TABLE_PREFIX.'translations',
'ja' => TABLE_PREFIX.'translations',
'zh' => TABLE_PREFIX.'translations'
),
'string_id_col' => 'token',
'string_page_id_col' => 'pageID',
'string_text_col' => '%s',
//'prefetch' => false //more queries, smaller result sets
//(use when db load is cheaper than network
load)
);
BUT the database contains columns for additional languages:
mysql> select * from xw_dlmgr_i18n_languages;
+----+--------+------------+------------------+---------------+
| id | locale | name | meta | error_text |
+----+--------+------------+------------------+---------------+
| 1 | en | english | default language | not available |
| 2 | ja | japanese | charset=utf-8 | nai |
| 3 | zh | chinese | charset=utf-8 | nai |
| 4 | ko | Korean | charset=utf-8 | n/a |
| 5 | ms | Malay | charset=utf-8 | n/a |
| 6 | id | Indonesian | charset=utf-8 | n/a |
| 7 | th | Thai | charset=utf-8 | n/a |
+----+--------+------------+------------------+---------------+
7 rows in set (0.00 sec)
Changes are required within PEAR::Translation2/Admin/Container/db.php
-------------------------------------------------------
class Translation2_Admin_Container_db.....
Line 329:
function remove($stringID, $pageID)
{
$langs = $this->getLangs('ids');
$tables = array();
foreach ($langs as $langID) {
// MiH - Suggested change...
// Check to see if table name is defined in
// configuration...
if (isset(
$this->options['strings_tables'][$langID] ))
$tables[ $langID ] =
$this->options['strings_tables'][$langID];
else
$this->_logger->warning('remove(): Misconfigured
language:'.$langID );
}
$tables = array_unique($tables);
Expected result:
----------------
If the Translation2 runtime configuration differs from the Available
Languages database table, then index errors shouldnt be sent to stderr.
Possibly use PEAR::Logging [or PHP error logging] to report a
misconfigured/missing language from the runtime Translation2 config's.
Alternatively, provide a facility within the config's to nominate a
default table for **all languages** for the scenario where strings for
multiple languages are stored within different columns in a single table
[as is the case here]. Hence, lack of nomination of a specific dbase
table could be compensated by, with a fallback to a default_strings_table
parameter (or alike).
Actual result:
--------------
PHP Notice: Undefined index: ko in
c:\products\php\PEAR\Translation2\Admin\Con
tainer\db.php on line 334
PHP Notice: Undefined index: ms in
c:\products\php\PEAR\Translation2\Admin\Con
tainer\db.php on line 334
PHP Notice: Undefined index: id in
c:\products\php\PEAR\Translation2\Admin\Con
tainer\db.php on line 334
PHP Notice: Undefined index: th in
c:\products\php\PEAR\Translation2\Admin\Con
tainer\db.php on line 334
--
Edit bug report at http://pear.php.net/bugs/bug.php?id=2248&edit=1
--