|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
13 + 20 = ?
Subscribe to this entry?

 [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: Mon Jan 30 09:05:52 2023 UTC