true, 'fa' => true, 'he' => true, ]; public function __construct(private LocaleService $localeService, private string $projectDirectory, private string $kernelEnvironment) { parent::__construct(); } public function isEnabled(): bool { return $this->kernelEnvironment !== 'prod'; } protected function configure(): void { $this->setDescription('Regenerate the locale definition file'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $locales = $this->localeService->getAllLocales(); // detect all registered locales and allow to choose them as well, so people get to // choose the language for translation with the correct format of their location /* $secondLevel = []; foreach (Locales::getLocales() as $locale) { if (substr_count($locale, '_') === 1) { $baseLocale = substr($locale, 0, strpos($locale, '_')); if (in_array($baseLocale, $locales)) { $subLocale = substr($locale, strpos($locale, '_') + 1); if (!is_numeric($subLocale)) { $secondLevel[] = $locale; } } } } $locales = array_merge($locales, $secondLevel); */ $appLocales = []; $defaults = [ 'date' => $this->defaultDate, 'time' => $this->defaultTime, 'rtl' => false, ]; // make sure all allowed locales are registered foreach ($locales as $locale) { if (!Locales::exists($locale)) { continue; } $appLocales[$locale] = $defaults; } // make sure all keys are registered for every locale foreach ($appLocales as $locale => $settings) { // these are completely new since v2 // calculate everything with IntlFormatter $shortDate = new \IntlDateFormatter($locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE); $shortTime = new \IntlDateFormatter($locale, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT); $settings['date'] = $shortDate->getPattern(); $settings['time'] = $shortTime->getPattern(); // make sure that sub-locales of a RTL language are also flagged as RTL $rtlLocale = $locale; if (substr_count($rtlLocale, '_') === 1) { $rtlLocale = substr($rtlLocale, 0, strpos($rtlLocale, '_')); } if (\array_key_exists($rtlLocale, $this->rtlLocales)) { $settings['rtl'] = $this->rtlLocales[$rtlLocale]; } // pre-fill all formats with the default locale settings $appLocales[$locale] = $settings; } ksort($appLocales); $filename = 'config/locales.php'; $targetFile = $this->projectDirectory . DIRECTORY_SEPARATOR . $filename; $content = 'success('Created new locale definition at: ' . $filename); return Command::SUCCESS; } }