mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8726 from open-sausages/pulls/4/extra-locale-formats
MINOR Update add_i18n_javascript to load lowercase-dash language files
This commit is contained in:
commit
074cf04b60
@ -18,6 +18,7 @@ use SilverStripe\Core\Path;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\i18n\i18n;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
|
||||
class Requirements_Backend
|
||||
{
|
||||
@ -1004,13 +1005,23 @@ class Requirements_Backend
|
||||
|
||||
$files = array();
|
||||
$candidates = array(
|
||||
'en.js',
|
||||
'en_US.js',
|
||||
i18n::getData()->langFromLocale(i18n::config()->get('default_locale')) . '.js',
|
||||
i18n::config()->get('default_locale') . '.js',
|
||||
i18n::getData()->langFromLocale(i18n::get_locale()) . '.js',
|
||||
i18n::get_locale() . '.js',
|
||||
'en',
|
||||
'en_US',
|
||||
i18n::getData()->langFromLocale(i18n::config()->get('default_locale')),
|
||||
i18n::config()->get('default_locale'),
|
||||
i18n::getData()->langFromLocale(i18n::get_locale()),
|
||||
i18n::get_locale(),
|
||||
strtolower(DBField::create_field('Locale', i18n::get_locale())->RFC1766()),
|
||||
strtolower(DBField::create_field('Locale', i18n::config()->get('default_locale'))->RFC1766())
|
||||
);
|
||||
|
||||
$candidates = array_map(
|
||||
function ($candidate) {
|
||||
return $candidate . '.js';
|
||||
},
|
||||
$candidates
|
||||
);
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
$relativePath = Path::join($langDir, $candidate);
|
||||
$absolutePath = Director::getAbsFile($relativePath);
|
||||
|
@ -6,6 +6,7 @@ use InvalidArgumentException;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\i18n\i18n;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use Silverstripe\Assets\Dev\TestAssetStore;
|
||||
@ -1109,4 +1110,77 @@ EOS
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testAddI18nJavascript()
|
||||
{
|
||||
/** @var Requirements_Backend $backend */
|
||||
$backend = Injector::inst()->create(Requirements_Backend::class);
|
||||
$this->setupRequirements($backend);
|
||||
$backend->add_i18n_javascript('i18n');
|
||||
|
||||
$actual = $backend->getJavascript();
|
||||
|
||||
// English and English US should always be loaded no matter what
|
||||
$this->assertArrayHasKey('i18n/en.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en_US.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en-us.js', $actual);
|
||||
}
|
||||
|
||||
public function testAddI18nJavascriptWithDefaultLocale()
|
||||
{
|
||||
i18n::config()->set('default_locale', 'fr_CA');
|
||||
|
||||
/** @var Requirements_Backend $backend */
|
||||
$backend = Injector::inst()->create(Requirements_Backend::class);
|
||||
$this->setupRequirements($backend);
|
||||
$backend->add_i18n_javascript('i18n');
|
||||
|
||||
$actual = $backend->getJavascript();
|
||||
|
||||
|
||||
$this->assertArrayHasKey('i18n/en.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en_US.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en-us.js', $actual);
|
||||
// Default locale should be loaded
|
||||
$this->assertArrayHasKey('i18n/fr.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/fr_CA.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/fr-ca.js', $actual);
|
||||
}
|
||||
|
||||
public function testAddI18nJavascriptWithMemberLocale()
|
||||
{
|
||||
i18n::set_locale('en_GB');
|
||||
|
||||
/** @var Requirements_Backend $backend */
|
||||
$backend = Injector::inst()->create(Requirements_Backend::class);
|
||||
$this->setupRequirements($backend);
|
||||
$backend->add_i18n_javascript('i18n');
|
||||
|
||||
$actual = $backend->getJavascript();
|
||||
|
||||
// The current member's Locale as defined by i18n::get_locale should be loaded
|
||||
$this->assertArrayHasKey('i18n/en.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en_US.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en-us.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en-gb.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en_GB.js', $actual);
|
||||
}
|
||||
|
||||
public function testAddI18nJavascriptWithMissingLocale()
|
||||
{
|
||||
i18n::set_locale('fr_BE');
|
||||
|
||||
/** @var Requirements_Backend $backend */
|
||||
$backend = Injector::inst()->create(Requirements_Backend::class);
|
||||
$this->setupRequirements($backend);
|
||||
$backend->add_i18n_javascript('i18n');
|
||||
|
||||
$actual = $backend->getJavascript();
|
||||
|
||||
// We don't have a file for French Belgium. Regular french should be loaded anyway.
|
||||
$this->assertArrayHasKey('i18n/en.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en_US.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/en-us.js', $actual);
|
||||
$this->assertArrayHasKey('i18n/fr.js', $actual);
|
||||
}
|
||||
}
|
||||
|
0
tests/php/View/SSViewerTest/i18n/en-gb.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en-gb.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en-us.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en-us.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en_GB.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en_GB.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en_US.js
Normal file
0
tests/php/View/SSViewerTest/i18n/en_US.js
Normal file
0
tests/php/View/SSViewerTest/i18n/fr-ca.js
Normal file
0
tests/php/View/SSViewerTest/i18n/fr-ca.js
Normal file
0
tests/php/View/SSViewerTest/i18n/fr.js
Normal file
0
tests/php/View/SSViewerTest/i18n/fr.js
Normal file
0
tests/php/View/SSViewerTest/i18n/fr_CA.js
Normal file
0
tests/php/View/SSViewerTest/i18n/fr_CA.js
Normal file
0
tests/php/View/SSViewerTest/i18n/mi.js
Normal file
0
tests/php/View/SSViewerTest/i18n/mi.js
Normal file
Loading…
Reference in New Issue
Block a user