48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
use App\Services\LocaleGuard;
|
|
|
|
uses(Tests\TestCase::class);
|
|
|
|
it('supports french as an application locale', function () {
|
|
expect(config('localization.supportedLocales'))
|
|
->toHaveKey('fr')
|
|
->and(LocaleGuard::normalize('FR'))
|
|
->toBe('fr');
|
|
});
|
|
|
|
it('keeps french translation files in sync with the german source keys', function () {
|
|
foreach (glob(resource_path('lang/de/*.php')) as $germanFile) {
|
|
$fileName = basename($germanFile);
|
|
$frenchFile = resource_path('lang/fr/'.$fileName);
|
|
|
|
expect($frenchFile)->toBeFile();
|
|
expect(frenchLocalizationFlattenTranslationKeys(require $frenchFile))
|
|
->toEqualCanonicalizing(frenchLocalizationFlattenTranslationKeys(require $germanFile));
|
|
}
|
|
});
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
function frenchLocalizationFlattenTranslationKeys(array $translations, string $prefix = ''): array
|
|
{
|
|
$keys = [];
|
|
|
|
foreach ($translations as $key => $value) {
|
|
$translationKey = $prefix.(string) $key;
|
|
|
|
if (is_array($value)) {
|
|
$keys = [
|
|
...$keys,
|
|
...frenchLocalizationFlattenTranslationKeys($value, $translationKey.'.'),
|
|
];
|
|
|
|
continue;
|
|
}
|
|
|
|
$keys[] = $translationKey;
|
|
}
|
|
|
|
return $keys;
|
|
}
|