Skip to content

Commit dc5f140

Browse files
authored
refactor: prefer usage of inlined language (#2820)
1 parent 4397342 commit dc5f140

File tree

10 files changed

+80
-58
lines changed

10 files changed

+80
-58
lines changed

docs/Configuration.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
There are several configuration settings that affect all UI5 Web Components globally.
77

8-
Setting | Values | Default value | Description
9-
------------ | ----------------------------------------------- | ------------- | -------------------------------------------------------------
10-
[theme](#theme) | sap_fiori_3, sap_fiori_3_dark, sap_fiori_3_hcb, sap_fiori_3_hcw, sap_belize, sap_belize_hcb, sap_belize_hcw | sap_fiori_3 | Visual theme
11-
language | en, de, es, etc... | en | Language to be used for translatable texts
12-
[RTL](#rtl) (**deprecated since 1.0.0-rc.8**) | true, false | false | When true, sets global text direction to right-to-left
13-
[animationMode](#animationMode) | full, basic, minimal, none | full | Defines different animation scenarios or levels
14-
calendarType | Gregorian, Islamic, Buddhist, Japanese, Persian | Gregorian | Default calendar type for date-related web components
15-
[noConflict](#noConflict) | true, false | false | When set to true, all events will be fired with a "ui5-" prefix only
16-
[formatSettings](#formatSettings)| See the [Format settings](#formatSettings) section below | Empty object | Allows to override locale-specific configuration
17-
[assetsPath](#assetsPath)| See the [Assets path](#assetsPath) section below | Empty string | Allows to set the assets path at runtime
8+
Setting | Values | Default value | Description
9+
--------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10+
[theme](#theme) | sap_fiori_3, sap_fiori_3_dark, sap_fiori_3_hcb, sap_fiori_3_hcw, sap_belize, sap_belize_hcb, sap_belize_hcw | sap_fiori_3 | Visual theme
11+
language | en, de, es, etc... | en | Language to be used for translatable texts
12+
[animationMode](#animationMode) | full, basic, minimal, none | full | Defines different animation scenarios or levels
13+
calendarType | Gregorian, Islamic, Buddhist, Japanese, Persian | Gregorian | Default calendar type for date-related web components
14+
[noConflict](#noConflict) | true, false | false | When set to true, all events will be fired with a "ui5-" prefix only
15+
[formatSettings](#formatSettings) | See the [Format settings](#formatSettings) section below | Empty object | Allows to override locale-specific configuration
16+
[assetsPath](#assetsPath) | See the [Assets path](#assetsPath) section below | Empty string | Allows to set the assets path at runtime
17+
[fetchDefaultLanguage](#fetchDefaultLanguage) | true, false | false | The default language is inlined at build time and will be used. Change this to `true` if you want the i18n to be always fetched from the network even for the default language.
1818

1919
### Content Density
2020

2121
UI5 Web Components contain different content densities for certain controls that allow your app to adapt to the device in question, allowing you to display larger controls for touch-enabled devices, and a smaller more compact design for devices that are operated by mouse. Cosy size is the default density for all components. Compact size could be set by adding a class `ui5-content-density-compact` to an html element. It cascades all the way down and enforces compact density (smaller margins/paddings, smaller touch areas, etc).
2222

23-
<a name="theme"></a>
2423
### Theme
24+
<a name="theme"></a>
2525
The `theme` setting values above are the technical names of our themes.
2626
- The `sap_fiori_3` is known as `Quartz Light` and it`s the default theme.
2727
- The `sap_fiori_3_dark` is known as `Quartz Dark`.
@@ -50,8 +50,8 @@ applyDirection();
5050
```
5151

5252

53-
<a name="animationMode"></a>
5453
### Animation Mode
54+
<a name="animationMode"></a>
5555

5656
Animation modes allow to specify different animation scenarios or levels.
5757
- When `full`, all animations run unrestricted.
@@ -85,8 +85,8 @@ The `noConflict` configuration setting allows certain control over this behavior
8585
You can still use them by listening to `ui5-selection-change` and `ui5-header-click`, but the names `selection-change` and `header-click` will be
8686
free for use by other UI components and libraries without name collision.
8787

88-
<a name="formatSettings"></a>
8988
### Format settings
89+
<a name="formatSettings"></a>
9090

9191
For example, to force the first day of week to Sunday, no matter the locale:
9292

@@ -98,12 +98,12 @@ For example, to force the first day of week to Sunday, no matter the locale:
9898
}
9999
```
100100

101-
Setting | Values | Default value | Description
102-
------------ | ----------------------------------------------- | ------------- | -------------------------------------------------------------
103-
firstDayOfWeek | 0 (Sunday) through 6 (Saturday) | *Depends on locale* | When set, overrides the locale's default value
101+
Setting | Values | Default value | Description
102+
-------------- | ------------------------------- | ------------------- | ----------------------------------------------
103+
firstDayOfWeek | 0 (Sunday) through 6 (Saturday) | *Depends on locale* | When set, overrides the locale's default value
104104

105-
<a name="assetsPath"></a>
106105
### Assets path
106+
<a name="assetsPath"></a>
107107

108108
This configuration setting allows to set the path where asset files (most commonly `.json` ) that are to be fetched at runtime, are located. These are:
109109
- Icon collections
@@ -123,6 +123,24 @@ Example:
123123
</script>
124124
```
125125

126+
### Fetching the default language
127+
<a name="fetchDefaultLanguage"></a>
128+
129+
All texts used by components are inlined during build time so that components look and feel normally when prototyping. The inlined text is decided at build time (`en` unless configured otherwise).
130+
131+
Since the default language is inlined, it makes no sense to fetch it again from the network along with the normal assets for other locales, so the default behaviour is to use the inlined text.
132+
133+
If for some reason it is necessary to fetch the default language text from the network as well, use this setting.
134+
135+
Example:
136+
```html
137+
<script data-ui5-config type="application/json">
138+
{
139+
"fetchDefaultLanguage": true
140+
}
141+
</script>
142+
```
143+
126144
## Configuration script
127145

128146
In order to provide configuration settings, include the following ```<script>``` element in your HTML page:

packages/base/src/InitialConfiguration.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let initialConfig = {
1212
calendarType: null,
1313
noConflict: false, // no URL
1414
formatSettings: {},
15-
useDefaultLanguage: false,
15+
fetchDefaultLanguage: false,
1616
assetsPath: "",
1717
};
1818

@@ -38,13 +38,13 @@ const getLanguage = () => {
3838
};
3939

4040
/**
41-
* Returns if the default language, that is inlined build time,
42-
* should be used, instead of trying fetching the language over the network.
41+
* Returns if the default language, that is inlined at build time,
42+
* should be fetched over the network instead.
4343
* @returns {Boolean}
4444
*/
45-
const getUseDefaultLanguage = () => {
45+
const getFetchDefaultLanguage = () => {
4646
initConfiguration();
47-
return initialConfig.useDefaultLanguage;
47+
return initialConfig.fetchDefaultLanguage;
4848
};
4949

5050
const getNoConflict = () => {
@@ -142,7 +142,7 @@ export {
142142
getTheme,
143143
getRTL,
144144
getLanguage,
145-
getUseDefaultLanguage,
145+
getFetchDefaultLanguage,
146146
getNoConflict,
147147
getCalendarType,
148148
getFormatSettings,

packages/base/src/asset-registries/i18n.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { attachLanguageChange } from "../locale/languageChange.js";
33
import normalizeLocale from "../locale/normalizeLocale.js";
44
import nextFallbackLocale from "../locale/nextFallbackLocale.js";
55
import { DEFAULT_LANGUAGE } from "../generated/AssetParameters.js";
6-
import { getUseDefaultLanguage } from "../config/Language.js";
6+
import { getFetchDefaultLanguage } from "../config/Language.js";
77

88
// contains package names for which the warning has been shown
99
const warningShown = new Set();
@@ -84,14 +84,15 @@ const fetchI18nBundle = async packageName => {
8484
localeId = nextFallbackLocale(localeId);
8585
}
8686

87-
if (!_hasLoader(packageName, localeId)) {
88-
_showAssetsWarningOnce(packageName);
87+
// use default language unless configured to always fetch it from the network
88+
const fetchDefaultLanguage = getFetchDefaultLanguage();
89+
if (localeId === DEFAULT_LANGUAGE && !fetchDefaultLanguage) {
90+
_setI18nBundleData(packageName, null); // reset for the default language (if data was set for a previous language)
8991
return;
9092
}
9193

92-
const useDefaultLanguage = getUseDefaultLanguage();
93-
if (useDefaultLanguage && localeId === DEFAULT_LANGUAGE) {
94-
_setI18nBundleData(packageName, null); // reset for the default language (if data was set for a previous language)
94+
if (!_hasLoader(packageName, localeId)) {
95+
_showAssetsWarningOnce(packageName);
9596
return;
9697
}
9798

packages/base/src/config/Language.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
22
getLanguage as getConfiguredLanguage,
3-
getUseDefaultLanguage as getConfiguredUseDefaultLanguage,
3+
getFetchDefaultLanguage as getConfiguredFetchDefaultLanguage,
44
} from "../InitialConfiguration.js";
55
import { fireLanguageChange } from "../locale/languageChange.js";
66
import { reRenderAllUI5Elements } from "../Render.js";
77

88
let language;
9-
let useDefaultLanguage;
9+
let fetchDefaultLanguage;
1010

1111
/**
1212
* Returns the currently configured language, or the browser language as a fallback
@@ -38,31 +38,31 @@ const setLanguage = async newLanguage => {
3838
};
3939

4040
/**
41-
* Defines if the default language, that is inlined, should be used,
42-
* instead of fetching the language over the network.
43-
* <b>Note:</b> By default the language will be fetched.
41+
* Defines if the default language, that is inlined, should be
42+
* fetched over the network instead of using the inlined one.
43+
* <b>Note:</b> By default the language will not be fetched.
4444
*
45-
* @param {Boolean} useDefaultLanguage
45+
* @param {Boolean} fetchDefaultLanguage
4646
*/
47-
const setUseDefaultLanguage = useDefaultLang => {
48-
useDefaultLanguage = useDefaultLang;
47+
const setFetchDefaultLanguage = fetchDefaultLang => {
48+
fetchDefaultLanguage = fetchDefaultLang;
4949
};
5050

5151
/**
52-
* Returns if the default language, that is inlined, should be used.
52+
* Returns if the default language, that is inlined, should be fetched over the network.
5353
* @returns {Boolean}
5454
*/
55-
const getUseDefaultLanguage = () => {
56-
if (useDefaultLanguage === undefined) {
57-
setUseDefaultLanguage(getConfiguredUseDefaultLanguage());
55+
const getFetchDefaultLanguage = () => {
56+
if (fetchDefaultLanguage === undefined) {
57+
setFetchDefaultLanguage(getConfiguredFetchDefaultLanguage());
5858
}
5959

60-
return useDefaultLanguage;
60+
return fetchDefaultLanguage;
6161
};
6262

6363
export {
6464
getLanguage,
6565
setLanguage,
66-
setUseDefaultLanguage,
67-
getUseDefaultLanguage,
66+
setFetchDefaultLanguage,
67+
getFetchDefaultLanguage,
6868
};

packages/main/bundle.esm.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import getLocaleData from "@ui5/webcomponents-localization/dist/locale/getLocale
2222
// const bg = "https://ui5.sap.com/resources/sap/ui/core/messagebundle_bg.properties";
2323
// registerI18nLoader("@ui5/webcomponents", "bg", async (localeId) => {
2424
// const props = await (await fetch(bg)).text();
25-
// return parse(props);;
25+
// return parse(props);
2626
// });
2727
// registerI18nLoader("@ui5/webcomponents", "fr", async (localeId) => {
2828
// return await (await fetch("fr")).json();
@@ -109,6 +109,7 @@ import { _getRegisteredNames as getIconNames } from "@ui5/webcomponents-base/di
109109
import applyDirection from "@ui5/webcomponents-base/dist/locale/applyDirection.js";
110110
import { attachDirectionChange } from "@ui5/webcomponents-base/dist/locale/directionChange.js";
111111
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
112+
import * as defaultTexts from "./dist/generated/i18n/i18n-defaults.js";
112113

113114
const testAssets = {
114115
configuration : {
@@ -133,6 +134,7 @@ const testAssets = {
133134
detachThemeLoaded,
134135
getIconNames,
135136
renderFinished,
137+
defaultTexts,
136138
};
137139

138140
window["sap-ui-webcomponents-bundle"] = testAssets;

packages/main/test/pages/i18n-defaultLang.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<meta http-equiv="X-UA-Compatible" content="IE=edge">
1111
<meta charset="utf-8">
1212

13-
<!-- The "useDefaultLanguage" is enabled,
14-
the configured default language won't be fetched over the network
13+
<!-- The "fetchDefaultLanguage" is enabled,
14+
the configured default language will be fetched over the network
1515
-->
16-
<script data-ui5-config type="application/json">{"useDefaultLanguage": true}</script>
16+
<script data-ui5-config type="application/json">{"fetchDefaultLanguage": true}</script>
1717

1818
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
1919
<script src="../../resources/bundle.esm.js" type="module"></script>

packages/main/test/specs/DatePicker.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,11 @@ describe("Date Picker Tests", () => {
810810
browser.url("http://localhost:8080/test-resources/pages/DatePicker_test_page.html?sap-ui-language=en");
811811
datepicker.root.setAttribute("primary-calendar-type", "Gregorian");
812812
datepicker.id = "#dp13";
813-
datepicker.openPicker();
814813
datepicker.input.click();
815814
browser.keys("May 3, 2100");
816815
browser.keys("Enter");
816+
// open picker after accepting the date
817+
datepicker.openPicker();
817818

818819
const data = Array.from(datepicker.getDayPickerDatesRow(2));
819820
assert.strictEqual(data[0].getAttribute("aria-label"), "Calendar Week 18", "First columnheader have Week number aria-label");

packages/main/test/specs/MultiComboBox.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,23 @@ describe("MultiComboBox general interaction", () => {
268268
const inivisbleTextId = invisibleText.getProperty("id");
269269
let tokens = mcb.shadow$$(".ui5-multi-combobox-token");
270270
let resourceBundleText = null;
271-
271+
272272
assert.strictEqual(tokens.length, 2, "should have two tokens");
273273
assert.strictEqual(innerInput.getAttribute("aria-describedby"), inivisbleTextId, "aria-describedby reference is correct");
274274
assert.strictEqual(invisibleText.getText(), "Contains 2 tokens", "aria-describedby text is correct");
275-
275+
276276
mcb.scrollIntoView();
277277
innerInput.click();
278278
innerInput.keys("Backspace");
279279
innerInput.keys("Backspace");
280280

281281
tokens = mcb.shadow$$(".ui5-multi-combobox-token");
282-
282+
283283
resourceBundleText = browser.execute(() => {
284284
const mcb = document.getElementById("mcb-compact");
285-
return mcb.i18nBundle.getText("TOKENIZER_ARIA_CONTAIN_ONE_TOKEN");
285+
return mcb.i18nBundle.getText(window["sap-ui-webcomponents-bundle"].defaultTexts.TOKENIZER_ARIA_CONTAIN_ONE_TOKEN);
286286
});
287-
287+
288288
assert.strictEqual(tokens.length, 1, "should have one token");
289289
assert.strictEqual(invisibleText.getText(), resourceBundleText, "aria-describedby text is correct");
290290

@@ -293,7 +293,7 @@ describe("MultiComboBox general interaction", () => {
293293
tokens = mcb.shadow$$(".ui5-multi-combobox-token");
294294
resourceBundleText = browser.execute(() => {
295295
const mcb = document.getElementById("mcb-compact");
296-
return mcb.i18nBundle.getText("TOKENIZER_ARIA_CONTAIN_TOKEN");
296+
return mcb.i18nBundle.getText(window["sap-ui-webcomponents-bundle"].defaultTexts.TOKENIZER_ARIA_CONTAIN_TOKEN);
297297
});
298298

299299
assert.strictEqual(tokens.length, 0, "should not have tokens");

packages/main/test/specs/MultiInput.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe("ARIA attributes", () => {
144144

145145
resourceBundleText = browser.execute(() => {
146146
const mi = document.getElementById("no-tokens");
147-
return mi.i18nBundle.getText("TOKENIZER_ARIA_CONTAIN_TOKEN");
147+
return mi.i18nBundle.getText(window["sap-ui-webcomponents-bundle"].defaultTexts.TOKENIZER_ARIA_CONTAIN_TOKEN);
148148
});
149149

150150
assert.strictEqual(mi.$$("ui5-token").length, 0, "should not have tokens");
@@ -156,7 +156,7 @@ describe("ARIA attributes", () => {
156156

157157
resourceBundleText = browser.execute(() => {
158158
const mi = document.getElementById("no-tokens");
159-
return mi.i18nBundle.getText("TOKENIZER_ARIA_CONTAIN_ONE_TOKEN");
159+
return mi.i18nBundle.getText(window["sap-ui-webcomponents-bundle"].defaultTexts.TOKENIZER_ARIA_CONTAIN_ONE_TOKEN);
160160
});
161161

162162
assert.strictEqual(mi.$$("ui5-token").length, 1, "should have one token");

packages/tools/components-package/nps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const getScripts = (options) => {
7070
test: {
7171
// --success first - report the exit code of the test run (first command to finish), as serve is always terminated and has a non-0 exit code
7272
default: 'concurrently "nps serve" "nps test.run" --kill-others --success first',
73-
run: "cross-env WDIO_LOG_LEVEL=error FORCE_COLOR=0 wdio config/wdio.conf.js",
73+
run: "cross-env WDIO_LOG_LEVEL=error wdio config/wdio.conf.js",
7474
spec: "wdio run config/wdio.conf.js",
7575
},
7676
startWithScope: "nps scope.prepare scope.dev",

0 commit comments

Comments
 (0)