##// END OF EJS Templates
Added tag v1.6.2 for changeset bc1b4dd8ca1a
Added tag v1.6.2 for changeset bc1b4dd8ca1a

File last commit:

r120:bc1b4dd8ca1a v1.6.2 default
r121:fa1906afc5a4 default
Show More
i18n.ts
56 lines | 1.8 KiB | video/mp2t | TypeScriptLexer
cin
Converted to subproject djx, removed dojo-typings
r65 import { id as mid} from "module";
cin
type fixes for i18n, store
r120 import { PromiseOrValue } from "@implab/core-amd/interfaces";
import { NlsBundle } from "./NlsBundle";
cin
Converted to subproject djx, removed dojo-typings
r65 import { isPromise } from "@implab/core-amd/safe";
import { locale as sysLocale } from "dojo/_base/kernel";
import { TraceSource } from "@implab/core-amd/log/TraceSource";
const trace = TraceSource.get(mid);
trace.debug("Current sysLocale: {0}", sysLocale);
export interface OnLoad {
cin
linting
r109 (result?: unknown): void;
error(err: unknown): void;
cin
Converted to subproject djx, removed dojo-typings
r65 }
cin
type fixes for i18n, store
r120 export const bundle = <T extends object>(nls: T, locales?: Record<string, () => PromiseOrValue<object>>) : {
i18n: (locale?: string) => T;
define: (pack: Partial<T>) => object;
load: (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => void;
} => {
cin
Converted to subproject djx, removed dojo-typings
r65 const nlsBundle = new NlsBundle(nls, locales);
const fn = (_locale?: string) => {
const locale = _locale || sysLocale;
const result = nlsBundle.getLocale(locale);
if (isPromise(result))
throw new Error(`The bundle '${locale}' isn't loaded`);
else
return result;
};
cin
type fixes for i18n, store
r120 fn.i18n = fn;
fn.define = (pack: Partial<T>): object => pack;
cin
linting
r109 fn.load = async (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => {
cin
Converted to subproject djx, removed dojo-typings
r65 const locale = id || sysLocale;
if (config && config.isBuild) {
cb();
} else {
try {
await nlsBundle.getLocale(locale);
cb();
} catch (e) {
if(cb.error) {
cb.error(e);
} else {
// in case the loader doesn't support error reporting
trace.error("Error loading {0}: {1}", locale, e);
}
}
}
};
return fn;
cin
type fixes for i18n, store
r120 };