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

@boost/translate

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boost/translate - npm Package Compare versions

Comparing version 1.3.10 to 2.0.0-alpha.1

lib/debug.d.ts

1

lib/constants.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = void 0;
const internal_1 = require("@boost/internal");
exports.debug = internal_1.createInternalDebugger('translate');

56

lib/createTranslator.js
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
/* eslint-disable @typescript-eslint/no-floating-promises */
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -19,6 +9,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const common_1 = require("@boost/common");
const internal_1 = require("@boost/internal");
const TranslateError_1 = __importDefault(require("./TranslateError"));
const LocaleDetector_1 = __importDefault(require("./LocaleDetector"));
const FileBackend_1 = __importDefault(require("./FileBackend"));
const constants_1 = require("./constants");
const debug_1 = __importDefault(require("./debug"));
// istanbul ignore next

@@ -30,15 +20,15 @@ function handleError(error) {

}
function createTranslator(namespace, resourcePath, { autoDetect = true, debug: debugOpt = false, fallbackLocale = 'en', locale, lookupType, resourceFormat = 'yaml', } = {}) {
function createTranslator(namespace, resourcePath, { autoDetect = true, debug: debugOpt = false, fallbackLocale = 'en', locale, lookupType = 'all', resourceFormat = 'yaml', } = {}) {
const namespaces = common_1.toArray(namespace);
const resourcePaths = common_1.toArray(resourcePath).map(common_1.Path.create);
if (namespaces.length === 0) {
throw new internal_1.RuntimeError('translate', 'TL_REQ_NAMESPACE');
throw new TranslateError_1.default('NAMESPACE_REQUIRED');
}
else if (resourcePaths.length === 0) {
throw new internal_1.RuntimeError('translate', 'TL_REQ_RES_PATHS');
throw new TranslateError_1.default('RESOURCES_REQUIRED');
}
else if (!autoDetect && !locale) {
throw new internal_1.RuntimeError('translate', 'TL_REQ_MANUAL_LOCALE');
throw new TranslateError_1.default('LOCALE_REQUIRED');
}
constants_1.debug('New translator created: %s namespace(s)', namespaces.join(', '));
debug_1.default('New translator created: %s namespace(s)', namespaces.join(', '));
const translator = i18next_1.default.createInstance().use(new FileBackend_1.default());

@@ -53,2 +43,3 @@ if (autoDetect) {

},
cleanCode: true,
debug: debugOpt,

@@ -60,19 +51,22 @@ defaultNS: namespaces[0],

load: lookupType,
lowerCaseLng: true,
lowerCaseLng: false,
ns: namespaces,
returnNull: false,
returnEmptyString: true,
returnNull: true,
}, handleError);
function msg(key, params, _a = {}) {
var { interpolation, locale: lng } = _a, options = __rest(_a, ["interpolation", "locale"]);
return translator.t(key, Object.assign(Object.assign({ interpolation: Object.assign({ escapeValue: false }, interpolation) }, options), { lng, replace: params }));
function msg(key, params, { interpolation, locale: lng, ...options } = {}) {
return translator.t(key, {
interpolation: { escapeValue: false, ...interpolation },
...options,
lng,
replace: params,
});
}
msg.dir = translator.dir();
msg.direction = translator.dir();
msg.locale = translator.language;
msg.changeLocale = (lang) => {
constants_1.debug('Locale manually changed to "%s"', lang);
translator.changeLanguage(lang, error => {
handleError(error);
msg.dir = translator.dir();
msg.locale = translator.language;
});
msg.changeLocale = async (lang) => {
debug_1.default('Locale manually changed to "%s"', lang);
await translator.changeLanguage(lang);
msg.direction = translator.dir();
msg.locale = translator.language;
};

@@ -79,0 +73,0 @@ if (process.env.NODE_ENV === 'test') {

import { BackendModule, Resource, ResourceKey } from 'i18next';
import { Contract, Path, Predicates } from '@boost/common';
import { Contract, Path, Predicates, Blueprint } from '@boost/common';
import { Locale, Format } from './types';

@@ -12,6 +12,3 @@ export interface FileBackendOptions {

init(services: unknown, options: Partial<FileBackendOptions>): void;
blueprint({ array, instance, string }: Predicates): {
format: import("optimal").StringPredicate<Format>;
paths: import("optimal").ArrayPredicate<Path>;
};
blueprint({ array, instance, string }: Predicates): Blueprint<FileBackendOptions>;
create(): void;

@@ -18,0 +15,0 @@ read(locale: Locale, namespace: string, callback: (error: Error | null, resources: Resource) => void): ResourceKey;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@boost/common");
const internal_1 = require("@boost/internal");
const TranslateError_1 = __importDefault(require("./TranslateError"));
const EXTS = {

@@ -19,5 +22,5 @@ js: ['js'],

// Validate resource paths are directories
this.options.paths.forEach(path => {
this.options.paths.forEach((path) => {
if (path.exists() && !path.isDirectory()) {
throw new internal_1.RuntimeError('translate', 'TL_INVALID_RES_PATH', [path.path()]);
throw new TranslateError_1.default('RESOURCE_PATH_INVALID', [path.path()]);
}

@@ -39,4 +42,4 @@ });

const resources = {};
paths.forEach(path => {
EXTS[format].some(ext => {
paths.forEach((path) => {
EXTS[format].some((ext) => {
const resPath = path.append(locale, `${namespace}.${ext}`);

@@ -43,0 +46,0 @@ const isCached = this.fileCache.has(resPath);

/**
* @copyright 2019, Miles Johnson
* @copyright 2020, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import createTranslator, { TranslatorOptions } from './createTranslator';
import TranslateError from './TranslateError';
export * from './types';
export { createTranslator, TranslatorOptions };
export { createTranslator, TranslatorOptions, TranslateError };
//# sourceMappingURL=index.d.ts.map
"use strict";
/**
* @copyright 2019, Miles Johnson
* @copyright 2020, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -10,3 +20,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.TranslateError = exports.createTranslator = void 0;
const createTranslator_1 = __importDefault(require("./createTranslator"));
exports.createTranslator = createTranslator_1.default;
const TranslateError_1 = __importDefault(require("./TranslateError"));
exports.TranslateError = TranslateError_1.default;
__exportStar(require("./types"), exports);

@@ -7,3 +7,3 @@ "use strict";

const os_locale_1 = __importDefault(require("os-locale"));
const constants_1 = require("./constants");
const debug_1 = __importDefault(require("./debug"));
class LocaleDetector {

@@ -22,3 +22,3 @@ constructor() {

if (this.locale) {
constants_1.debug('Locale "%s" manually provided', this.locale);
debug_1.default('Locale "%s" manually provided', this.locale);
return this.locale;

@@ -30,7 +30,7 @@ }

const args = process.argv;
const index = args.findIndex(arg => arg === '--locale');
const index = args.findIndex((arg) => arg === '--locale');
const nextIndex = index + 1;
if (index >= 0 && args[nextIndex] && !args[nextIndex].startsWith('-')) {
const locale = args[nextIndex];
constants_1.debug('Locale "%s" detected from --locale option', locale);
debug_1.default('Locale "%s" detected from --locale option', locale);
return locale;

@@ -42,3 +42,3 @@ }

const locale = os_locale_1.default.sync().replace(/_/gu, '-');
constants_1.debug('Locale "%s" detected from operating system', locale);
debug_1.default('Locale "%s" detected from operating system', locale);
return locale;

@@ -45,0 +45,0 @@ }

@@ -23,8 +23,8 @@ import { i18n, InterpolationOptions } from 'i18next';

export interface Translator {
dir: Direction;
direction: Direction;
locale: Locale;
changeLocale: (locale: Locale) => Promise<void>;
(key: string | string[], params?: InterpolationParams, options?: MessageOptions): string;
changeLocale(locale: Locale): void;
i18n: i18n;
}
//# sourceMappingURL=types.d.ts.map
{
"name": "@boost/translate",
"version": "1.3.10",
"version": "2.0.0-alpha.1",
"release": "1592788092197",
"description": "Package and application level translations made easy.",

@@ -15,5 +16,4 @@ "keywords": [

"types": "./lib/index.d.ts",
"nonce": "1579986563745",
"engines": {
"node": ">=8.9.0"
"node": ">=10.17.0"
},

@@ -26,6 +26,6 @@ "repository": "https://github.com/milesj/boost/tree/master/packages/log",

"dependencies": {
"@boost/common": "^1.9.0",
"@boost/internal": "^1.2.0",
"i18next": "^19.4.2",
"os-locale": "^4.0.0"
"@boost/common": "^2.0.0-alpha.1",
"@boost/internal": "^2.0.0-alpha.1",
"i18next": "^19.5.0",
"os-locale": "^5.0.0"
},

@@ -36,3 +36,3 @@ "funding": {

},
"gitHead": "257f5a0a342a014f3ce9cf8c288879a73b36ef76"
"gitHead": "3fffbcf3231b86592d2083902b8c39a2ed1b2e4c"
}

@@ -1,2 +0,2 @@

# Boost Translate
# Translate - Boost

@@ -3,0 +3,0 @@ [![Build Status](https://github.com/milesj/boost/workflows/Build/badge.svg)](https://github.com/milesj/boost/actions?query=branch%3Amaster)

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

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