bobril-g11n
Advanced tools
Comparing version 2.0.0 to 2.1.0
CHANGELOG | ||
=== | ||
2.1.0 | ||
-- | ||
New features | ||
- | ||
Compilable by TS 2.0 with most strict settings. | ||
2.0.0 | ||
@@ -5,0 +13,0 @@ -- |
@@ -0,0 +0,0 @@ /// <reference path="typings/moment/moment-node.d.ts" /> |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "bobril-g11n", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Bobril globalization", | ||
@@ -19,2 +19,3 @@ "main": "index.js", | ||
"gulp-bump": "*", | ||
"gulp-shell": "^0.5.2", | ||
"gulp-util": "^3.0.6", | ||
@@ -21,0 +22,0 @@ "jasmine-core": "*", |
export declare function extractUsedParams(msgAst: any): string[]; |
@@ -43,3 +43,3 @@ "use strict"; | ||
{ | ||
var style = msgAst.format.style || 'default'; | ||
//let style = msgAst.format.style || 'default'; | ||
var options = msgAst.format.options; | ||
@@ -46,0 +46,0 @@ if (options) { |
@@ -42,3 +42,3 @@ export function extractUsedParams(msgAst: any): string[] { | ||
{ | ||
let style = msgAst.format.style || 'default'; | ||
//let style = msgAst.format.style || 'default'; | ||
let options = msgAst.format.options; | ||
@@ -45,0 +45,0 @@ if (options) { |
export declare function jsonp(url: string): Promise<any>; |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
script.onerror = function (ev) { | ||
script.onerror = function (_ev) { | ||
e('Failed to load ' + url); | ||
@@ -13,0 +13,0 @@ }; |
@@ -9,3 +9,3 @@ export function jsonp(url: string): Promise<any> { | ||
}; | ||
script.onerror = (ev) => { | ||
script.onerror = (_ev) => { | ||
e('Failed to load ' + url); | ||
@@ -12,0 +12,0 @@ }; |
export declare function setPluralRule(locale: string, pluralFn: (val: number, ordinal: boolean) => string): void; | ||
export declare function getLanguageFromLocale(locale: string): string; | ||
export declare function getPluralRule(locale: string): (val: number, ordinal: boolean) => string; |
@@ -14,5 +14,6 @@ "use strict"; | ||
if (d === undefined) { | ||
d = {}; | ||
d = { pluralFn: pluralFn }; | ||
} | ||
d.pluralFn = pluralFn; | ||
else | ||
d.pluralFn = pluralFn; | ||
defs[locale] = d; | ||
@@ -19,0 +20,0 @@ } |
let defs: { | ||
[locale: string]: { | ||
pluralFn?: (val: number, ordinal: boolean) => string, | ||
pluralFn: (val: number, ordinal: boolean) => string, | ||
} | ||
@@ -9,3 +9,3 @@ } = Object.create(null); | ||
pluralFn(n: number, ord: boolean) { | ||
var s = String(n).split("."), v0 = !s[1], t0 = Number(s[0]) == n, n10:any = t0 && s[0].slice(-1), n100:any = t0 && s[0].slice(-2); | ||
var s = String(n).split("."), v0 = !s[1], t0 = Number(s[0]) == n, n10: any = t0 && s[0].slice(-1), n100: any = t0 && s[0].slice(-2); | ||
if (ord) return n10 == 1 && n100 != 11 ? "one" : n10 == 2 && n100 != 12 ? "two" : n10 == 3 && n100 != 13 ? "few" : "other"; return n == 1 && v0 ? "one" : "other" | ||
@@ -18,6 +18,6 @@ } | ||
if (d === undefined) { | ||
d = {}; | ||
} | ||
d.pluralFn = pluralFn; | ||
defs[locale] = <any>d; | ||
d = { pluralFn }; | ||
} else | ||
d.pluralFn = pluralFn; | ||
defs[locale] = d; | ||
} | ||
@@ -24,0 +24,0 @@ |
export declare function parse(text: string): any; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare function compile(locale: string, msgAst: any): (params: Object, hashArg?: string) => string; |
@@ -15,9 +15,9 @@ "use strict"; | ||
if (style === 'default') { | ||
return function (val, opt) { numeral.language(language); return numeral(val).format('0,0.[0000]'); }; | ||
return function (val, _opt) { numeral.language(language); return numeral(val).format('0,0.[0000]'); }; | ||
} | ||
if (style === 'percent') { | ||
return function (val, opt) { numeral.language(language); return numeral(val).format('0%'); }; | ||
return function (val, _opt) { numeral.language(language); return numeral(val).format('0%'); }; | ||
} | ||
if (style === 'bytes') { | ||
return function (val, opt) { numeral.language(language); return numeral(val).format('0b'); }; | ||
return function (val, _opt) { numeral.language(language); return numeral(val).format('0b'); }; | ||
} | ||
@@ -30,3 +30,3 @@ break; | ||
if (options['noago'] === true) { | ||
return function (val, opt) { return moment(val).locale(language).fromNow(true); }; | ||
return function (val, _opt) { return moment(val).locale(language).fromNow(true); }; | ||
} | ||
@@ -36,6 +36,6 @@ if (options['noago'] === null) { | ||
} | ||
return function (val, opt) { return moment(val).locale(language).fromNow(false); }; | ||
return function (val, _opt) { return moment(val).locale(language).fromNow(false); }; | ||
} | ||
if (style === 'calendar') { | ||
return function (val, opt) { return moment(val).locale(language).calendar(); }; | ||
return function (val, _opt) { return moment(val).locale(language).calendar(); }; | ||
} | ||
@@ -45,5 +45,6 @@ if (style === 'custom' && 'format' in options) { | ||
} | ||
return function (val, opt) { return moment(val).locale(language).format(style); }; | ||
return function (val, _opt) { return moment(val).locale(language).format(style); }; | ||
} | ||
} | ||
throw new Error("bad type in AnyFormatter"); | ||
} | ||
@@ -79,3 +80,3 @@ function compile(locale, msgAst) { | ||
case 'hash': | ||
return function (params, hashArg) { | ||
return function (_params, hashArg) { | ||
if (hashArg === undefined) | ||
@@ -186,3 +187,3 @@ return '#'; | ||
else { | ||
var formatFn = comp.addConstant(AnyFormatter(locale, type, style, null)); | ||
var formatFn = comp.addConstant(AnyFormatter(locale, type, style, {})); | ||
comp.addBody("return " + formatFn + "(" + localArg + ");"); | ||
@@ -194,3 +195,4 @@ } | ||
} | ||
throw new Error("invalid AST in compile"); | ||
} | ||
exports.compile = compile; |
@@ -17,9 +17,9 @@ import { RuntimeFunctionGenerator } from './RuntimeFunctionGenerator'; | ||
if (style === 'default') { | ||
return (val, opt) => { numeral.language(language); return numeral(val).format('0,0.[0000]') }; | ||
return (val, _opt) => { numeral.language(language); return numeral(val).format('0,0.[0000]') }; | ||
} | ||
if (style === 'percent') { | ||
return (val, opt) => { numeral.language(language); return numeral(val).format('0%') }; | ||
return (val, _opt) => { numeral.language(language); return numeral(val).format('0%') }; | ||
} | ||
if (style === 'bytes') { | ||
return (val, opt) => { numeral.language(language); return numeral(val).format('0b') }; | ||
return (val, _opt) => { numeral.language(language); return numeral(val).format('0b') }; | ||
} | ||
@@ -32,3 +32,3 @@ break; | ||
if ((<any>options)['noago'] === true) { | ||
return (val, opt) => { return moment(val).locale(language).fromNow(true); }; | ||
return (val, _opt) => { return moment(val).locale(language).fromNow(true); }; | ||
} | ||
@@ -38,6 +38,6 @@ if ((<any>options)['noago'] === null) { | ||
} | ||
return (val, opt) => { return moment(val).locale(language).fromNow(false); }; | ||
return (val, _opt) => { return moment(val).locale(language).fromNow(false); }; | ||
} | ||
if (style === 'calendar') { | ||
return (val, opt) => { return moment(val).locale(language).calendar(); }; | ||
return (val, _opt) => { return moment(val).locale(language).calendar(); }; | ||
} | ||
@@ -47,5 +47,6 @@ if (style === 'custom' && 'format' in options) { | ||
} | ||
return (val, opt) => { return moment(val).locale(language).format(style); }; | ||
return (val, _opt) => { return moment(val).locale(language).format(style); }; | ||
} | ||
} | ||
throw new Error("bad type in AnyFormatter"); | ||
} | ||
@@ -79,3 +80,3 @@ | ||
case 'hash': | ||
return (params, hashArg) => { | ||
return (_params, hashArg) => { | ||
if (hashArg === undefined) return '#'; | ||
@@ -174,3 +175,3 @@ return hashArg; | ||
} else { | ||
let formatFn = comp.addConstant(AnyFormatter(locale, type, style, null)); | ||
let formatFn = comp.addConstant(AnyFormatter(locale, type, style, {})); | ||
comp.addBody(`return ${formatFn}(${localArg});`); | ||
@@ -182,2 +183,3 @@ } | ||
} | ||
throw new Error("invalid AST in compile"); | ||
} |
@@ -0,0 +0,0 @@ export declare class RuntimeFunctionGenerator { |
@@ -0,0 +0,0 @@ "use strict"; |
export interface IG11NConfig { | ||
defaultLocale?: string; | ||
pathToTranslation?: (locale: string) => string; | ||
pathToTranslation?: (locale: string) => string | undefined; | ||
} | ||
export declare function t(message: string | number, params?: Object, translationHelp?: string): string; | ||
export declare function t(message: string | number, params?: Object, _translationHelp?: string): string; | ||
export declare function f(message: string, params: Object): string; | ||
export declare function initGlobalization(config?: IG11NConfig): Promise<any>; | ||
export declare function initGlobalization(config?: IG11NConfig): Promise<void>; | ||
export declare function setLocale(locale: string): Promise<any>; | ||
export declare function getLocale(): string; | ||
export declare function getMoment(): moment.Moment; | ||
export declare function getMoment(init?: any, init2?: any, init3?: any): moment.Moment; | ||
export declare function unformatNumber(str: string): number; | ||
export declare function registerTranslations(locale: string, localeDefs: any[], msgs: string[]): void; |
@@ -9,3 +9,3 @@ "use strict"; | ||
} | ||
var cfg = { defaultLocale: "en-US", pathToTranslation: function () { return null; } }; | ||
var cfg = { defaultLocale: "en-US", pathToTranslation: function () { return undefined; } }; | ||
var loadedLocales = newMap(); | ||
@@ -32,3 +32,3 @@ var registeredTranslations = newMap(); | ||
} | ||
function t(message, params, translationHelp) { | ||
function t(message, params, _translationHelp) { | ||
if (currentLocale.length === 0) { | ||
@@ -103,6 +103,7 @@ throw new Error('before using t you need to wait for initialization of g11n'); | ||
return jsonp_1.jsonp(p_1); | ||
}).then(null, function (e) { | ||
}).catch(function (e) { | ||
console.warn(e); | ||
if (locale != cfg.defaultLocale) | ||
return setLocale(cfg.defaultLocale).then(function () { return Promise.reject(e); }); | ||
return undefined; | ||
}); | ||
@@ -109,0 +110,0 @@ } |
@@ -13,3 +13,3 @@ import * as msgFormatParser from "./msgFormatParser"; | ||
defaultLocale?: string; | ||
pathToTranslation?: (locale: string) => string; | ||
pathToTranslation?: (locale: string) => string | undefined; | ||
} | ||
@@ -25,3 +25,3 @@ | ||
let cfg: IG11NConfig = { defaultLocale: "en-US", pathToTranslation: () => null }; | ||
let cfg: IG11NConfig = { defaultLocale: "en-US", pathToTranslation: () => undefined }; | ||
let loadedLocales: { [name: string]: boolean } = newMap(); | ||
@@ -52,3 +52,3 @@ let registeredTranslations: { [name: string]: string[] } = newMap(); | ||
export function t(message: string | number, params?: Object, translationHelp?: string): string { | ||
export function t(message: string | number, params?: Object, _translationHelp?: string): string { | ||
if (currentLocale.length === 0) { | ||
@@ -91,3 +91,3 @@ throw new Error('before using t you need to wait for initialization of g11n'); | ||
let initPromise = Promise.resolve<any>(null); | ||
initPromise = initPromise.then(() => setLocale(cfg.defaultLocale)); | ||
initPromise = initPromise.then(() => setLocale(cfg.defaultLocale!)); | ||
b.setBeforeInit((cb: (_: any) => void) => { | ||
@@ -107,3 +107,3 @@ initPromise.then(cb, cb); | ||
} | ||
return setLocale(cfg.defaultLocale); | ||
return setLocale(cfg.defaultLocale!); | ||
} | ||
@@ -123,7 +123,8 @@ return initPromise; | ||
prom = prom.then(() => { | ||
return jsonp(p); | ||
}).then(null, (e) => { | ||
return jsonp(p!); | ||
}).catch((e) => { | ||
console.warn(e); | ||
if (locale != cfg.defaultLocale) | ||
return setLocale(cfg.defaultLocale).then(() => Promise.reject(e)); | ||
return setLocale(cfg.defaultLocale!).then(() => Promise.reject(e)); | ||
return undefined; | ||
}); | ||
@@ -130,0 +131,0 @@ } |
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"lib": [ | ||
"es5", | ||
"dom", | ||
"es2015.core", | ||
"es2015.promise" | ||
], | ||
"removeComments": false, | ||
"noLib": false | ||
"noLib": false, | ||
"preserveConstEnums": false, | ||
"strictNullChecks": true | ||
}, | ||
"compileOnSave": false, | ||
"filesGlob": [ | ||
"include": [ | ||
"./index.ts", | ||
@@ -17,31 +31,7 @@ "./src/*.ts", | ||
"./typings/numeral/numeral.d.ts", | ||
"./typings/jasmine/jasmine.d.ts", | ||
"./node_modules/typescript/lib/typescript.d.ts" | ||
"./typings/jasmine/jasmine.d.ts" | ||
], | ||
"files": [ | ||
"./index.ts", | ||
"./src/RuntimeFunctionGenerator.d.ts", | ||
"./src/RuntimeFunctionGenerator.ts", | ||
"./src/jsonp.d.ts", | ||
"./src/jsonp.ts", | ||
"./src/localeDataStorage.d.ts", | ||
"./src/localeDataStorage.ts", | ||
"./src/msgFormatParser.d.ts", | ||
"./src/msgFormatParser.ts", | ||
"./src/msgFormatter.d.ts", | ||
"./src/msgFormatter.ts", | ||
"./src/translate.d.ts", | ||
"./src/translate.ts", | ||
"./src/extractUsedParams.ts", | ||
"./test/msgFormatParserSpec.d.ts", | ||
"./test/msgFormatParserSpec.ts", | ||
"./test/msgFormatterSpec.d.ts", | ||
"./test/msgFormatterSpec.ts", | ||
"./test/extractUsedParamsSpec.ts", | ||
"./test/translateSpec.ts", | ||
"./typings/moment/moment-node.d.ts", | ||
"./typings/numeral/numeral.d.ts", | ||
"./typings/jasmine/jasmine.d.ts", | ||
"./node_modules/typescript/lib/typescript.d.ts" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170411
15
3933