chore: measure impact of a configurable i18n abstraction over Transactions on tree-shaking [POC] #668
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



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