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: -
From: salarmehr at gmail dot com Assigned:
Status: Open Package: I18N and L10N related
PHP Version: 7.3.14 OS: Windows/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: salarmehr at gmail dot com
New email:
PHP Version: OS:

 

 [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

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 18:01:24 2020 UTC