setDescription('Compile translations'); $this->setHelp('This command compiles all .po files in the locale folder of the plugin.'); } protected function execute(InputInterface $input, OutputInterface $output): int { try { $folder = $this->getPluginFolder($input); foreach (glob("{$folder}/locale/*/LC_MESSAGES/*.po") as $po) { $command_line = 'msgfmt "${:PO}" -o "${:MO}"'; $process = Process::fromShellCommandline($command_line); try { $process->mustRun(null, [ 'PO' => $po, 'MO' => preg_replace('/\.po$/', '.mo', $po), ]); $out = $process->getOutput(); if ($out) { $output->writeln($out, OutputInterface::VERBOSITY_VERBOSE); } $output->writeln("Translations have been compiled successfully."); } catch (ProcessFailedException $e) { $output->writeln("Could not execute shell command"); $output->writeln($e->getmessage()); return Command::FAILURE; } } return Command::SUCCESS; } catch (Exception $e) { $output->writeln("{$e->getMessage()}"); return Command::FAILURE; } } }