Comparing version 3.1.5 to 3.1.6
@@ -10,2 +10,9 @@ # Changelog | ||
## [v3.1.6](https://github.com/artus9033/i18n-plus/compare/v3.1.5...v3.1.6) - 2021-08-26 | ||
### Commits | ||
- Added an EventEmitter so that LocaleHelper can inform of its state changes (e.g. for React provider re-render purposes) [`1632e5c`](https://github.com/artus9033/i18n-plus/commit/1632e5c3877718a8fa7b7e2e6c3730c18c8091f9) | ||
- Updated CHANGELOG [`71e1e5a`](https://github.com/artus9033/i18n-plus/commit/71e1e5aabb116be6db00a91e7aaf22d52284d374) | ||
## [v3.1.5](https://github.com/artus9033/i18n-plus/compare/v3.1.4...v3.1.5) - 2021-08-26 | ||
@@ -12,0 +19,0 @@ |
@@ -0,5 +1,7 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
/** | ||
* Key class used for rendering translated, conjugated & interpolated strings; see trans | ||
*/ | ||
export declare class LocaleHelper { | ||
export declare class LocaleHelper extends EventEmitter { | ||
private locale; | ||
@@ -6,0 +8,0 @@ private fallbackLocale; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -26,2 +41,3 @@ if (k2 === undefined) k2 = k; | ||
exports.LocaleHelper = void 0; | ||
var events_1 = require("events"); | ||
var auto_bind_1 = __importDefault(require("auto-bind")); | ||
@@ -33,3 +49,4 @@ var lodash_1 = __importDefault(require("lodash")); | ||
*/ | ||
var LocaleHelper = /** @class */ (function () { | ||
var LocaleHelper = /** @class */ (function (_super) { | ||
__extends(LocaleHelper, _super); | ||
/** | ||
@@ -43,2 +60,3 @@ * @constructor | ||
if (fallbackLocale === void 0) { fallbackLocale = Locales_1.default.en; } | ||
var _this = _super.call(this) || this; | ||
/** | ||
@@ -48,3 +66,3 @@ * Current locale used for choosing translations | ||
*/ | ||
this.locale = localeKey; | ||
_this.locale = localeKey; | ||
/** | ||
@@ -54,3 +72,3 @@ * Dictionary with templates of translations as values of properties with keys as names, grouped as values of properties with locale codenames as names | ||
*/ | ||
this.localeValues = localeValues; | ||
_this.localeValues = localeValues; | ||
/** | ||
@@ -60,5 +78,6 @@ * Current fallback locale used for choosing translations when they are not defined for the current locale set | ||
*/ | ||
this.fallbackLocale = fallbackLocale; | ||
_this.fallbackLocale = fallbackLocale; | ||
// bind all properties to fix context problems e.g. in React | ||
auto_bind_1.default(this); | ||
auto_bind_1.default(_this); | ||
return _this; | ||
} | ||
@@ -191,3 +210,7 @@ /** | ||
LocaleHelper.prototype.setLocale = function (locale) { | ||
var localeChanged = locale !== this.locale; | ||
this.locale = locale; | ||
if (localeChanged) { | ||
this.emit("changed"); | ||
} | ||
return this; | ||
@@ -201,3 +224,7 @@ }; | ||
LocaleHelper.prototype.setFallbackLocale = function (locale) { | ||
var fallbackLocaleChanged = locale !== this.fallbackLocale; | ||
this.fallbackLocale = locale; | ||
if (fallbackLocaleChanged) { | ||
this.emit("changed"); | ||
} | ||
return this; | ||
@@ -224,5 +251,5 @@ }; | ||
return LocaleHelper; | ||
}()); | ||
}(events_1.EventEmitter)); | ||
exports.LocaleHelper = LocaleHelper; | ||
exports.default = LocaleHelper; | ||
//# sourceMappingURL=LocaleHelper.js.map |
{ | ||
"name": "i18n-plus", | ||
"version": "3.1.5", | ||
"version": "3.1.6", | ||
"description": "Node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -0,1 +1,3 @@ | ||
import { EventEmitter } from "events"; | ||
import autoBind from "auto-bind"; | ||
@@ -9,3 +11,3 @@ import _ from "lodash"; | ||
*/ | ||
export class LocaleHelper { | ||
export class LocaleHelper extends EventEmitter { | ||
private locale: string; | ||
@@ -22,2 +24,4 @@ private fallbackLocale: string; | ||
constructor(localeKey: string, localeValues: Object, fallbackLocale: string = Locales.en) { | ||
super(); | ||
/** | ||
@@ -206,4 +210,10 @@ * Current locale used for choosing translations | ||
setLocale(locale: string): LocaleHelper { | ||
let localeChanged = locale !== this.locale; | ||
this.locale = locale; | ||
if (localeChanged) { | ||
this.emit("changed"); | ||
} | ||
return this; | ||
@@ -218,4 +228,10 @@ } | ||
setFallbackLocale(locale: string): LocaleHelper { | ||
let fallbackLocaleChanged = locale !== this.fallbackLocale; | ||
this.fallbackLocale = locale; | ||
if (fallbackLocaleChanged) { | ||
this.emit("changed"); | ||
} | ||
return this; | ||
@@ -222,0 +238,0 @@ } |
Sorry, the diff of this file is not supported yet
86382
1912