Comparing version 1.1.21 to 1.1.22
@@ -14,2 +14,4 @@ export interface StringsMap { | ||
static setLocale: (value: string) => "ru-ru"; | ||
private static safeT; | ||
private static safeTS; | ||
static t: (category: string, key: string) => string; | ||
@@ -16,0 +18,0 @@ static ts: (category: string, key: string) => string[]; |
@@ -16,6 +16,20 @@ "use strict"; | ||
}; | ||
Intl.safeT = function (category, locale, key) { | ||
var result = null; | ||
if (Intl.categories[category] && Intl.categories[category][locale]) { | ||
result = Intl.categories[category][locale][key]; | ||
} | ||
return result; | ||
}; | ||
Intl.safeTS = function (category, locale, key) { | ||
var result = null; | ||
if (Intl.categories[category] && Intl.categories[category][locale]) { | ||
result = Intl.categories[category][locale][key]; | ||
} | ||
return result; | ||
}; | ||
Intl.t = function (category, key) { | ||
var result = Intl.categories[category][Intl.currentLocale][key]; | ||
var result = Intl.safeT(category, Intl.currentLocale, key); | ||
if (!result) { | ||
result = Intl.categories[category][defaultLocale][key]; | ||
result = Intl.safeT(category, defaultLocale, key); | ||
} | ||
@@ -25,5 +39,5 @@ return result; | ||
Intl.ts = function (category, key) { | ||
var result = Intl.categories[category][Intl.currentLocale][key]; | ||
var result = Intl.safeTS(category, Intl.currentLocale, key); | ||
if (!result) { | ||
result = Intl.categories[category][defaultLocale][key]; | ||
result = Intl.safeTS(category, defaultLocale, key); | ||
} | ||
@@ -30,0 +44,0 @@ return result; |
{ | ||
"name": "onix-core", | ||
"version": "1.1.21", | ||
"version": "1.1.22", | ||
"description": "Onix library core", | ||
@@ -5,0 +5,0 @@ "main": "built/index.js", |
@@ -32,6 +32,24 @@ declare type Locales = 'ru-ru' | 'en-us'; | ||
private static safeT = (category: string, locale: string, key: string) => { | ||
let result: string = null; | ||
if (Intl.categories[category] && Intl.categories[category][locale]) { | ||
result = <string>Intl.categories[category][locale][key]; | ||
} | ||
return result; | ||
}; | ||
private static safeTS = (category: string, locale: string, key: string) => { | ||
let result: string[] = null; | ||
if (Intl.categories[category] && Intl.categories[category][locale]) { | ||
result = <string[]>Intl.categories[category][locale][key]; | ||
} | ||
return result; | ||
}; | ||
public static t = (category: string, key: string) => { | ||
let result = <string>Intl.categories[category][Intl.currentLocale][key]; | ||
let result = Intl.safeT(category, Intl.currentLocale, key); | ||
if (!result) { | ||
result = <string>Intl.categories[category][defaultLocale][key]; | ||
result = Intl.safeT(category, defaultLocale, key); | ||
} | ||
@@ -43,5 +61,5 @@ | ||
public static ts = (category: string, key: string) => { | ||
let result = <string[]>Intl.categories[category][Intl.currentLocale][key]; | ||
let result = Intl.safeTS(category, Intl.currentLocale, key); | ||
if (!result) { | ||
result = <string[]>Intl.categories[category][defaultLocale][key]; | ||
result = Intl.safeTS(category, defaultLocale, key); | ||
} | ||
@@ -48,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1511707
21538