IBX-12091: Added TypeScript translation extraction support#1967
IBX-12091: Added TypeScript translation extraction support#1967mikadamczyk wants to merge 6 commits into
Conversation
5198656 to
8b44786
Compare
26d6cc2 to
8b9bbb0
Compare
|
| use Symfony\Component\Process\InputStream; | ||
| use Symfony\Component\Process\Process; | ||
|
|
||
| final class TypeScriptExtractorClient |
There was a problem hiding this comment.
| final class TypeScriptExtractorClient | |
| final readonly class TypeScriptExtractorClient |
|
|
||
| final class TypeScriptExtractorClient | ||
| { | ||
| private const DEFAULT_RESPONSE_TIMEOUT_SECONDS = 30.0; |
There was a problem hiding this comment.
| private const DEFAULT_RESPONSE_TIMEOUT_SECONDS = 30.0; | |
| private const float DEFAULT_RESPONSE_TIMEOUT_SECONDS = 30.0; |
| $this->parserScriptPath = $parserScriptPath ?? __DIR__ . '/typescript_translation_extractor.mjs'; | ||
| } | ||
|
|
||
| public function __destruct() |
There was a problem hiding this comment.
Can this have a return type?
| use SplFileInfo; | ||
| use Twig\Node\Node as TwigNode; | ||
|
|
||
| final class TypeScriptFileVisitor implements FileVisitorInterface, LoggerAwareInterface |
There was a problem hiding this comment.
| final class TypeScriptFileVisitor implements FileVisitorInterface, LoggerAwareInterface | |
| final readonly class TypeScriptFileVisitor implements FileVisitorInterface, LoggerAwareInterface |
| * @param array<mixed> $ast | ||
| */ | ||
| public function visitPhpFile(SplFileInfo $file, MessageCatalogue $catalogue, array $ast): void | ||
| { |
There was a problem hiding this comment.
Should we provide a comment why it is empty? 😉 Same goes for the Twig below.
|
|
||
| public function testServeModeProcessesMultipleFilesSequentiallyAndSurvivesPerFileErrors(): void | ||
| { | ||
| $goodFile = tempnam(sys_get_temp_dir(), 'ts_extractor_') . '.ts'; |
There was a problem hiding this comment.
tempnam() creates the file immediately. Appending .ts only modifies the returned path, so file_put_contents() creates a second file and the original temporary file is never removed. Could we rename the file instead, as done in testExtractsExpectedMessages()? The same applies to the other tempnam(...).'.ts' occurrences.
|
|
||
| foreach ($warnings as $warning) { | ||
| if (is_string($warning)) { | ||
| $this->logger?->error($warning); |
There was a problem hiding this comment.
Nitpick but shouldn't it be warning per method's name and variables' names?
| $extractionResponse['error'], | ||
| )); | ||
|
|
||
| return null; |
There was a problem hiding this comment.
Would it make sense to narrow down the return type to an empty array since the method's name implies messages? In this case we won't need check from line 40.


Description:
This PR adds TypeScript translation extraction support for
Translator.trans()andTranslator.transChoice()calls, including translation descriptions from@Desccomments. The extractor uses a persistent Node.js process with runtime validation, response timeouts, error handling, and automatic restart after failures. The implementation separates the JMS visitor from process management and installs frontend dependencies in the backend CI job so the tests can run correctly.For QA:
Documentation: