Skip to content

Commit ea287f8

Browse files
committed
ENH Explicitly set i18n locale to en_US for supported modules
1 parent 0f3c88f commit ea287f8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"symfony/dom-crawler": "^6.1",
3232
"silverstripe/testsession": "^3",
3333
"silverstripe/framework": "^5",
34+
"silverstripe/supported-modules": "^1.1",
3435
"symfony/finder": "^6.1"
3536
},
3637
"autoload": {

src/Controllers/ModuleSuiteLocator.php

+32
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\DependencyInjection\Container;
1919
use Symfony\Component\DependencyInjection\ContainerInterface;
2020
use Symfony\Component\Yaml\Parser;
21+
use SilverStripe\i18n\i18n;
22+
use SilverStripe\SupportedModules\MetaData;
2123

2224
/**
2325
* Locates test suite configuration based on module name.
@@ -141,6 +143,10 @@ public function execute(InputInterface $input, OutputInterface $output)
141143
$config['type'],
142144
$config['settings']
143145
);
146+
147+
// Set i18n locale
148+
$this->setI18nLocale($config);
149+
144150
return null;
145151
}
146152

@@ -190,4 +196,30 @@ protected function loadSuiteConfiguration($suite, Module $module)
190196
'settings' => $resolvedConfig,
191197
];
192198
}
199+
200+
private function setI18nLocale(array $config): void
201+
{
202+
$path = $config['type']['settings']['paths'][0] ?? '';
203+
$packagistName = '';
204+
if (preg_match('#^vendor/([^/]+/[^/]+)/.+#', $path, $matches)) {
205+
// Running unit tests of a module in the vendor folder
206+
$packagistName = $matches[1];
207+
} else {
208+
// Running unit tests of a module or project in the root folder
209+
$file = BASE_PATH . '/composer.json';
210+
if (file_exists($file)) {
211+
$json = json_decode(file_get_contents($file), true);
212+
$packagistName = $json['name'] ?? '';
213+
}
214+
}
215+
$metaData = MetaData::getMetaDataByPackagistName($packagistName);
216+
$isSupportedModule = !empty($metaData);
217+
if ($isSupportedModule) {
218+
// Anything that is in silverstripe/supported-module has behat tests in en_US
219+
// Update the default_locale config in case in case any config at the project level or any
220+
// installed optional module has set it to a non-en_US locale
221+
i18n::config()->set('default_locale', 'en_US');
222+
i18n::set_locale('en_US');
223+
}
224+
}
193225
}

0 commit comments

Comments
 (0)