Skip to content

Conversation

@Kocal
Copy link
Member

@Kocal Kocal commented Dec 5, 2025

Q A
License MIT
Doc issue/PR symfony/symfony-docs#...

Related to symfony/ux#3218

@Kocal Kocal marked this pull request as draft December 5, 2025 17:46
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1499/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1499/index.json
  2. Install the package(s) related to this recipe:

    composer req symfony/flex
    composer req 'symfony/ux-translator:^2.32'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

symfony/ux-translator

2.8 vs 2.9
diff --git a/symfony/ux-translator/2.8/assets/translator.js b/symfony/ux-translator/2.9/assets/translator.js
index eab7b6c7..28012a65 100644
--- a/symfony/ux-translator/2.8/assets/translator.js
+++ b/symfony/ux-translator/2.9/assets/translator.js
@@ -1,3 +1,4 @@
+import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-translator';
 /*
  * This file is part of the Symfony UX Translator package.
  *
@@ -7,10 +8,6 @@
  * If you use TypeScript, you can rename this file to "translator.ts" to take advantage of types checking.
  */
 
-import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-translator';
-import { localeFallbacks } from '../var/translations/configuration';
-
 setLocaleFallbacks(localeFallbacks);
 
 export { trans };
-export * from '../var/translations';
diff --git a/symfony/ux-translator/2.8/manifest.json b/symfony/ux-translator/2.9/manifest.json
index 3f984fca..a1ac08ba 100644
--- a/symfony/ux-translator/2.8/manifest.json
+++ b/symfony/ux-translator/2.9/manifest.json
@@ -2,8 +2,38 @@
     "bundles": {
         "Symfony\\UX\\Translator\\UxTranslatorBundle": ["all"]
     },
+    "conflict": {
+        "symfony/flex": "<1.20.0 || >=2.0.0,<2.3.0"
+    },
     "copy-from-recipe": {
         "assets/": "assets/",
-        "config/": "%CONFIG_DIR%/"
-    }
+        "config/": "%CONFIG_DIR%/",
+        "var/": "var/"
+    },
+    "add-lines": [
+        {
+            "file": "assets/translator.js",
+            "content": "import { localeFallbacks } from '../var/translations/configuration';",
+            "position": "top",
+            "requires": "symfony/webpack-encore-bundle"
+        },
+        {
+            "file": "assets/translator.js",
+            "content": "import { localeFallbacks } from '@app/translations/configuration';",
+            "position": "top",
+            "requires": "symfony/asset-mapper"
+        },
+        {
+            "file": "assets/translator.js",
+            "content": "export * from '../var/translations';",
+            "position": "bottom",
+            "requires": "symfony/webpack-encore-bundle"
+        },
+        {
+            "file": "assets/translator.js",
+            "content": "export * from '@app/translations';",
+            "position": "bottom",
+            "requires": "symfony/asset-mapper"
+        }
+    ]
 }
diff --git a/symfony/ux-translator/2.9/var/translations/configuration.js b/symfony/ux-translator/2.9/var/translations/configuration.js
new file mode 100644
index 00000000..bea96d63
--- /dev/null
+++ b/symfony/ux-translator/2.9/var/translations/configuration.js
@@ -0,0 +1,3 @@
+export const localeFallbacks = {};
+
+console.log('Run bin/console cache:warmup to generate the translation files.');
diff --git a/symfony/ux-translator/2.9/var/translations/index.js b/symfony/ux-translator/2.9/var/translations/index.js
new file mode 100644
index 00000000..34f7c1ba
--- /dev/null
+++ b/symfony/ux-translator/2.9/var/translations/index.js
@@ -0,0 +1 @@
+console.log('Run bin/console cache:warmup to generate the translation files.');
2.9 vs 2.32
diff --git a/symfony/ux-translator/2.9/assets/translator.js b/symfony/ux-translator/2.32/assets/translator.js
index 28012a65..a0181a08 100644
--- a/symfony/ux-translator/2.9/assets/translator.js
+++ b/symfony/ux-translator/2.32/assets/translator.js
@@ -1,4 +1,6 @@
-import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-translator';
+import { createTranslator } from '@symfony/ux-translator';
+import { messages, localeFallbacks } from '../var/translations/index.js';
+
 /*
  * This file is part of the Symfony UX Translator package.
  *
@@ -8,6 +10,9 @@ import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-tra
  * If you use TypeScript, you can rename this file to "translator.ts" to take advantage of types checking.
  */
 
