You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The paths are relative to the node_modules directory, as during yarn build the file resides in /node_modules/@company-name/bundle-name/translator.js. The path isn't relative to the vendor/ directory, autocomplete gets it wrong.
Is this the correct approach to use UX Translator within a bundle? Or is there a better approach? Depending on the directory structure feels brittle to me and I wasn't able to find an answer regarding this topic.
I'm creating an Issue instead asking on Stack Overflow, as I would love to see this in the official documentation.
Thanks in advance :)
The text was updated successfully, but these errors were encountered:
asdfMaciej
changed the title
How to properly use UX Translator from a Bundle?
[Translator] How to properly use UX Translator from a Bundle?
Aug 4, 2023
The Symfony UX Translator was designed with Symfony apps support in mind, and not bundles. Anyway, the Translator must not be installed in your bundle, it's not its responsability IMO.
A bundle won't be able to import translations directly, from your app.
However your app can initialize your bundle script and inject the needed translations:
Your bundle should not require the UX Translator
Your bundle must define its translations (in translations/ directory)
Your bundle must keep its assets uncompiled, this is needed for later
Your app must require the UX Translator, it will dump your app+bundles translations in /var/translations/... files
Your app must initialize your bundle's asset and inject the needed translations:
// assets/foo.jsimport{FIRST_TRANSLATION_FROM_BUNDLE,SECOND_TRANSLATION_FROM_BUNDLE}from'./translator';import{initBundle}from'path-to-your-bundle';// your bundle must provide this kind of functioninitBundle({translations: {FIRST_TRANSLATION_FROM_BUNDLE,SECOND_TRANSLATION_FROM_BUNDLE}});
Hello,
I'm creating a bundle with the following
assets/
directory structure:I have manually copied translator.js from existing application code, and modified it to use different relative paths:
The paths are relative to the node_modules directory, as during
yarn build
the file resides in/node_modules/@company-name/bundle-name/translator.js
. The path isn't relative to thevendor/
directory, autocomplete gets it wrong.Is this the correct approach to use UX Translator within a bundle? Or is there a better approach? Depending on the directory structure feels brittle to me and I wasn't able to find an answer regarding this topic.
I'm creating an Issue instead asking on Stack Overflow, as I would love to see this in the official documentation.
Thanks in advance :)
The text was updated successfully, but these errors were encountered: