chore: measure impact of a configurable i18n abstraction over Transactions on tree-shaking [POC]#668
chore: measure impact of a configurable i18n abstraction over Transactions on tree-shaking [POC]#668
Conversation
…tions on tree-shaking [POC] Don't depend on `Translations` directly in the code. Introduce an "I18n" abstraction as we did with Logger for MaxLog. A configurable instance of the "I18nProvider" is set on `GlobalConfig` which is then use everywhere in the code. The configuration related to Translations is no longer in Client but in a new dedicated `TranslationsConfig` global object.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
|
The POC is completed. |



DISCLAIMER
Context
This experiment is part of the investigation for #665.
A significant portion of the codebase relies directly on the Translations module, which retrieves resources via MaxXmlRequest. Both of these components add considerable weight to the final application bundle, even when the maxGraph i18n features aren't being used.
Additionally, this tight coupling makes it difficult to integrate alternative i18n solutions, as it requires setting up a custom bridge between the application's i18n mechanism and maxGraph.
Important
This POC is only an evaluation and the final implementation may differ from that described in this PR.
Derived from mxGraph, the configuration of
Translationsis global, and this PR only modifies the way in which global configuration is carried out.It is probably possible to switch to local configurations, but this would require significant internal changes, in particular to inject the configuration into the various places where it is used.
High-level solution
Don't depend on
Translationsdirectly in the code.Introduce an "I18n" abstraction as we did with Logger for MaxLog.
A configurable instance of the "I18nProvider" is set on
GlobalConfigwhich is then use everywhere in the code.The configuration related to Translations is no longer in Client but in a new dedicated
TranslationsConfigglobal object.By default, use a "no op" i18n provider, so there is no dependency on Translations and MaxXmlRequest, which has a possible impact on the tree-shaking.
Results
✔️ ts-example and storybook stories are working as before when using the new "no op" i18n provider.
❓ The translation resources are not available in maxGraph, so there is currently no need to test that the actual usage of the former Translations implementation through its new i18n provider.
✔️ Bundle size reduction around 5 kB
Note: js-example use Codecs, and the Codec class still imports Translations directly in this POC (it calls a specific method of Translations which is currently not generalized in the I18nProvider). This may explain why the size decrease is lower than for other examples.
Notes
Covers #665