Skip to content

[core] Extend core/i18n substates with actions to set schema and uischema#1181

Merged
edgarmueller merged 2 commits intoeclipsesource:masterfrom
edgarmueller:feature/core/i18n
Dec 12, 2018
Merged

[core] Extend core/i18n substates with actions to set schema and uischema#1181
edgarmueller merged 2 commits intoeclipsesource:masterfrom
edgarmueller:feature/core/i18n

Conversation

@edgarmueller
Copy link
Contributor

@edgarmueller edgarmueller commented Nov 29, 2018

This PR introduces changes that are meant to be used in the following fashion:

During initialization one is ought to register the respective localized versions of the schema/UI schemas, e.g.:

const localizedSchemas = new Map<string, JsonSchema>();
localizedSchemas.set('de-DE', deSchema);
localizedSchemas.set('en-US', usSchema);
store.dispatch(Actions.setLocalizedSchemas(localizedSchemas));

Likewise for UI schemas.

Then, within the locale switcher of the respective app (which needs to be custom anyway, I think), locales can be switched via the new actions (this could be probably be improved a bit since we need to pass the entire state ATM):

changeLocale(locale: string) {
  store.dispatch(setLocale(locale));
  store.dispatch(setSchema(getLocalizedSchema(locale)(store.getState())));
  store.dispatch(setUISchema(getLocalizedUISchema(locale)(store.getState())));
}

This will cause the root schema/UI schema to be updated and hence the entire forms managed by JSON Forms will be re-rendered with the new schema/UI schema

@coveralls
Copy link

coveralls commented Nov 29, 2018

Coverage Status

Coverage decreased (-0.5%) to 87.504% when pulling bd5dd39 on edgarmueller:feature/core/i18n into 2ba0316 on eclipsesource:master.

@eneufeld
Copy link
Member

would it make sense to extend the examples in order to try this feature out?

@edgarmueller
Copy link
Contributor Author

I'll add the example code I've tested with

Copy link
Member

@eneufeld eneufeld left a comment

Choose a reason for hiding this comment

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

Awesome

@edgarmueller edgarmueller merged commit 91a681c into eclipsesource:master Dec 12, 2018
@edgarmueller edgarmueller changed the title [feedback wanted] Extend core/i18n substates with actions to set schema and uischema Extend core/i18n substates with actions to set schema and uischema Dec 12, 2018
@edgarmueller edgarmueller changed the title Extend core/i18n substates with actions to set schema and uischema [core] Extend core/i18n substates with actions to set schema and uischema Dec 12, 2018
@edgarmueller edgarmueller added this to the 2.1.0 milestone Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants