Skip to content

Conversation

@Kocal
Copy link
Member

@Kocal Kocal commented Dec 5, 2025

Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? yes
Issues Fix #...
License MIT

Recipe PR: symfony/recipes#1499


When using the UX Translator with the AssetMapper, there is no point to dump TypeScript types in production, since these files will not be used. The deployment will be faster.

The new option dump_typescript allows to disable this behavior, default to true.

On an app with ~3320 translation messages, a cache clear goes from ~1min to ~10s, see https://blackfire.io/profiles/compare/4d9553ca-7b96-415d-aa0f-2991f721b609/graph:
image

~50 sec for extracting types, especially when using ICU translations, is too much, even for ~3k keys. I think we can have a quick-win by early exiting when no { is found in the translation message.

@carsonbot carsonbot added Deprecation Documentation Improvements or additions to documentation Feature New Feature Status: Needs Review Needs to be reviewed labels Dec 5, 2025
@Kocal Kocal force-pushed the translator/add-option-dump-typescript branch 3 times, most recently from 7d77142 to 021db9e Compare December 5, 2025 17:45
@Kocal Kocal removed the Deprecation label Dec 5, 2025
@Kocal Kocal requested a review from Copilot December 5, 2025 17:49
Copilot finished reviewing on behalf of Kocal December 5, 2025 17:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new configuration option dump_typescript to the UX Translator component, allowing developers to disable TypeScript type definitions generation. This is particularly useful in production environments when using AssetMapper, where TypeScript types are not needed, resulting in significantly faster cache clears (from ~1min to ~10s for applications with ~3320 translation messages).

Key changes:

  • Added dump_typescript boolean configuration option (defaults to true)
  • Modified TranslationsDumper to conditionally generate TypeScript .d.ts files based on the configuration
  • Updated tests to verify the new behavior and refactored to remove shared test setup

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Translator/src/TranslationsDumper.php Added dumpTypeScript parameter and conditional logic to skip TypeScript file generation when disabled
src/Translator/src/DependencyInjection/Configuration.php Added dump_typescript boolean configuration node with default value true
src/Translator/src/DependencyInjection/UxTranslatorExtension.php Wired the new configuration value to the dumper service
src/Translator/config/services.php Updated service definition to include the new dump_typescript abstract argument
src/Translator/tests/TranslationsDumperTest.php Added test for disabled TypeScript generation and refactored tests to instantiate dumper per test
src/Translator/doc/index.rst Added documentation section explaining how to disable TypeScript types in production
src/Translator/CHANGELOG.md Documented the new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Kocal Kocal force-pushed the translator/add-option-dump-typescript branch from 021db9e to a2cc3dc Compare December 5, 2025 18:11
Kocal added a commit that referenced this pull request Dec 5, 2025
…sages, if no `{` is found (Kocal)

This PR was merged into the 2.x branch.

Discussion
----------

[Translator] Early exit parameters extraction from Intl messages, if no `{` is found

| Q              | A
| -------------- | ---
| Bug fix?       | yes
| New feature?   | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations?  | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md -->
| Documentation? | no <!-- required for new features, or documentation updates -->
| Issues         | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License        | MIT

Following #3218

On an app with ~3320 keys, ~2870 of them didn't use the ICU syntax. Early exiting when no `{` reduced the cache-clear time by ~60%:
[![](https://github.com/user-attachments/assets/481076d8-1d5c-4b98-b454-e936d16b3ca9)](https://blackfire.io/profiles/compare/209538ae-26bf-40bf-a3f4-5a51d91a4fe7/graph)

Commits
-------

c8a303c [Translator] Early exit parameters extraction from Intl messages, if no `{` is found
@Kocal Kocal force-pushed the translator/add-option-dump-typescript branch from a2cc3dc to 741b421 Compare December 5, 2025 19:52
@Kocal Kocal merged commit 72e0f7b into symfony:2.x Dec 5, 2025
27 of 30 checks passed
@Kocal Kocal deleted the translator/add-option-dump-typescript branch December 5, 2025 20:14
->defaultValue('%kernel.project_dir%/var/translations')
->end()
->booleanNode('dump_typescript')
->info('Control if TypeScript types should be dumped alongside translations. Can be useful to disable when not using TypeScript (e.g. AssetMapper in production).')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->info('Control if TypeScript types should be dumped alongside translations. Can be useful to disable when not using TypeScript (e.g. AssetMapper in production).')
->info('Control whether TypeScript types are dumped alongside translations. Disable this if you do not use TypeScript (e.g. in production when using AssetMapper).')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #3221

Comment on lines 37 to 39
private string $dumpDir,
private bool $dumpTypeScript,
private MessageParametersExtractor $messageParametersExtractor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now this class is marked @experimental but the component is out there for some times now ... :/

Kocal added a commit that referenced this pull request Dec 6, 2025
…ription (Kocal)

This PR was merged into the 2.x branch.

Discussion
----------

[Translator] Reword `dump_typescript` option description

| Q              | A
| -------------- | ---
| Bug fix?       | no
| New feature?   | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations?  | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md -->
| Documentation? | yes <!-- required for new features, or documentation updates -->
| Issues         | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License        | MIT

Following #3218 (review), thank you `@smnandre`

The recipe symfony/recipes#1499 have been updated as well.

Commits
-------

248f7fc [Translator] Reword `dump_typescript` option description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Feature New Feature Status: Needs Review Needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants