Skip to content

Commit 503d47d

Browse files
authored
Add option for POT file in DeepLTranslatorCommand
1 parent bccd830 commit 503d47d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/commands/DeepLTranslatorCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ protected function configure(): void {
2929
->addOption('force', null, InputOption::VALUE_NONE, 'Force re-translate including translated sentences')
3030
->addOption('ignore', null, InputOption::VALUE_REQUIRED, 'Regular expression to ignore parts of the text', null)
3131
->addOption('only', null, InputOption::VALUE_NONE, 'Create only PO file, no MO file')
32+
->addOption('pot', null, InputOption::VALUE_REQUIRED, 'POT file path for mapping translations', null)
3233
->addOption('wait', null, InputOption::VALUE_REQUIRED, 'Wait between translations in milliseconds', false)
3334
->addOption('apikey', null, InputOption::VALUE_REQUIRED, 'Deepl API Key')
3435
->addOption('translator', null, InputOption::VALUE_OPTIONAL, 'Path to custom translator instance', null)
@@ -65,6 +66,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6566
throw new InvalidOptionException('Invalid directory path: ' . $outputDir);
6667
}
6768

69+
// Input POT file
70+
$potTrans = null;
71+
if ($potFile = $input->getOption('pot')) {
72+
if ($potFile[0] !== '/') {
73+
$potFile = $dir . '/' . $potFile;
74+
}
75+
76+
$potTrans = (new \Gettext\Loader\PoLoader())->loadFile($potFile);
77+
}
78+
6879
// Get API key from .env or command line
6980
$apikey = $_ENV['DEEPL_API_KEY'] ?? $input->getOption('apikey');
7081

@@ -83,6 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8394
} else {
8495
$translator = new DeepLTranslator(
8596
new Translator($apikey),
97+
$potTrans,
8698
$input->getOption('ignore')
8799
);
88100
}

0 commit comments

Comments
 (0)