Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] manifestCreator: enrich manifest with supportedLocales in i18n (for libraries) #547

Merged
merged 13 commits into from
Jan 14, 2021

Conversation

tobiasso85
Copy link
Contributor

@tobiasso85 tobiasso85 commented Nov 20, 2020

With app descriptor v22 (1.21.0) the i18n sections in the manifest can be an object
with:

  • bundleUrl
  • supportedLocales

This change reads the provided properties files and automatically creates the supportedLocales
array based on this information.

e.g.

files:

  • i18n/i18n.properties
  • i18n/i18n_de.properties
  • i18n/i18n_en.properties

snippet in manifest.json

"i18n": {
      "bundleUrl": "i18n/i18n.properties",
      "supportedLocales": [
        "",
        "de",
        "en"
      ]
    },

@coveralls
Copy link

coveralls commented Nov 20, 2020

Coverage Status

Coverage increased (+0.3%) to 93.546% when pulling d6e7c64 on manifest-creator-supported-locales into 1b7a277 on master.

@tobiasso85 tobiasso85 changed the title [FEATURE] manifestCreator: i18n section v22 [FEATURE] manifestCreator: enrich manifest with supportedLocales in i18n Nov 20, 2020
@tobiasso85 tobiasso85 force-pushed the manifest-creator-supported-locales branch 2 times, most recently from ba9f72b to 745509b Compare December 1, 2020 09:21
@ecker ecker changed the title [FEATURE] manifestCreator: enrich manifest with supportedLocales in i18n [FEATURE] manifestCreator: enrich manifest with supportedLocales in i18n (for libraries) Dec 2, 2020
t.is(verboseLogStub.getCall(1).args[1], "/resources/sap/apf");
});

test.serial("manifest creation for sap/ui/core", async (t) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed by accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restored with:
535668a

} else {
return false;
}
}
// i18n can be an empty string therefore check for not being null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for an empty string createI18nSection returns false anyways. Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tackled with: 8eaf458

* <code>null</code> if given i18n String is <code>null</code>
*/
function createI18nSection(i18n, i18nToSupportedLocales) {
if (!i18n) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this handles the empty string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tackled with: 8eaf458

supportedLocales.add("");
}
const i18nPatternStr = i18n.substring(0, i18n.length - ".properties".length);
const i18nRegexp = new RegExp(i18nPatternStr + "_([^.]+)\\.properties$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does i18nPatternStr need to be encoded for RegExp or can we be sure that it doesn't contain special characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tackled with: f649422

i18nToSupportedLocales.set(i18n, supportedLocales);
}

const supportedLocalesArray = [...supportedLocales];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is fine to convert the Set to an Array I think Array.from(supportedLocales) would be easier to understand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I like the spread operator more, but that's a matter of taste.

With both ways, I anyhow struggle with the details of iteration (whether it iterates entries - like for Object.entries or Map's default iterator - or only values).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed with: c90b9a4

@tobiasso85 tobiasso85 force-pushed the manifest-creator-supported-locales branch from ff9521e to 53986f9 Compare December 23, 2020 09:20
@tobiasso85 tobiasso85 requested a review from matz3 December 23, 2020 09:58
With app descriptor v22 (1.21.0)
the i18n sections in the manifest are objects
with:
* bundleUrl
* supportedLocales
Improve i18n language extraction code by avoiding regexp
avoid duplicate check for null because createI18nSection()
also performs an existence check
changed to Array.from instead of spread operator.
and is reflected as such in the manifest.json
"i18n": ""
@tobiasso85 tobiasso85 force-pushed the manifest-creator-supported-locales branch from b651ad1 to fdec47a Compare January 8, 2021 11:07
Add "return" after "reject() call", because a promise should either reject or resovle.
@tobiasso85 tobiasso85 merged commit 8102034 into master Jan 14, 2021
@tobiasso85 tobiasso85 deleted the manifest-creator-supported-locales branch January 14, 2021 13:19
kristian added a commit to kristian/ui5-builder that referenced this pull request Aug 21, 2021
kristian added a commit to kristian/ui5-builder that referenced this pull request Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants