mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX IntlLocales::validate when lang and region are the same e.g. de_DE
This commit is contained in:
parent
16aebb83e4
commit
3a372a1f41
@ -1605,6 +1605,18 @@ class IntlLocales implements Locales, Resettable
|
|||||||
if (!$lang || !$region) {
|
if (!$lang || !$region) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the configurable whitelist
|
||||||
|
$localeCode = strtolower($lang) . '_' . strtoupper($region);
|
||||||
|
$locales = $this->getLocales();
|
||||||
|
|
||||||
|
if (array_key_exists($localeCode, $locales)
|
||||||
|
|| array_key_exists(strtolower($localeCode), $locales)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
return strcasecmp($lang, $region)
|
return strcasecmp($lang, $region)
|
||||||
&& strcasecmp($lang, $locale)
|
&& strcasecmp($lang, $locale)
|
||||||
&& strcasecmp($region, $locale);
|
&& strcasecmp($region, $locale);
|
||||||
|
@ -376,6 +376,9 @@ class i18nTest extends SapphireTest
|
|||||||
$this->assertFalse(i18n::getData()->validate('en'), 'Short lang format is not valid');
|
$this->assertFalse(i18n::getData()->validate('en'), 'Short lang format is not valid');
|
||||||
$this->assertFalse(i18n::getData()->validate('xx_XX'), 'Unknown locale in correct format is not valid');
|
$this->assertFalse(i18n::getData()->validate('xx_XX'), 'Unknown locale in correct format is not valid');
|
||||||
$this->assertFalse(i18n::getData()->validate(''), 'Empty string is not valid');
|
$this->assertFalse(i18n::getData()->validate(''), 'Empty string is not valid');
|
||||||
|
$this->assertTrue(i18n::getData()->validate('de_DE'), 'Known locale where language is same as region');
|
||||||
|
$this->assertTrue(i18n::getData()->validate('fr-FR'), 'Known locale where language is same as region');
|
||||||
|
$this->assertTrue(i18n::getData()->validate('zh_cmn'), 'Known locale with all lowercase letters');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTranslate()
|
public function testTranslate()
|
||||||
|
Loading…
Reference in New Issue
Block a user