Comparing version 1.1.19 to 1.1.20
@@ -11,2 +11,4 @@ export interface StringsMap { | ||
export declare class Intl { | ||
private static currentLocale; | ||
private static categories; | ||
static setLocale: (value: string) => "ru-ru"; | ||
@@ -13,0 +15,0 @@ static t: (category: string, key: string) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var defaultLocale = 'ru-ru'; | ||
var currentLocale = defaultLocale; | ||
var categories = {}; | ||
var locale = function (value) { | ||
if (value == "en" || value == "en-us" || value == "en-uk") { | ||
currentLocale = 'en-us'; | ||
var Intl = (function () { | ||
function Intl() { | ||
} | ||
currentLocale = 'ru-ru'; | ||
return currentLocale; | ||
}; | ||
var register = function (category, strings) { | ||
if (!categories[category]) { | ||
categories[category] = strings; | ||
} | ||
else { | ||
for (var lang in strings) { | ||
if (!categories[category][lang]) { | ||
categories[category][lang] = {}; | ||
Intl.currentLocale = defaultLocale; | ||
Intl.categories = {}; | ||
Intl.setLocale = function (value) { | ||
if (value == "en" || value == "en-us" || value == "en-uk") { | ||
Intl.currentLocale = 'en-us'; | ||
} | ||
Intl.currentLocale = 'ru-ru'; | ||
return Intl.currentLocale; | ||
}; | ||
Intl.t = function (category, key) { | ||
var result = Intl.categories[category][Intl.currentLocale][key]; | ||
if (!result) { | ||
result = Intl.categories[category][defaultLocale][key]; | ||
} | ||
return result; | ||
}; | ||
Intl.ts = function (category, key) { | ||
var result = Intl.categories[category][Intl.currentLocale][key]; | ||
if (!result) { | ||
result = Intl.categories[category][defaultLocale][key]; | ||
} | ||
return result; | ||
}; | ||
Intl.registerStrings = function (category, strings) { | ||
if (!Intl.categories[category]) { | ||
Intl.categories[category] = strings; | ||
} | ||
else { | ||
for (var lang in strings) { | ||
if (!Intl.categories[category][lang]) { | ||
Intl.categories[category][lang] = {}; | ||
} | ||
var langCat = strings[lang]; | ||
for (var key in langCat) { | ||
Intl.categories[category][lang][key] = langCat[key]; | ||
} | ||
} | ||
var langCat = strings[lang]; | ||
for (var key in langCat) { | ||
categories[category][lang][key] = langCat[key]; | ||
} | ||
} | ||
} | ||
}; | ||
var t = function (category, key) { | ||
var result = categories[category][currentLocale][key]; | ||
if (!result) { | ||
result = categories[category][defaultLocale][key]; | ||
} | ||
return result; | ||
}; | ||
var ts = function (category, key) { | ||
var result = categories[category][currentLocale][key]; | ||
if (!result) { | ||
result = categories[category][defaultLocale][key]; | ||
} | ||
return result; | ||
}; | ||
var Intl = (function () { | ||
function Intl() { | ||
} | ||
Intl.setLocale = locale; | ||
Intl.t = t; | ||
Intl.ts = ts; | ||
Intl.registerStrings = register; | ||
}; | ||
return Intl; | ||
@@ -51,0 +47,0 @@ }()); |
{ | ||
"name": "onix-core", | ||
"version": "1.1.19", | ||
"version": "1.1.20", | ||
"description": "Onix library core", | ||
@@ -5,0 +5,0 @@ "main": "built/index.js", |
@@ -17,61 +17,53 @@ declare type Locales = 'ru-ru' | 'en-us'; | ||
const defaultLocale: Locales = 'ru-ru'; | ||
let currentLocale: Locales = defaultLocale; | ||
let categories: Strings = {}; | ||
const locale = (value: string) => { | ||
if (value=="en" || value=="en-us" || value=="en-uk") { | ||
currentLocale = 'en-us'; | ||
} | ||
export class Intl { | ||
private static currentLocale: Locales = defaultLocale; | ||
private static categories: Strings = {}; | ||
currentLocale = 'ru-ru'; | ||
public static setLocale = (value: string) => { | ||
if (value=="en" || value=="en-us" || value=="en-uk") { | ||
Intl.currentLocale = 'en-us'; | ||
} | ||
return currentLocale; | ||
} | ||
Intl.currentLocale = 'ru-ru'; | ||
const register = (category: string, strings: StringsCategory) => { | ||
if (!categories[category]) { | ||
categories[category] = strings; | ||
} else { | ||
for (const lang in strings) { | ||
if (!categories[category][lang]) { | ||
categories[category][lang] = {}; | ||
} | ||
return Intl.currentLocale; | ||
}; | ||
const langCat = strings[lang]; | ||
for (const key in langCat) { | ||
categories[category][lang][key] = langCat[key]; | ||
} | ||
public static t = (category: string, key: string) => { | ||
let result = <string>Intl.categories[category][Intl.currentLocale][key]; | ||
if (!result) { | ||
result = <string>Intl.categories[category][defaultLocale][key]; | ||
} | ||
} | ||
} | ||
const t = (category: string, key: string) => { | ||
let result = <string>categories[category][currentLocale][key]; | ||
if (!result) { | ||
result = <string>categories[category][defaultLocale][key]; | ||
} | ||
return result; | ||
}; | ||
return result; | ||
} | ||
public static ts = (category: string, key: string) => { | ||
let result = <string[]>Intl.categories[category][Intl.currentLocale][key]; | ||
if (!result) { | ||
result = <string[]>Intl.categories[category][defaultLocale][key]; | ||
} | ||
const ts = (category: string, key: string) => { | ||
let result = <string[]>categories[category][currentLocale][key]; | ||
if (!result) { | ||
result = <string[]>categories[category][defaultLocale][key]; | ||
} | ||
return result; | ||
}; | ||
return result; | ||
} | ||
public static registerStrings = (category: string, strings: StringsCategory) => { | ||
if (!Intl.categories[category]) { | ||
Intl.categories[category] = strings; | ||
} else { | ||
for (const lang in strings) { | ||
if (!Intl.categories[category][lang]) { | ||
Intl.categories[category][lang] = {}; | ||
} | ||
export class Intl { | ||
public static setLocale = locale; | ||
public static t = t; | ||
public static ts = ts; | ||
public static registerStrings = register; | ||
const langCat = strings[lang]; | ||
for (const key in langCat) { | ||
Intl.categories[category][lang][key] = langCat[key]; | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
Intl.setLocale(window.navigator.language); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
1509268
21486