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

bobril-g11n

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bobril-g11n - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

119

CHANGELOG.md

@@ -1,44 +0,40 @@

CHANGELOG
===
# CHANGELOG
4.0.0
--
## 4.1.0
Global moment has set current locale. So you are free to use it, but even better is just use getMoment.
Compare locale in case insensitive way.
3.3.4
--
## 4.0.0
Global moment has set current locale. So you are free to use it, but even better is just use
getMoment.
## 3.3.4
Simplified typings and Moment import.
3.3.2
--
## 3.3.2
Remove empty files from tsconfig.json
3.3.1
--
## 3.3.1
Remove nonsense JSX from tsconfig.json
3.3.0
--
## 3.3.0
Improved upon previous fix by using and exporting useful escapeRegExp function.
3.2.1
--
## 3.2.1
Fixes bug with unformating number in locales with . as thousands separator
Fixes bug with unformating number in locales with . as thousands separator
3.2.0
--
## 3.2.0
Reintroduce number format "0 b", but with nonbreakable space in output which makes more sence.
3.1.0
--
## 3.1.0
Added feature to turn on/off preview of translated texts. When turned on, texts that are translated will be encapsulated by user function.
To enable it run this in console:
Added feature to turn on/off preview of translated texts. When turned on, texts that are translated
will be encapsulated by user function. To enable it run this in console:

@@ -50,2 +46,3 @@ ```

To disable it run this in console:
```

@@ -56,2 +53,3 @@ b.spyTr(null);

