i18n-dialect
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -14,3 +14,3 @@ "use strict"; | ||
var translationForms = key && this.dictionary[key] || this.getUntranslatedFallback(descriptor); | ||
var translation = this.selectPluralForm(translationForms, descriptor); | ||
var translation = this.selectPluralForm(translationForms, descriptor, forceUntranslated); | ||
return this.substituteStrings(translation, descriptor); | ||
@@ -84,3 +84,3 @@ }; | ||
// Select proper plural form based on descriptor | ||
TranslationController.prototype.selectPluralForm = function (forms, descriptor) { | ||
TranslationController.prototype.selectPluralForm = function (forms, descriptor, forceUntranslated) { | ||
switch (descriptor.type) { | ||
@@ -95,3 +95,3 @@ case '_t': | ||
} | ||
var formIndex = this.pluralSelect | ||
var formIndex = this.pluralSelect && !forceUntranslated | ||
? this.pluralSelect(descriptor.factor) | ||
@@ -98,0 +98,0 @@ : this.defaultPluralSelect(descriptor.factor); |
{ | ||
"name": "i18n-dialect", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Internationalization support library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -10,3 +10,3 @@ # i18n-dialect | ||
- **onFailedSubstitution**: a callback, which will be called every time any `%N` substitution is failed; may be undefined. | ||
- **defaultPluralSelect**: a function that will be a default for plural forms selection. Usually, this should be a plural selector of developers' primary language. | ||
- **defaultPluralSelect**: a function that will be a default for plural forms selection. This should be a plural selector of developers' primary language. | ||
@@ -13,0 +13,0 @@ The `TranslationController` object also has a `setLocale` method to update internal dictionary - once this is done, the changes are applied to all subsequent calls of translation functions. Notice that `setLocale` method is asynchronous, so updating your user interface should not be done right after it's call: you should wait until everything is loaded and parsed. |
@@ -21,3 +21,3 @@ import { | ||
let translationForms: string[] = key && this.dictionary[key] || this.getUntranslatedFallback(descriptor); | ||
let translation = this.selectPluralForm(translationForms, descriptor); | ||
let translation = this.selectPluralForm(translationForms, descriptor, forceUntranslated); | ||
return this.substituteStrings(translation, descriptor); | ||
@@ -101,3 +101,3 @@ } | ||
// Select proper plural form based on descriptor | ||
protected selectPluralForm(forms: string[], descriptor: Descriptor): string { | ||
protected selectPluralForm(forms: string[], descriptor: Descriptor, forceUntranslated: boolean): string { | ||
switch (descriptor.type) { | ||
@@ -112,3 +112,3 @@ case '_t': | ||
} | ||
let formIndex = this.pluralSelect | ||
let formIndex = this.pluralSelect && !forceUntranslated | ||
? this.pluralSelect(descriptor.factor) | ||
@@ -115,0 +115,0 @@ : this.defaultPluralSelect(descriptor.factor); |
@@ -118,3 +118,3 @@ import * as assert from 'assert'; | ||
assert.equal( | ||
t.pSelectPluralForm(['одна форма', 'две-четыре формы', 'пять и более форм'], descr), | ||
t.pSelectPluralForm(['одна форма', 'две-четыре формы', 'пять и более форм'], descr, /*forceUntranslated = */ false), | ||
'две-четыре формы' | ||
@@ -124,3 +124,3 @@ ); | ||
assert.equal( | ||
t.pSelectPluralForm(['одна форма', 'две-четыре формы', 'пять и более форм'], descr), | ||
t.pSelectPluralForm(['одна форма', 'две-четыре формы', 'пять и более форм'], descr, /*forceUntranslated = */ false), | ||
'одна форма' | ||
@@ -130,3 +130,3 @@ ); | ||
assert.equal( | ||
t.pSelectPluralForm(['одна форма', 'две-четыре формы', 'пять и более форм'], descr), | ||
t.pSelectPluralForm(['одна форма', 'две-четыре формы', 'пять и более форм'], descr, /*forceUntranslated = */ false), | ||
'пять и более форм' | ||
@@ -147,3 +147,3 @@ ); | ||
assert.equal( | ||
t.pSelectPluralForm(['одна форма'], descr), | ||
t.pSelectPluralForm(['одна форма'], descr, /*forceUntranslated = */ false), | ||
'одна форма' | ||
@@ -150,0 +150,0 @@ ); |
@@ -18,3 +18,5 @@ import { TranslationController } from '../src/controller'; | ||
public pGetUntranslatedFallback = (descriptor: Descriptor) => this.getUntranslatedFallback(descriptor); | ||
public pSelectPluralForm = (forms: string[], descriptor: Descriptor) => this.selectPluralForm(forms, descriptor); | ||
public pSelectPluralForm = ( | ||
forms: string[], descriptor: Descriptor, forceUntranslated: boolean | ||
) => this.selectPluralForm(forms, descriptor, forceUntranslated); | ||
public pSubstituteStrings = (str: string, descriptor: Descriptor) => this.substituteStrings(str, descriptor); | ||
@@ -21,0 +23,0 @@ public pMakeNewDict = (items: I18NEntry[]) => this.makeNewDict(items); |
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
194358
1470