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

Update I18n modules to support loading automatically bundled CLDR data #657

Merged
merged 26 commits into from
Feb 11, 2020

Conversation

agubler
Copy link
Member

@agubler agubler commented Jan 27, 2020

Type: feature

The following has been addressed in the PR:

Description:

Comprehensive change of i18n support in Dojo; The motivation is to enable automatic detection of CLDR data requirements with lazy loading and resolution of i18n CLDR data bundles. Ensuring that CLDR data automatically included in i18n enables Dojo to remove existing custom locale resolution logic and entirely depend on Globalize for locale resolution.

This should be backwards compatible, unless the downstream application is importing interfaces that are no longer needed (and can be removed) or using the core i18n module directly (which shouldn't be required).

Details:

  1. Expose all i18n message bundle and locale behaviour using reactive patterns from the existing i18n mixin and middleware.
  2. Expose an API for registering CLDR loaders, default locale and other supported locales.
  3. Migrate to using Globalize for all message bundle resolution.
  4. Lazily load required CLDR data using loaders registered with the i18n system.
  5. Fallback to using a complete CLDR supplemental bundle when an unknown locale is used.
  6. Basic i18n support for codesandbox using a util cldr module that loads the required supplemental data (This import will automatically be elided during the Dojo build)
  7. Lazily loading CLDR data when updating a widget's locale through either the global application injector or explicitly via the locale property (support in both the middleware and mixin)

Related to #655

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 449f5dc:

Sandbox Source
dank-mountain-ygze5 Configuration

@agubler agubler force-pushed the refector-i18n branch 2 times, most recently from 55135af to e3fc460 Compare January 28, 2020 22:35
src/i18n/i18n.ts Outdated
Comment on lines 222 to 225
const localCldrLoader = cldrLoaders[userLocale];
if (localCldrLoader && localCldrLoader !== true) {
loaderPromises.push(localCldrLoader());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be changed from localCldrLoader to localeCldrLoader since it's specific to the locale and has nothing to do with the local option?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup absolutely

src/i18n/i18n.ts Outdated
Comment on lines 354 to 361
messages: Object.keys(bundle.messages).reduce(
(messages, key) => {
const message = globalize.cldr.get(`${MESSAGE_BUNDLE_PATH}/${bundleId}/${key}`);
messages[key] = message;
return messages;
},
{} as any
),
Copy link
Contributor

Choose a reason for hiding this comment

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

When called from within middleware/i18n.localize(), will this object be regenerated each time the widget is invalidated? If so, caching the result would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

root.innerHTML,
'<div><div>{"foo":""}</div><div></div><div>true</div><div>{"locale":"es"}</div><button>es</button></div>'
);
es.resolver({ default: { foo: 'holla, {name}' } });
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "hello" in Spanish is "hola" :trollface:

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol Thanks 😄

loadData(frCurrencies);
loadData(frNumbers);
loadData(frUnits);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Just verifying nothing throws?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is used to load data in for the tests, runs in both browser and node.

@agubler
Copy link
Member Author

agubler commented Feb 5, 2020

@mwistrand I think I've addressed your comments

@agubler agubler merged commit 6224e88 into dojo:master Feb 11, 2020
@codecov
Copy link

codecov bot commented Feb 11, 2020

Codecov Report

Merging #657 into master will decrease coverage by 0.25%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #657      +/-   ##
==========================================
- Coverage   98.06%   97.80%   -0.26%     
==========================================
  Files         120      117       -3     
  Lines        6654     6570      -84     
  Branches     1510     1494      -16     
==========================================
- Hits         6525     6426      -99     
- Misses        129      144      +15     
Impacted Files Coverage Δ
src/i18n/util/cldr.ts 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b61c6ff...449f5dc. Read the comment docs.

agubler added a commit to agubler/framework that referenced this pull request Feb 13, 2020
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.

2 participants