##// END OF EJS Templates
corrected i18n, css modules to support requirejs optimizer...
corrected i18n, css modules to support requirejs optimizer i18n bundles now conforms js modules with default exports (breaking change!)

File last commit:

r53:deb0ed6fb680 v1.0.7 default
r53:deb0ed6fb680 v1.0.7 default
Show More
i18n.ts
38 lines | 1015 B | video/mp2t | TypeScriptLexer
import { MapOf } from "@implab/core-amd/interfaces";
import { NlsBundle } from "./NlsBundle";
import { isPromise } from "@implab/core-amd/safe";
export 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 = nlsBundle.getLocale(locale);
if (isPromise(result))
throw new Error(`The bundle '${locale}' isn't loaded`);
else
return result;
};
fn.define = (pack: Partial<T>) => pack;
fn.load = async (id: string, require: Require, cb: OnLoad, config: any) => {
if (config && config.isBuild) {
cb();
} else {
try {
await nlsBundle.getLocale(id);
cb();
} catch (e) {
if(cb.error)
cb.error(e);
}
}
};
return fn;
}