Skip to content

Commit

Permalink
clean up the i18n cldr fallback and resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
agubler committed Jan 28, 2020
1 parent b86470b commit e3fc460
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 207 deletions.
10 changes: 5 additions & 5 deletions src/core/middleware/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { localizeBundle, Bundle, Messages, setLocale, getComputedLocale } from '../../i18n/i18n';
import { localizeBundle, Bundle, Messages, setLocale, getCurrentLocale } from '../../i18n/i18n';
import { create, invalidator, getRegistry, diffProperty } from '../vdom';
import injector from './injector';
import Injector from '../Injector';
Expand Down Expand Up @@ -38,18 +38,18 @@ export const i18n = factory(({ properties, middleware: { invalidator, injector,
}
}
if (next.locale && current.locale !== next.locale) {
const result = setLocale(next.locale, true);
const result = setLocale({ locale: next.locale, local: true });
if (isThenable(result)) {
result.then(() => {
invalidator();
});
return current.locale || injectedLocale || getComputedLocale();
return current.locale || injectedLocale || getCurrentLocale();
}
}
if (current.locale !== next.locale) {
invalidator();
}
return next.locale || injectedLocale || getComputedLocale();
return next.locale || injectedLocale || getCurrentLocale();
});

injector.subscribe(INJECTOR_KEY);
Expand Down Expand Up @@ -79,7 +79,7 @@ export const i18n = factory(({ properties, middleware: { invalidator, injector,
const localeDataInjector = injector.get<Injector<LocaleData | undefined>>(INJECTOR_KEY);
if (localeDataInjector) {
if (localeData && localeData.locale) {
const result = setLocale(localeData.locale);
const result = setLocale({ locale: localeData.locale });
if (isThenable(result)) {
result.then(() => {
localeDataInjector.set(localeData);
Expand Down
10 changes: 5 additions & 5 deletions src/core/mixins/I18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* tslint:disable:interface-name */
import { localizeBundle, Bundle, Messages, setLocale, getComputedLocale } from '../../i18n/i18n';
import { localizeBundle, Bundle, Messages, setLocale, getCurrentLocale } from '../../i18n/i18n';
import { isVNode } from './../vdom';
import { afterRender } from './../decorators/afterRender';
import { getInjector } from './../decorators/inject';
Expand Down Expand Up @@ -48,7 +48,7 @@ interface I18nVNodeProperties extends VNodeProperties {
class I18nInjector extends Injector {
set(localeData: LocaleData) {
if (localeData.locale) {
const result = setLocale(localeData.locale);
const result = setLocale({ locale: localeData.locale });
if (isThenable(result)) {
result.then(() => {
super.set(localeData);
Expand Down Expand Up @@ -90,19 +90,19 @@ export function I18nMixin<T extends Constructor<WidgetBase<any>>>(Base: T): T &
previousLocaleMap.set(this, properties.locale);

if (properties.locale && previousLocale !== properties.locale) {
const result = setLocale(properties.locale, true);
const result = setLocale({ locale: properties.locale, local: true });
if (isThenable(result)) {
result.then(() => {
this.invalidate();
});
return {
locale: previousLocale || injectedLocale || getComputedLocale(),
locale: previousLocale || injectedLocale || getCurrentLocale(),
rtl: properties.rtl !== undefined ? properties.rtl : injectedRtl
};
}
}
return {
locale: properties.locale || injectedLocale || getComputedLocale(),
locale: properties.locale || injectedLocale || getCurrentLocale(),
rtl: properties.rtl !== undefined ? properties.rtl : injectedRtl
};
})
Expand Down
Loading

0 comments on commit e3fc460

Please sign in to comment.