##// END OF EJS Templates
Added tag v1.0.0-rc7 for changeset 9e546fe36fdd
Added tag v1.0.0-rc7 for changeset 9e546fe36fdd

File last commit:

r2:8ec37bf1b4d1 default
r18:8419ebe3b63d default
Show More
i18n.ts
29 lines | 878 B | video/mp2t | TypeScriptLexer
import { MapOf } from "@implab/core-amd/interfaces";
import { NlsBundle } from "./NlsBundle";
import { isPromise } from "@implab/core-amd/safe";
export function bundle<T extends object>(nls: T, locales?: MapOf<any>) {
const nlsBundle = new NlsBundle(nls, locales);
const fn = (locale?: string) => {
const result = locale ? nlsBundle.getLocale(locale) : nlsBundle.default;
if (isPromise(result))
throw new Error(`The bundle '${locale}' isn't loaded`);
else
return result;
};
fn.define = (pack: Partial<T>) => pack;
fn.default = nlsBundle.default;
fn.load = async (id: string, require: Require, cb: { (): void; error: (arg0: any) => void; }) => {
try {
await nlsBundle.getLocale(id);
cb();
} catch (e) {
cb.error(e);
}
};
return fn;
}