SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.5k stars 260 forks source link

Configuration - fetchDefaultLanguage unclear for custom 18n bundles #3165

Open HappyHepo opened 3 years ago

HappyHepo commented 3 years ago

Describe the documentation issue

Description of the issue A clear and concise description. Configuration - fetchDefaultLanguage describes that the default language is inlined by default. This does not appear to be the case when using custom i18n files. Only the i18n ids are shown and the bundle is empty. When setting fetchDefaultLanguage: true, the bundle works as expected. The i18n for apps documentation also does not mention this.

Please clarify, that "If for some reason it is necessary to fetch the default language text from the network as well, use this setting." does include custom i18n, possibly also on the i18n documentation page.

alexandar-mitsev commented 3 years ago

Hello @SAP/ui5-webcomponents-team ,

Can you please check this problem with application (custom) i18n properties files which do not get inlined by default. Or the documentation might need update.

Regards, Alexandar Mitsev

pskelin commented 3 years ago

Hi @HappyHepo,

the build tools (for components) work on .properties files and generate two kinds of artefacts:

The i18n-defaults.js file is imported by all components, so that they can work out of the box without configuring additional assets. The i18n-defaults.js contains keys and the default language values (english, unless changed during build time).

See an example of the defaults file generated here: https://unpkg.com/browse/@ui5/webcomponents@1.0.0-rc.14/dist/generated/i18n/i18n-defaults.js

Then components pass the object from this file to the translation function, and if the current language is english, the text from the i18n-defaults.js file is used and the en.json file is not fetched (since the default language is part of the component through the imports).

If for some reason the json file contains different data from the inlined data, this option fetchDefaultLanguage forces the runtime to fetch the json even though the same language is inlined and available. This is more of an exceptional case (some runtime changes perhaps).

From your description, it seems that you did not use the tooling to generate the json files and you have no i18n-defaults.js file. Could you give more information on how you use i18n? Is it a standalone app?

Currently, the tooling for i18n is only usable by components, but a change is on the way to extract it as a separate npm package. Check it out here: https://github.com/SAP/ui5-webcomponents/pull/3045

Any input on how to shape this for app usage will be very helpful.

HappyHepo commented 3 years ago

Hi @pskelin,

I use the i18n functionality for a standalone (angular) app which uses ui5-webcomponents for the UI. I directly created json files as per the Tips and Trick section of i18n for apps, to reduce runtime size.

A CLI mode, as you mentioned in the change, would be neccessary to use it from the build script. As I use ng serve during development, an integration with ng serve/build would be nice to have.