Background
In the ICU-Data-Directory that you listed on GitHub (note that you were on a release branch rather than master branch), there are neither files for en_US
nor en_UK
present. On the master branch you can find an en_GB
file which seems to be the proper locale code rather than UK.
Though I can not say why the en_US
is not around (which I would absolutely expect, just as you did), it appears that with all your tests where you are getting "French" as a result, you are not actually loading the correct ICU path but rather because that one can not be found, the root path is loaded.
You already evidenced that by trying with en_foobar
. Same works if you try to load any other nonsense locale that just does not exist in that data directory, and the same is true for both en_US
and en_UK
(since they do both not exist, as explained before).
As a side note: I think you may have misunderstood the fallback parameter. This is so that if the language can not be loaded, the fallback language is loaded - not that any data you request on it would directly be requested on the parent.
Code examples
To make it a bit more clear what I am talking about, here are some examples.
Loading with nonsense locales always loads the whole directory data so you have access to all the root data:
$bundle = \ResourceBundle::create('stackoverflow-is-great', 'ICUDATA-lang', true);
var_dump($bundle->get('Languages')->get('fr')); // string(6) "French"
var_dump($bundle->get('Languages')->get('de')); // string(6) "German"
Loading sub-languages from en_NZ that do not exist:
$bundle = \ResourceBundle::create('en_NZ', 'ICUDATA-lang', true);
var_dump($bundle->get('Languages')->get('fr')); // NULL
var_dump($bundle->get('Languages')->get('de')); // NULL
Loading sub-languages from en_NZ that do exist:
$bundle = \ResourceBundle::create('en_NZ', 'ICUDATA-lang', true);
var_dump($bundle->get('Languages')->get('mi')); // string(6) "Māori"
To put it in a nutshell: It actually works as expected and gives you data where it is available, and no data where none is available.
Debugging
How did I find that out? Based on this user comment on the PHP ResourceBundle docs page. I added a depth output and had a very handy debug function:
function t($rb, $depth = 0) {
foreach($rb as $k => $v) {
echo str_repeat('->', $depth);
if(is_object($v)) {
print_r($v);
var_dump($k);
t($v, ++$depth);
} else {
var_dump($k . " " . $v);
}
}
}
$rb = new ResourceBundle('en_UK', 'ICUDATA-lang', true);
var_dump($rb->get('Languages')->get('fr'));
t($rb);
This prints a (really long, which is why I am not adding it here) output which looks suspiciously like the root data.
One last side note: en_GB
seems to be aliased to en_001 here as well, I am not sure to what effect though.
TL;DR: First three locales do not really exist in the data set and hence root data is loaded, en_NZ
and en_AU
work just like they should.