PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Internationalization » Translation2 » Bug #2619

Falling back to language code if fully qualified locale is not available

Details

Request #2619Falling back to language code if fully qualified locale is not available
Submitted2004-10-26 11:30 UTC
Fromylf at xung dot org
Assignedquipo
StatusWont fix
PackageTranslation2
PHP Version4.3.4
OSLinux Debian
Roadmaps(Not assigned)

Comments

[2004-10-26 11:30 UTC] ylf at xung dot org

Description:
------------
Hi,

I'd appreciate to see support for another option in addition to fallbackLang.

Say I request fr_CH but it's either not an available locale, or the specified string is not available with this locale.

If this happens, I'd like to fall back to "fr", that is : the language code part of the locale name. If it's not available either, then "fallbackLang" would be used.

So, in the translations definition (the strings table), one could put both fully qualified locale (fr_FR, fr_CH), and language code only ones (fr, en).

In my case, most of the strings would be attached to 'fr', and a few to 'fr_CH' overriding 'fr' translations for the rare swiss differences.

Regards

[2004-10-26 12:14 UTC] ylf at xung dot org

This kind of fallback 'stack' is nice.

The point is my application will be told to work on a fully qualified locale, say 'fr_CH'.

Then it's gonna edit some administrative documents, for which it will query Translation2 in order to get the properly translated strings.

With what you describe, I'll have to do this :

// the user has set $locale to 'fr_CH' but it could be any
// fully qualified locale (lang code + country code)

$tr->setLang($locale);

$language_code = substr($locale,0,2);

$tr =& $tr->getDecorator('Lang');
$tr->setOption('fallbackLang', $language_code);

Or with an array, falling back to a fully qualified locale :

$fallbacks = array ('fr_CH' => 'fr_FR', 'de_AT' => 'de_DE');

if (isset($fallbacks[$locale])) {
$tr =& $tr->getDecorator('Lang');
$tr->setOption('fallbackLang', $fallbacks[$locale]);
}

I think this last method is the most flexible. What about supporting it as a setting in the languages meta info ?

Like :

+-------+--------------+------------+------------+---------+
| id | name | meta | error_text | fallback|
+-------+--------------+------------+------------+---------+
| fr_CH | Swiss french | iso-8859-1 | ... | fr_FR |
+-------+--------------+------------+------------+---------+

Or

+-----+-----------------------------------+-----+
| ... | meta | ... |
+-----+-----------------------------------+-----+
| |encoding=iso-8859-1,fallback=fr_FR | ... |
+-----+-----------------------------------+-----+

?