Skip to content

Commit

Permalink
[FIX] manifestCreator: set fallbackLocale to empty string if no local…
Browse files Browse the repository at this point in the history
…e is present (#962)

Instead of using a artificial placeholder, you use a real message bundle
file for tests.
  • Loading branch information
flovogt authored Dec 12, 2023
1 parent 3a1874e commit 26526a0
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 12 deletions.
4 changes: 3 additions & 1 deletion lib/processors/manifestCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,11 @@ async function createManifest(

const supportedLocalesArray = Array.from(supportedLocales);
supportedLocalesArray.sort();

return {
bundleUrl: i18n,
supportedLocales: supportedLocalesArray
supportedLocales: supportedLocalesArray,
fallbackLocale: supportedLocalesArray.length === 1 ? supportedLocalesArray[0] : undefined
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<i18n>(i18nPathRelativeToLibrary)</i18n>
<i18n>i18nf/custommessagebundle.properties</i18n>
<offline>false</offline>
<deviceTypes desktop="true" phone="true" tablet="true" />
<supportedTheme>sap_belize</supportedTheme>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mytext=Hello

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"id": "library.i",
"type": "library",
"embeds": [],
"i18n": "(i18nPathRelativeToLibrary)",
"i18n": {
"bundleUrl": "i18nf/custommessagebundle.properties",
"supportedLocales": [
""
],
"fallbackLocale": ""
},
"applicationVersion": {
"version": "1.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<i18n>(i18nPathRelativeToLibrary)</i18n>
<i18n>i18nf/custommessagebundle.properties</i18n>
<offline>false</offline>
<deviceTypes desktop="true" phone="true" tablet="true" />
<supportedTheme>sap_belize</supportedTheme>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mytext=Hello
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"id": "library.i",
"type": "library",
"embeds": [],
"i18n": "(i18nPathRelativeToLibrary)",
"i18n": {
"bundleUrl": "i18nf/custommessagebundle.properties",
"supportedLocales": [
""
],
"fallbackLocale": ""
},
"applicationVersion": {
"version": "1.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<i18n>(i18nPathRelativeToLibrary)</i18n>
<i18n>i18nf/custommessagebundle.properties</i18n>
<offline>false</offline>
<deviceTypes desktop="true" phone="true" tablet="true" />
<supportedTheme>sap_belize</supportedTheme>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mytext=Hello
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"id": "library.i",
"type": "library",
"embeds": [],
"i18n": "(i18nPathRelativeToLibrary)",
"i18n": {
"bundleUrl": "i18nf/custommessagebundle.properties",
"supportedLocales": [
""
],
"fallbackLocale": ""
},
"applicationVersion": {
"version": "1.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/library.i/main/src/library/i/.library
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<i18n>(i18nPathRelativeToLibrary)</i18n>
<i18n>i18nf/custommessagebundle.properties</i18n>
<offline>false</offline>
<deviceTypes desktop="true" phone="true" tablet="true" />
<supportedTheme>sap_belize</supportedTheme>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mytext=Hello
155 changes: 152 additions & 3 deletions test/lib/tasks/generateLibraryManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ test("integration: Library with i18n bundle file (messagebundle.properties)", as
library: {
i18n: {
bundleUrl: "messagebundle.properties",
supportedLocales: [""]
supportedLocales: [""],
fallbackLocale: ""
}
}
},
Expand Down Expand Up @@ -214,7 +215,154 @@ test("integration: Library with i18n=true declared in .library", async (t) => {
library: {
i18n: {
bundleUrl: "messagebundle.properties",
supportedLocales: [""]
supportedLocales: [""],
fallbackLocale: ""
}
}
},
});
});

test("integration: Library with i18n=true declared in .library and multiple locales", async (t) => {
t.context.workspace = createWorkspace();

t.context.resources = [];
t.context.resources.push(createResource({
path: "/resources/test/lib/.library",
string: `
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
<name>test.lib</name>
<vendor>SAP SE</vendor>
<copyright></copyright>
<version>2.0.0</version>
<documentation>Test Lib</documentation>
<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<sap.ui5>
<library>
<i18n>true</i18n>
</library>
</sap.ui5>
</manifest>
</appData>
</library>
`,
project: t.context.workspace._project
}));

t.context.resources.push(createResource({
path: "/resources/test/lib/messagebundle.properties",
project: t.context.workspace._project
}));

t.context.resources.push(createResource({
path: "/resources/test/lib/messagebundle_en.properties",
project: t.context.workspace._project
}));

await assertCreatedManifest(t, {
"_version": "1.21.0",
"sap.app": {
applicationVersion: {
version: "2.0.0",
},
description: "Test Lib",
embeds: [],
id: "test.lib",
offline: true,
resources: "resources.json",
title: "Test Lib",
type: "library",
},
"sap.ui": {
supportedThemes: [],
technology: "UI5",
},
"sap.ui5": {
dependencies: {
libs: {},
minUI5Version: "1.0",
},
library: {
i18n: {
bundleUrl: "messagebundle.properties",
supportedLocales: ["", "en"]
}
}
},
});
});

test("integration: Library with i18n=true declared in .library and single locale", async (t) => {
t.context.workspace = createWorkspace();

t.context.resources = [];
t.context.resources.push(createResource({
path: "/resources/test/lib/.library",
string: `
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
<name>test.lib</name>
<vendor>SAP SE</vendor>
<copyright></copyright>
<version>2.0.0</version>
<documentation>Test Lib</documentation>
<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<sap.ui5>
<library>
<i18n>true</i18n>
</library>
</sap.ui5>
</manifest>
</appData>
</library>
`,
project: t.context.workspace._project
}));

t.context.resources.push(createResource({
path: "/resources/test/lib/messagebundle_de.properties",
project: t.context.workspace._project
}));

await assertCreatedManifest(t, {
"_version": "1.21.0",
"sap.app": {
applicationVersion: {
version: "2.0.0",
},
description: "Test Lib",
embeds: [],
id: "test.lib",
offline: true,
resources: "resources.json",
title: "Test Lib",
type: "library",
},
"sap.ui": {
supportedThemes: [],
technology: "UI5",
},
"sap.ui5": {
dependencies: {
libs: {},
minUI5Version: "1.0",
},
library: {
i18n: {
bundleUrl: "messagebundle.properties",
supportedLocales: ["de"],
fallbackLocale: "de"
}
}
},
Expand Down Expand Up @@ -345,7 +493,8 @@ test("integration: Library with i18n=foo.properties declared in .library", async
library: {
i18n: {
bundleUrl: "foo.properties",
supportedLocales: [""]
supportedLocales: [""],
fallbackLocale: ""
}
}
},
Expand Down

0 comments on commit 26526a0

Please sign in to comment.