|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63945 Fallback not used when calling ResourceBundle::get() on a nested table
Submitted: 2013-01-08 19:31 UTC Modified: 2021-11-11 11:16 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: nrawlings at imiassociates dot com Assigned:
Status: Open Package: I18N and L10N related
PHP Version: 5.4.10 OS: Mac OS X
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: nrawlings at imiassociates dot com
New email:
PHP Version: OS:


 [2013-01-08 19:31 UTC] nrawlings at imiassociates dot com
Locale inheritance is not used when calling ResourceBundle::get() to access a 
in a table that is nested under the bundle's root table.

For example, suppose that the keys "username" and "password" are both defined in 
the "loginForm" table of the root bundle, but the "loginForm" table in the 
bundle only defines the "password" key, and the Italian bundle does not define 
"loginForm" table at all.  If we do the following:

    $english = new ResourceBundle('en', '/path/to/resource/bundle');
    $italian = new ResourceBundle('it', '/path/to/resource/bundle');
    $spanish = new ResourceBundle('es', '/path/to/resource/bundle');

    echo $english->get('loginForm')->get('username');
    echo $italian->get('loginForm')->get('username');
    echo $spanish->get('loginForm')->get('username');

The English and Italian echo statements print the string stored in the 
key of the "loginForm" table of the root bundle, as expected.  The Spanish one, 
however, prints nothing (ResourceBundle::get() actually returns NULL) instead of 
falling back to the root locale.  This behavior seems to be a result of the 
"loginForm" table being defined, but not containing a "username" entry.

This is not a bug per se, but a question of expected results.  The PHP and ICU 
documentation suggests that locale inheritance should take place regardless of 
deeply the key being accessed is nested.  In practice, however, the Intl 
only allows for locale inheritance when accessing a top-level key.

Calling ures_getByKeyWithFallback() instead of ures_getByKey() 
(resourcebundle_class.c, line 181) should rectify this issue.

Test script:
// Given the following compiled into a .dat format resource bundle:
// root:table {
//     loginForm:table {
//         username:string {"Username"}
//         password:string {"Password"}
//     }
// }
// es:table {
//     loginForm:table {
//         password:string {"Contraseña"}
//     }
// }

$rb = new ResourceBundle('es_MX', '/path/to/resource/bundle');
$loginStrings = $bundle->get('loginForm');

Expected result:
string(8) "Username"
string(11) "Contraseña"

Actual result:
string(11) "Contraseña"


intl-resourcebundle-get-locale-inheritance (last revision 2013-01-08 19:31 UTC by nrawlings at imiassociates dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-09 09:31 UTC]
ures_getByKeyWithFallback is not a public API, therefore I'd prefer not to use it unless there's a very compelling reason.

This problem is described in . Since then 4 years have passed.
 [2021-11-11 11:16 UTC]
-Package: intl +Package: I18N and L10N related
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Feb 07 01:05:51 2023 UTC