Skip to content

Commit

Permalink
ENH Explicitly set i18n locale to en_US for supported modules
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 23, 2025
1 parent 0f3c88f commit 6760344
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"symfony/dom-crawler": "^6.1",
"silverstripe/testsession": "^3",
"silverstripe/framework": "^5",
"silverstripe/supported-modules": "^1.1",
"symfony/finder": "^6.1"
},
"autoload": {
Expand Down
33 changes: 33 additions & 0 deletions src/Controllers/ModuleSuiteLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Yaml\Parser;
use SilverStripe\i18n\i18n;
use SilverStripe\SupportedModules\MetaData;
use SilverStripe\Core\Path;

/**
* Locates test suite configuration based on module name.
Expand Down Expand Up @@ -141,6 +144,10 @@ public function execute(InputInterface $input, OutputInterface $output)
$config['type'],
$config['settings']
);

// Set i18n locale
$this->setI18nLocale($config);

return null;
}

Expand Down Expand Up @@ -190,4 +197,30 @@ protected function loadSuiteConfiguration($suite, Module $module)
'settings' => $resolvedConfig,
];
}

private function setI18nLocale(array $config): void
{
$path = $config['type']['settings']['paths'][0] ?? '';
$packagistName = '';
if (preg_match('#(^|/)vendor/([^/]+/[^/]+)/.+#', $path, $matches)) {
// Running behat tests of a module in the vendor folder
$packagistName = $matches[1];
} else {
// Running behat tests of a module or project in the root folder
$file = Path::join(BASE_PATH, 'composer.json');
if (file_exists($file)) {
$json = json_decode(file_get_contents($file), true);
$packagistName = $json['name'] ?? '';
}
}
$metaData = MetaData::getMetaDataByPackagistName($packagistName);
$isSupportedModule = !empty($metaData);
if ($isSupportedModule) {
// Anything that is in silverstripe/supported-module has behat tests in en_US
// Update the default_locale config in case in case any config at the project level or any
// installed optional module has set it to a non-en_US locale
i18n::config()->set('default_locale', 'en_US');
i18n::set_locale('en_US');
}
}
}

0 comments on commit 6760344

Please sign in to comment.