|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesintl-resourcebundle-get-locale-inheritance (last revision 2013-01-08 19:31 UTC by nrawlings at imiassociates dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-09 09:31 UTC] cataphract@php.net
[2021-11-11 11:16 UTC] nikic@php.net
-Package: intl
+Package: I18N and L10N related
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
Description: ------------ Locale inheritance is not used when calling ResourceBundle::get() to access a key 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 Spanish bundle only defines the "password" key, and the Italian bundle does not define the "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 "username" 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 how deeply the key being accessed is nested. In practice, however, the Intl extension 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'); var_dump($loginStrings->get('username')); var_dump($loginStrings->get('password')); Expected result: ---------------- string(8) "Username" string(11) "Contraseña" Actual result: -------------- NULL string(11) "Contraseña"