To check if enabled run this in console:
```

@@ -61,87 +59,68 @@ b.spyTr()!==undefined

## 3.0.0
3.0.0
--
Breaking change needs bobril-build 0.57+.
Removed dependency on numeral, make code shorter, but also faster. It has slightly less features, so if you missing some please add failing test.
Removed dependency on numeral, make code shorter, but also faster. It has slightly less features, so
if you missing some please add failing test.
2.3.0
--
## 2.3.0
Upgraded numeral version to 2.0.4
-
## Upgraded numeral version to 2.0.4
2.2.0
--
## 2.2.0
Fixes
-
## Fixes
Compilation errors with TS 2.1.4. `setLocale` returns `Promise<void>` instead of `Promise<any>`
2.1.3
--
## 2.1.3
Fixes
-
## Fixes
Fixed tests. Now testable by Bobril-build.
2.1.2
--
## 2.1.2
Fixes
-
## Fixes
Fixed problem with en-gb date format treated as en only. The formated date for en-gb locale should now be DD/MM/YYYY
Fixed problem with en-gb date format treated as en only. The formated date for en-gb locale should
now be DD/MM/YYYY
2.1.1
--
## 2.1.1
Fixes
-
## Fixes
Additional improvements for TS 2.0
2.1.0
--
New features
-
## 2.1.0
## New features
Compilable by TS 2.0 with most strict settings.
2.0.0
--
## 2.0.0
Breaking changes
-
## Breaking changes
Requires Bobril 4.44.0 or higher, but does not depend on it in package.json. Bobril needs to be required sooner than bobril-g11n.
When setLocale fails it will revoke returned promise. Additionaly it will try to revert to default locale before.
Requires Bobril 4.44.0 or higher, but does not depend on it in package.json. Bobril needs to be
required sooner than bobril-g11n. When setLocale fails it will revoke returned promise. Additionally
it will try to revert to default locale before.
1.4.0
--
## 1.4.0
New features
-
## New features
Check plural and selectordinal selectors to be only in allowed list.
1.3.0
--
## 1.3.0
New features
-
## New features
Added 2 additional parameters to getMoment function.
1.2.0
--
## 1.2.0
Changed behaviour
-
## Changed behavior
Missing translation file just logs to console instead of crashing.
{
"name": "bobril-g11n",
"version": "4.0.0",
"description": "Bobril globalization",
"main": "index.js",
"types": "index.d.ts",
"typescript": {
"main": "index.ts"
},
"dependencies": {
"moment": "^2.10.6"
},
"devDependencies": {
"bobril": "*"
},
"bobril": {
"compilerOptions": {
"declaration": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true
}
},
"scripts": {
"test": "bb test"
},
"author": "Boris Letocha",
"license": "MIT"
}
"name": "bobril-g11n",
"version": "4.1.0",
"description": "Bobril globalization",
"main": "index.js",
"types": "index.d.ts",
"typescript": {
"main": "index.ts"
},
"dependencies": {
"moment": "^2.10.6"
},
"devDependencies": {
"bobril": "*"
},
"bobril": {
"compilerOptions": {
"declaration": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true
}
},
"scripts": {
"test": "bb test"
},
"author": "Boris Letocha",
"license": "MIT"
}

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

import * as moment from 'moment';
import * as moment from "moment";
export interface IG11NConfig {

@@ -3,0 +3,0 @@ defaultLocale?: string;

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

var initWasStarted = false;
var currentLocale = '';
var currentLocale = "";
var currentRules = localeDataStorage.getRules("en");

@@ -36,3 +36,3 @@ var currentUnformatter;

if (text === undefined) {
throw new Error('message ' + message + ' is not defined');
throw new Error("message " + message + " is not defined");
}

@@ -48,6 +48,6 @@ return text;

if (currentLocale.length === 0) {
throw new Error('before using t you need to wait for initialization of g11n');
throw new Error("before using t you need to wait for initialization of g11n");
}
var format;
if (typeof message === 'number') {
if (typeof message === "number") {
if (params == null) {

@@ -59,4 +59,4 @@ return spyTranslatedString(currentTranslationMessage(message));

var ast = msgFormatParser.parse(currentTranslationMessage(message));
if (ast.type === 'error') {
throw new Error('message ' + message + ' in ' + currentLocale + ' has error: ' + ast.msg);
if (ast.type === "error") {
throw new Error("message " + message + " in " + currentLocale + " has error: " + ast.msg);
}

@@ -73,4 +73,4 @@ format = msgFormatter.compile(currentLocale, ast);

var ast = msgFormatParser.parse(message);
if (ast.type === 'error') {
throw new Error('message "' + message + '" has error: ' + ast.msg + ' on position: ' + ast.pos);
if (ast.type === "error") {
throw new Error('message "' + message + '" has error: ' + ast.msg + " on position: " + ast.pos);
}

@@ -95,3 +95,3 @@ format = msgFormatter.compile(currentLocale, ast);

if (initWasStarted) {
throw new Error('initLocalization must be called only once');
throw new Error("initLocalization must be called only once");
}

@@ -113,3 +113,4 @@ Object.assign(cfg, config);

return prom;
if (!loadedLocales[locale]) {
var lcLocale = locale.toLowerCase();
if (!loadedLocales[lcLocale]) {
var pathToTranslation = cfg.pathToTranslation;

@@ -130,4 +131,4 @@ if (pathToTranslation) {

currentLocale = locale;
currentRules = localeDataStorage.getRules(locale);
currentTranslations = exports.registeredTranslations[locale] || [];
currentRules = localeDataStorage.getRules(lcLocale);
currentTranslations = exports.registeredTranslations[lcLocale] || [];
currentUnformatter = undefined;

@@ -156,2 +157,3 @@ currentCachedFormat = [];

function registerTranslations(locale, localeDefs, msgs) {
locale = locale.toLowerCase();
if (Array.isArray(localeDefs)) {

@@ -178,4 +180,4 @@ localeDataStorage.setRules(locale, localeDefs);

if (window) {
window['bobrilRegisterTranslations'] = registerTranslations;
window['b'].spyTr = spyTranslation;
window["bobrilRegisterTranslations"] = registerTranslations;
window["b"].spyTr = spyTranslation;
}

@@ -1,7 +0,7 @@

import * as moment from 'moment';
import * as msgFormatParser from './msgFormatParser';
import * as msgFormatter from './msgFormatter';
import { jsonp } from './jsonp';
import * as localeDataStorage from './localeDataStorage';
import * as numberFormatter from './numberFormatter';
import * as moment from "moment";
import * as msgFormatParser from "./msgFormatParser";
import * as msgFormatter from "./msgFormatter";
import { jsonp } from "./jsonp";
import * as localeDataStorage from "./localeDataStorage";
import * as numberFormatter from "./numberFormatter";

@@ -36,3 +36,3 @@ declare var b: {

let initWasStarted = false;
let currentLocale = '';
let currentLocale = "";
let currentRules: localeDataStorage.ILocaleRules = localeDataStorage.getRules("en");

@@ -55,3 +55,3 @@ let currentUnformatter: ((val: string) => number) | undefined;

if (text === undefined) {
throw new Error('message ' + message + ' is not defined');
throw new Error("message " + message + " is not defined");
}

@@ -62,4 +62,3 @@ return text;

function spyTranslatedString(translated: string) {
if (spyTranslationFunc === undefined)
return translated;
if (spyTranslationFunc === undefined) return translated;

@@ -71,6 +70,6 @@ return spyTranslationFunc(translated);

if (currentLocale.length === 0) {
throw new Error('before using t you need to wait for initialization of g11n');
throw new Error("before using t you need to wait for initialization of g11n");
}
let format: IMessageFormat;
if (typeof message === 'number') {
if (typeof message === "number") {
if (params == null) {

@@ -82,4 +81,6 @@ return spyTranslatedString(currentTranslationMessage(message));

let ast = msgFormatParser.parse(currentTranslationMessage(message));
if (ast.type === 'error') {
throw new Error('message ' + message + ' in ' + currentLocale + ' has error: ' + ast.msg);
if (ast.type === "error") {
throw new Error(
"message " + message + " in " + currentLocale + " has error: " + ast.msg
);
}

@@ -94,4 +95,6 @@ format = msgFormatter.compile(currentLocale, ast);

let ast = msgFormatParser.parse(message);
if (ast.type === 'error') {
throw new Error('message "' + message + '" has error: ' + ast.msg + ' on position: ' + ast.pos);
if (ast.type === "error") {
throw new Error(
'message "' + message + '" has error: ' + ast.msg + " on position: " + ast.pos
);
}

@@ -117,3 +120,3 @@ format = msgFormatter.compile(currentLocale, ast);

if (initWasStarted) {
throw new Error('initLocalization must be called only once');
throw new Error("initLocalization must be called only once");
}

@@ -133,5 +136,5 @@ Object.assign(cfg, config);

let prom = Promise.resolve();
if (currentLocale === locale)
return prom;
if (!loadedLocales[locale]) {
if (currentLocale === locale) return prom;
var lcLocale = locale.toLowerCase();
if (!loadedLocales[lcLocale]) {
let pathToTranslation = cfg.pathToTranslation;

@@ -141,6 +144,8 @@ if (pathToTranslation) {

if (p) {
prom = prom.then(() => jsonp(p!)).catch((e) => {
prom = prom.then(() => jsonp(p!)).catch(e => {
console.warn(e);
if (locale != cfg.defaultLocale)
return setLocale(cfg.defaultLocale!).then(() => Promise.reject(e) as Promise<void>);
return setLocale(cfg.defaultLocale!).then(
() => Promise.reject(e) as Promise<void>
);
return undefined;

@@ -153,4 +158,4 @@ });

currentLocale = locale;
currentRules = localeDataStorage.getRules(locale);
currentTranslations = registeredTranslations[locale] || [];
currentRules = localeDataStorage.getRules(lcLocale);
currentTranslations = registeredTranslations[lcLocale] || [];
currentUnformatter = undefined;

@@ -180,17 +185,17 @@ currentCachedFormat = [];

export function registerTranslations(locale: string, localeDefs: any[], msgs: string[]): void {
locale = locale.toLowerCase();
if (Array.isArray(localeDefs)) {
localeDataStorage.setRules(locale, localeDefs);
}
if (Array.isArray(msgs))
registeredTranslations[locale] = msgs;
if (Array.isArray(msgs)) registeredTranslations[locale] = msgs;
loadedLocales[locale] = true;
}
export function spyTranslation(spyFn?: ((text: string) => string) | null): ((text: string) => string) | undefined {
if (spyFn === undefined)
return spyTranslationFunc;
export function spyTranslation(
spyFn?: ((text: string) => string) | null
): ((text: string) => string) | undefined {
if (spyFn === undefined) return spyTranslationFunc;
if (spyFn === null) {
spyTranslationFunc = undefined;
}
else {
} else {
spyTranslationFunc = spyFn;

@@ -202,4 +207,4 @@ }

if (window) {
(<any>window)['bobrilRegisterTranslations'] = registerTranslations;
(<any>window)['b'].spyTr = spyTranslation;
(<any>window)["bobrilRegisterTranslations"] = registerTranslations;
(<any>window)["b"].spyTr = spyTranslation;
}
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