0

Given I have a directory /locales with the files root.res and es.res, which have been generated (using genrb) from the text files as follows:

File: root.txt

root:table {
    test:string { "My test text" }
}

File: es.txt

es:table {
    test:string { "Mi texto de prueba" }
}

When I run the following code:

<?php
$bundleName = 'locale';
$resourceBundle = new ResourceBundle('es', $bundleName);
echo join("\n", $resourceBundle->getLocales($bundleName));

I should see:

es
root

However, the code produces:

Warning: join(): Invalid arguments passed...

This happens because $resourceBundle ->getLocales($bundleName) returns bool(false), but running the following code for locale es:

<?php
$bundleName = 'locale';
$resourceBundle = new ResourceBundle('es', $bundleName);
echo ($resourceBundle->get('test') . "\n");

correctly outputs:

Mi texto de prueba

And running for locale root:

<?php
$bundleName = 'locale';
$resourceBundle = new ResourceBundle('root', $bundleName);
echo ($resourceBundle->get('test') . "\n");

correctly outputs:

My test text

What do I need to do to make getLocales() work?

Frederik Krautwald
  • 1,782
  • 23
  • 32

1 Answers1

0

So, the PHP Manual, as usual, is not clear about this. However, the ICU Web site is:

A resource bundle is a set of pairs that provide a mapping from key to value. A given program can have different sets of resource bundles; one set for error messages, one for menus, and so on. However, the program may be organized to combine all of its resource bundles into a single related set.

The set is organized into a tree with "root" at the top, the language at the first level, the country at the second level, and additional variants below these levels. The set must contain a root that has all keys that can be used by the program accessing the resource bundles.

I will return with an update when tested.

Frederik Krautwald
  • 1,782
  • 23
  • 32