Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@spinajs/intl

Package Overview
Dependencies
Maintainers
1
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spinajs/intl - npm Package Compare versions

Comparing version 2.0.46 to 2.0.48

lib/config/locales.d.ts.map

1

lib/config/locales.d.ts

@@ -13,1 +13,2 @@ /**

export default config;
//# sourceMappingURL=locales.d.ts.map

4

lib/config/locales.js

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -16,3 +14,3 @@ * Localisation configuration, structure like in

};
exports.default = config;
export default config;
//# sourceMappingURL=locales.js.map
import { AsyncService } from '@spinajs/di';
import { Configuration } from '@spinajs/configuration';
import { Log } from '@spinajs/log';
export * from './sources';
export * from './sources.js';
export interface IPhraseWithOptions {

@@ -112,1 +112,2 @@ phrase: string;

export declare function defaultLanguage(): string;
//# sourceMappingURL=index.d.ts.map

@@ -1,18 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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) {

@@ -24,30 +7,18 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
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.defaultLanguage = exports.guessLanguage = exports.__translateH = exports.__translateL = exports.__translateNumber = exports.__translate = exports.SpineJsInternationalizationFromJson = exports.Intl = void 0;
const node_async_hooks_1 = require("node:async_hooks");
const di_1 = require("@spinajs/di");
const configuration_1 = require("@spinajs/configuration");
const log_1 = require("@spinajs/log");
const exceptions_1 = require("@spinajs/exceptions");
const _ = __importStar(require("lodash"));
const util = __importStar(require("util"));
const MakePlural = __importStar(require("make-plural"));
const InvervalParser = __importStar(require("math-interval-parser"));
const TranslatioSources = __importStar(require("./sources"));
__exportStar(require("./sources"), exports);
import { AsyncLocalStorage } from 'node:async_hooks';
import { Injectable, AsyncService, Autoinject, DI } from '@spinajs/di';
import { Configuration } from '@spinajs/configuration';
import { Log, Logger } from '@spinajs/log';
import { InvalidArgument } from '../../exceptions/lib/index.js';
import _ from 'lodash';
import * as util from 'util';
import * as MakePlural from 'make-plural';
import intervalParse from 'math-interval-parser';
import * as TranslatioSources from './sources.js';
export * from './sources.js';
const globalAny = global;
class Intl extends di_1.AsyncService {
export class Intl extends AsyncService {
constructor() {

@@ -71,3 +42,3 @@ super(...arguments);

if (!value) {
throw new exceptions_1.InvalidArgument('value cannot be empty or null');
throw new InvalidArgument('value cannot be empty or null');
}

@@ -77,3 +48,2 @@ this._currentLocale = value;

}
exports.Intl = Intl;
/**

@@ -94,3 +64,3 @@ * Basic internationalization support. Text phrases are read from json files specified

this.CurrentLocale = this.Configuration.get('intl.defaultLocale', 'en');
const sources = await di_1.DI.resolve(Array.ofType(TranslatioSources.TranslationSource));
const sources = await DI.resolve(Array.ofType(TranslatioSources.TranslationSource));
for (const s of sources) {

@@ -110,3 +80,2 @@ const translations = await s.load();

__(text, ...args) {
var _a, _b;
let locTable;

@@ -121,3 +90,3 @@ let toLocalize;

else {
locTable = (_a = this.Locales[text.locale]) !== null && _a !== void 0 ? _a : this.Locales[this.CurrentLocale];
locTable = this.Locales[text.locale] ?? this.Locales[this.CurrentLocale];
toLocalize = text.phrase;

@@ -128,3 +97,3 @@ }

}
return util.format((_b = locTable[toLocalize]) !== null && _b !== void 0 ? _b : toLocalize, ...args);
return util.format(locTable[toLocalize] ?? toLocalize, ...args);
}

@@ -140,3 +109,2 @@ /**

__n(text, count) {
var _a, _b;
let locTable;

@@ -153,4 +121,4 @@ let toLocalize;

else {
locale = (_a = text.locale) !== null && _a !== void 0 ? _a : this.CurrentLocale;
locTable = (_b = this.Locales[text.locale]) !== null && _b !== void 0 ? _b : this.Locales[this.CurrentLocale];
locale = text.locale ?? this.CurrentLocale;
locTable = this.Locales[text.locale] ?? this.Locales[this.CurrentLocale];
toLocalize = text.phrase;

@@ -193,3 +161,3 @@ }

function _matchInterval(c, eq) {
const interval = InvervalParser.default(eq);
const interval = intervalParse.default(eq);
if (interval) {

@@ -236,13 +204,13 @@ if (interval.from.value === c) {

__decorate([
(0, log_1.Logger)('Intl'),
__metadata("design:type", log_1.Log)
Logger('Intl'),
__metadata("design:type", Log)
], SpineJsInternationalizationFromJson.prototype, "Log", void 0);
__decorate([
(0, di_1.Autoinject)(),
__metadata("design:type", configuration_1.Configuration)
Autoinject(),
__metadata("design:type", Configuration)
], SpineJsInternationalizationFromJson.prototype, "Configuration", void 0);
SpineJsInternationalizationFromJson = __decorate([
(0, di_1.Injectable)(Intl)
Injectable(Intl)
], SpineJsInternationalizationFromJson);
exports.SpineJsInternationalizationFromJson = SpineJsInternationalizationFromJson;
export { SpineJsInternationalizationFromJson };
/**

@@ -257,3 +225,3 @@ * I18n localization function. Returns localized string.

globalAny.__ = (text, ...args) => {
return di_1.DI.get(Intl).__(text, ...args);
return DI.get(Intl).__(text, ...args);
};

@@ -269,3 +237,3 @@ /**

globalAny.__n = (text, count) => {
return di_1.DI.get(Intl).__n(text, count);
return DI.get(Intl).__n(text, count);
};

@@ -278,3 +246,3 @@ /**

globalAny.__l = (text) => {
return di_1.DI.get(Intl).__l(text);
return DI.get(Intl).__l(text);
};

@@ -287,3 +255,3 @@ /**

globalAny.__h = (text) => {
return di_1.DI.get(Intl).__h(text);
return DI.get(Intl).__h(text);
};

@@ -293,5 +261,5 @@ /**

*/
function __translate(lang) {
export function __translate(lang) {
return (text, ...args) => {
const intl = di_1.DI.get(Intl);
const intl = DI.get(Intl);
if (typeof text === 'string') {

@@ -306,6 +274,5 @@ return intl.__({

}
exports.__translate = __translate;
function __translateNumber(lang) {
export function __translateNumber(lang) {
return (text, count) => {
const intl = di_1.DI.get(Intl);
const intl = DI.get(Intl);
if (typeof text === 'string') {

@@ -320,21 +287,18 @@ return intl.__n({

}
exports.__translateNumber = __translateNumber;
function __translateL(text) {
const intl = di_1.DI.get(Intl);
export function __translateL(text) {
const intl = DI.get(Intl);
return intl.__l(text);
}
exports.__translateL = __translateL;
function __translateH(text) {
const intl = di_1.DI.get(Intl);
export function __translateH(text) {
const intl = DI.get(Intl);
return intl.__h(text);
}
exports.__translateH = __translateH;
function guessLanguage(lang) {
export function guessLanguage(lang) {
let selectedLang = lang;
if (!selectedLang) {
const store = di_1.DI.get(node_async_hooks_1.AsyncLocalStorage);
const store = DI.get(AsyncLocalStorage);
if (store) {
const storage = di_1.DI.get(node_async_hooks_1.AsyncLocalStorage).getStore();
const storage = DI.get(AsyncLocalStorage).getStore();
if (!storage || !storage.language) {
selectedLang = di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
selectedLang = DI.get(Configuration).get('intl.defaultLocale');
}

@@ -346,3 +310,3 @@ else {

else {
selectedLang = di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
selectedLang = DI.get(Configuration).get('intl.defaultLocale');
}

@@ -352,7 +316,5 @@ }

}
exports.guessLanguage = guessLanguage;
function defaultLanguage() {
return di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
export function defaultLanguage() {
return DI.get(Configuration).get('intl.defaultLocale');
}
exports.defaultLanguage = defaultLanguage;
//# sourceMappingURL=index.js.map

@@ -14,1 +14,2 @@ import { ILog } from '@spinajs/log';

}
//# sourceMappingURL=sources.d.ts.map

@@ -1,18 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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) {

@@ -24,35 +7,22 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.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);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsTranslationSource = exports.JsonTranslationSource = exports.TranslationSource = void 0;
const configuration_1 = require("@spinajs/configuration");
const di_1 = require("@spinajs/di");
const glob_1 = __importDefault(require("glob"));
const fs = __importStar(require("fs"));
const _ = __importStar(require("lodash"));
const path_1 = require("path");
const log_1 = require("@spinajs/log");
class TranslationSource {
import { Configuration } from '@spinajs/configuration';
import { Autoinject, Injectable } from '@spinajs/di';
import glob from 'glob';
import * as fs from 'fs';
import _ from 'lodash';
import { normalize, resolve, basename } from 'path';
import { Logger } from '@spinajs/log';
export class TranslationSource {
}
__decorate([
(0, di_1.Autoinject)(),
__metadata("design:type", configuration_1.Configuration)
Autoinject(),
__metadata("design:type", Configuration)
], TranslationSource.prototype, "Configuration", void 0);
__decorate([
(0, log_1.Logger)('intl'),
Logger('intl'),
__metadata("design:type", Object)
], TranslationSource.prototype, "Log", void 0);
exports.TranslationSource = TranslationSource;
let JsonTranslationSource = class JsonTranslationSource extends TranslationSource {

@@ -64,7 +34,7 @@ async load() {

.filter((d) => fs.existsSync(d))
.map((d) => glob_1.default.sync(`${d}/**/*.json`))
.map((d) => glob.sync(`${d}/**/*.json`.replace(/\\/g, '/')))
.reduce((prev, current) => {
return prev.concat(_.flattenDeep(current));
}, [])
.map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
.map((f) => normalize(resolve(f)))
.map((f) => {

@@ -75,3 +45,3 @@ this.Log.trace(`Found json localisation file at ${f}`);

.forEach((f) => {
const lang = (0, path_1.basename)(f, '.json');
const lang = basename(f, '.json');
let data;

@@ -95,5 +65,5 @@ try {

JsonTranslationSource = __decorate([
(0, di_1.Injectable)(TranslationSource)
Injectable(TranslationSource)
], JsonTranslationSource);
exports.JsonTranslationSource = JsonTranslationSource;
export { JsonTranslationSource };
let JsTranslationSource = class JsTranslationSource extends TranslationSource {

@@ -103,22 +73,22 @@ async load() {

let translations = {};
localeDirs
const files = localeDirs
.filter((d) => fs.existsSync(d))
.map((d) => glob_1.default.sync(`${d}/**/*.js`))
.map((d) => glob.sync(`${d}/**/*.{js,cjs}`.replace(/\\/g, '/')))
.reduce((prev, current) => {
return prev.concat(_.flattenDeep(current));
}, [])
.map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
.map((f) => normalize(resolve(f)))
.map((f) => {
this.Log.trace(`Found json localisation file at ${f}`);
return f;
})
.forEach((f) => {
const lang = (0, path_1.basename)(f, '.js');
let data = require(f);
if (!data) {
});
for (const f of files) {
const lang = basename(basename(f, '.js'), '.cjs');
let data = await import(`file://${f}`);
if (!data || !data.default) {
this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
return;
}
translations = _.merge({ [lang]: data }, translations);
});
translations = _.merge({ [lang]: data.default }, translations);
}
return translations;

@@ -128,5 +98,5 @@ }

JsTranslationSource = __decorate([
(0, di_1.Injectable)(TranslationSource)
Injectable(TranslationSource)
], JsTranslationSource);
exports.JsTranslationSource = JsTranslationSource;
export { JsTranslationSource };
//# sourceMappingURL=sources.js.map
{
"name": "@spinajs/intl",
"version": "2.0.46",
"version": "2.0.48",
"description": "internationalization for spinajs framework",
"main": "lib/index.js",
"exports": "./lib/index.js",
"type": "module",
"private": false,
"engines": {
"node": ">=16.11"
},
"scripts": {
"build": "npm run clean && npm run compile",
"compile": "tsc -p tsconfig.build.json",
"clean": "",
"compile": "tsc -b tsconfig.json",
"rimraf": "./node_modules/rimraf/bin.js",
"clean": "rimraf lib/ && rimraf tsconfig.tsbuildinfo",
"test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
"coverage": "nyc npm run test",
"build-docs": "rimraf docs && typedoc --options typedoc.json src/",
"prepare": "npm run build",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint -c .eslintrc.js --ext .ts src --fix",
"prepublishOnly": "npm test && npm run lint",
"lint": "eslint -c .eslintrc.cjs --ext .ts src --fix",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
"postinstall": "npm run build"
},

@@ -46,8 +49,8 @@ "files": [

"@spinajs/reflection": "^2.0.46",
"glob": "^7.1.6",
"lodash": "^4.17.15",
"make-plural": "^6.0.1",
"glob": "^8.1.0",
"lodash": "^4.17.21",
"make-plural": "^7.2.0",
"math-interval-parser": "^2.0.1"
},
"gitHead": "bd560afd6c9a156071102cc6b4f36115b5498e9d"
"gitHead": "002dc553b0ffffd72193d0121ac425a4083bc9ee"
}

@@ -0,0 +0,0 @@ # `@spinajs/intl`

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc