##// END OF EJS Templates
Added tag 1.0.0-rc17 for changeset a1a1ef050ecc
Added tag 1.0.0-rc17 for changeset a1a1ef050ecc

File last commit:

r36:a1a1ef050ecc 1.0.0-rc17 default
r37:2e8680269302 default
Show More
i18n.ts
38 lines | 1.0 KiB | video/mp2t | TypeScriptLexer
import { MapOf } from "@implab/core-amd/interfaces";
import { NlsBundle } from "./NlsBundle";
import { isPromise } from "@implab/core-amd/safe";
interface OnLoad {
(result?: any): void;
error(err: any): void;
}
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: OnLoad, config: any) => {
if (config.isBuild) {
cb();
} else {
try {
await nlsBundle.getLocale(id);
cb();
} catch (e) {
cb.error(e);
}
}
};
return fn;
}