@spinajs/intl
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
import { IContainer, ResolveStrategy } from "@spinajs/di"; | ||
import { IContainer, SyncModule } from "@spinajs/di"; | ||
import { Configuration } from '@spinajs/configuration'; | ||
@@ -8,7 +8,7 @@ import { Log } from "@spinajs/log"; | ||
} | ||
export declare abstract class Intl extends ResolveStrategy { | ||
export declare abstract class Intl extends SyncModule { | ||
CurrentLocale: string; | ||
Locales: Map<string, any>; | ||
abstract __(text: string | IPhraseWithOptions, ...args: any[]): string; | ||
abstract __n(text: string, count: number): string; | ||
abstract __n(text: string | IPhraseWithOptions, count: number): string; | ||
abstract __l(text: string): string[]; | ||
@@ -26,5 +26,5 @@ abstract __h(text: string): any[]; | ||
__(text: string | IPhraseWithOptions, ...args: any[]): string; | ||
__n(text: string, count: number): string; | ||
__n(text: string | IPhraseWithOptions, count: number): string; | ||
__l(text: string): string[]; | ||
__h(text: string): any[]; | ||
} |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -8,13 +20,14 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SpineJsInternationalizationFromJson = exports.Intl = void 0; | ||
const di_1 = require("@spinajs/di"); | ||
@@ -32,3 +45,3 @@ const configuration_1 = require("@spinajs/configuration"); | ||
const globalAny = global; | ||
class Intl extends di_1.ResolveStrategy { | ||
class Intl extends di_1.SyncModule { | ||
constructor() { | ||
@@ -50,3 +63,3 @@ super(...arguments); | ||
if (!value) { | ||
throw new exceptions_1.ArgumentException("value cannot be empty or null"); | ||
throw new exceptions_1.InvalidArgument("value cannot be empty or null"); | ||
} | ||
@@ -103,6 +116,19 @@ this._currentLocale = value; | ||
__n(text, count) { | ||
if (/%/.test(text) && this.Locales.has(this.CurrentLocale)) { | ||
const locTable = this.Locales.get(this.CurrentLocale); | ||
const phrase = locTable[text]; | ||
const pluralVerb = MakePlural[this.CurrentLocale](count); | ||
var _a, _b; | ||
let locTable; | ||
let toLocalize; | ||
let locale; | ||
if (_.isString(text)) { | ||
locale = this.CurrentLocale; | ||
locTable = this.Locales.get(this.CurrentLocale); | ||
toLocalize = text; | ||
} | ||
else { | ||
locale = (_a = text.locale) !== null && _a !== void 0 ? _a : this.CurrentLocale; | ||
locTable = (_b = this.Locales.get(text.locale)) !== null && _b !== void 0 ? _b : this.Locales.get(this.CurrentLocale); | ||
toLocalize = text.phrase; | ||
} | ||
if (/%/.test(toLocalize) && this.Locales.has(locale)) { | ||
const phrase = locTable[toLocalize]; | ||
const pluralVerb = MakePlural[locale](count); | ||
if (phrase[pluralVerb]) { | ||
@@ -172,13 +198,13 @@ return util.format(phrase[pluralVerb], count); | ||
globalAny.__ = (text, ...args) => { | ||
return di_1.DI.get('Internationalization').__(text, ...args); | ||
return di_1.DI.get(Intl).__(text, ...args); | ||
}; | ||
globalAny.__n = (text, count) => { | ||
return di_1.DI.get('Internationalization').__n(text, count); | ||
return di_1.DI.get(Intl).__n(text, count); | ||
}; | ||
globalAny.__l = (text) => { | ||
return di_1.DI.get('Internationalization').__l(text); | ||
return di_1.DI.get(Intl).__l(text); | ||
}; | ||
globalAny.__h = (text) => { | ||
return di_1.DI.get('Internationalization').__h(text); | ||
return di_1.DI.get(Intl).__h(text); | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@spinajs/intl", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "spinajs internationalization api", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
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
35475
15
532