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

i18n middleware format function could be typed by message keys #591

Closed
JamesLMilner opened this issue Nov 28, 2019 · 0 comments · Fixed by #610
Closed

i18n middleware format function could be typed by message keys #591

JamesLMilner opened this issue Nov 28, 2019 · 0 comments · Fixed by #610
Labels
area: i18n Internationalisation enhancement New feature or request

Comments

@JamesLMilner
Copy link
Contributor

JamesLMilner commented Nov 28, 2019

Enhancement

The format function in the i18n middleware is currently typed as (key: string, options?: any):

https://github.com/dojo/framework/blob/master/src/core/middleware/i18n.ts#L94

It would be useful to be able to ensure that the key argument was a type of the key of the messages in the bundle to prevent passing invalid key property.

Package Version: 7.0.0-pre

Code

Assume an .nls file as such:

const messages = {
     foosAvailable: '{num} are available'
};

export default { messages };

A widget with this behaviour in the render

const { messages, format } = i18n.localize(bundle);
// Later on
format('barsAvailable', { num: bars.length })}

Expected behavior:

A type error occurs when using a no message bundle key.

Actual behavior:

There is no type error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: i18n Internationalisation enhancement New feature or request
Projects
None yet
2 participants