-setLocaleFallbacks(localeFallbacks);
+const translator = createTranslator({
+    messages,
+    localeFallbacks,
+});
 
-export { trans };
+export const { trans } = translator;
diff --git a/symfony/ux-translator/2.9/config/packages/ux_translator.yaml b/symfony/ux-translator/2.32/config/packages/ux_translator.yaml
index 1c1c7060..c8453a50 100644
--- a/symfony/ux-translator/2.9/config/packages/ux_translator.yaml
+++ b/symfony/ux-translator/2.32/config/packages/ux_translator.yaml
@@ -1,3 +1,9 @@
 ux_translator:
     # The directory where the JavaScript translations are dumped
     dump_directory: '%kernel.project_dir%/var/translations'
+
+when@prod:
+    ux_translator:
+        # Control whether TypeScript types are dumped alongside translations.
+        # Disable this if you do not use TypeScript (e.g. in production when using AssetMapper), to speed up cache warmup.
+        # dump_typescript: false
diff --git a/symfony/ux-translator/2.9/manifest.json b/symfony/ux-translator/2.32/manifest.json
index a1ac08ba..5af38680 100644
--- a/symfony/ux-translator/2.9/manifest.json
+++ b/symfony/ux-translator/2.32/manifest.json
@@ -9,31 +9,5 @@
         "assets/": "assets/",
         "config/": "%CONFIG_DIR%/",
         "var/": "var/"
-    },
-    "add-lines": [
-        {
-            "file": "assets/translator.js",
-            "content": "import { localeFallbacks } from '../var/translations/configuration';",
-            "position": "top",
-            "requires": "symfony/webpack-encore-bundle"
-        },
-        {
-            "file": "assets/translator.js",
-            "content": "import { localeFallbacks } from '@app/translations/configuration';",
-            "position": "top",
-            "requires": "symfony/asset-mapper"
-        },
-        {
-            "file": "assets/translator.js",
-            "content": "export * from '../var/translations';",
-            "position": "bottom",
-            "requires": "symfony/webpack-encore-bundle"
-        },
-        {
-            "file": "assets/translator.js",
-            "content": "export * from '@app/translations';",
-            "position": "bottom",
-            "requires": "symfony/asset-mapper"
-        }
-    ]
+    }
 }
diff --git a/symfony/ux-translator/2.9/var/translations/configuration.js b/symfony/ux-translator/2.9/var/translations/configuration.js
deleted file mode 100644
index bea96d63..00000000
--- a/symfony/ux-translator/2.9/var/translations/configuration.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export const localeFallbacks = {};
-
-console.log('Run bin/console cache:warmup to generate the translation files.');

@Kocal Kocal marked this pull request as ready for review December 5, 2025 19:52
@Kocal Kocal force-pushed the ux-translator-dump-ts branch from 56fc195 to 4236b67 Compare December 5, 2025 20:11
@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) December 5, 2025 20:11
Kocal added a commit to symfony/ux that referenced this pull request Dec 5, 2025
… to enable/disable TypeScript types generation (Kocal)

This PR was merged into the 2.x branch.

Discussion
----------

[Translator] Add option `ux_translator.dump_typescript` to enable/disable TypeScript types generation

| Q              | A
| -------------- | ---
| Bug fix?       | no
| New feature?   | yes <!-- 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

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:
<img width="1200" height="630" alt="image" src="https://github.com/user-attachments/assets/1b9fe129-c1f5-49d4-a379-caa98aa92afb" />

~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.

Commits
-------

741b421 [Translator] Add option `ux_translator.dump_typescript` to enable/disable TypeScript types generation
auto-merge was automatically disabled December 6, 2025 12:20

Head branch was pushed to by a user without write access

@Kocal Kocal force-pushed the ux-translator-dump-ts branch from 4236b67 to f2811eb Compare December 6, 2025 12:20
@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) December 6, 2025 12:20
Kocal added a commit to symfony/ux 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant