-
-
Notifications
You must be signed in to change notification settings - Fork 503
[UXTranslator] Update recipe with dump_typescript config
#1499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the PR 😍 How to test these changes in your application
Diff between recipe versionsIn order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes. symfony/ux-translator2.8 vs 2.9diff --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.32diff --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.'); |
56fc195 to
4236b67
Compare
… 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
Head branch was pushed to by a user without write access
4236b67 to
f2811eb
Compare
…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
Related to symfony/ux#3218