php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79197 Intl class does not for some locales (maybe fallback option bug)
Submitted: 2020-01-30 09:36 UTC Modified: 2021-12-14 15:44 UTC
From: salarmehr at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: I18N and L10N related
PHP Version: 7.3.14 OS: Windows/Linux
Private report: No CVE-ID: None
 [2020-01-30 09:36 UTC] salarmehr at gmail dot com
Description:
------------
Trying to get the language name from the language code, I run

```
$bundle = \ResourceBundle::create('en_UK', 'ICUDATA-lang', true);
$lang = $bundle->get('Languages')->get('fr');
var_dump($lang);

$bundle = \ResourceBundle::create('en_US', 'ICUDATA-lang', true);
$lang = $bundle->get('Languages')->get('fr');
var_dump($lang);

$bundle = \ResourceBundle::create('en_foobar', 'ICUDATA-lang', true);
$lang = $bundle->get('Languages')->get('fr');
var_dump($lang);

$bundle = \ResourceBundle::create('en_NZ', 'ICUDATA-lang', true);
$lang = $bundle->get('Languages')->get('fr');
var_dump($lang);

$bundle = \ResourceBundle::create('en_AU', 'ICUDATA-lang', true);
$lang = $bundle->get('Languages')->get('fr');
var_dump($lang);
```
```
string(6) "French"
string(6) "French"
string(6) "French"
NULL
NULL
```

It returns `null` for Australia and New Zealand that indicates an Intl error of
> Cannot load resource element 'fr': U_MISSING_RESOURCE_ERROR"

The third parameter of `\ResourceBundle::create` functions is for call back that means it should fallback to its parent locale. Interestingly the [parent locale of `en_AU`][1] is `en_001`.

Similarly, this happens for currency names

  [1]: https://github.com/unicode-org/icu/blob/release-65-1/icu4c/source/data/lang/en_AU.txt

Test script:
---------------
$bundle = \ResourceBundle::create('en_AU', 'ICUDATA-lang', true);
$lang = $bundle->get('Languages')->get('fr');
var_dump($lang);

Expected result:
----------------
string(6) "French"


Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-12-14 15:44 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-12-14 15:44 UTC] cmb@php.net
> Interestingly the [parent locale of `en_AU`][1] is `en_001`.

Right, and that is an upstream issue, so consider to report
there[1].

[1] <https://unicode-org.atlassian.net/jira/software/c/projects/ICU/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC