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 46fbfc9
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 206 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
38 changes: 38 additions & 0 deletions blah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require('cldrjs/dist/cldr/unresolved');
const Globalize = require('globalize/dist/globalize/message');
const Cldr = require('cldrjs/dist/cldr');

let resolved = {};

// Object.defineProperty(Cldr, '_raw', {
// get() {
// return { ...raw };
// },
// set(value) {
// raw = { ...value };
// }
// });

// Object.defineProperty(Cldr, '_resolved', {
// get() {
// return { ...resolved };
// },
// set(value) {
// resolved = { ...value };
// }
// });

Globalize.load(require('cldr-data/supplemental/likelySubtags'));

Globalize.loadMessages({
root: { todos: 'root todo', fallback: 'root fallback' },
'en-GB': { todos: 'bonjour' }
});

let fallback = Globalize('en-GB').cldr.get(`globalize-messages/{bundle}/fallback`);
console.log('whatever the fallback is', fallback);
Globalize.loadMessages({
en: { todos: 'lol', fallback: 'yay' }
});
fallback = Globalize('en-GB').cldr.get(`globalize-messages/{bundle}/fallback`);
console.log('still whatever the fallback is and not yay', fallback);
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 46fbfc9

Please sign in to comment.