Comparing version 3.1.0 to 3.1.1
@@ -5,2 +5,13 @@ # Change Log | ||
<a name="3.1.1"></a> | ||
## [3.1.1](https://github.com/martinheidegger/i18n-core/compare/v3.1.0...v3.1.1) (2017-05-29) | ||
### Bug Fixes | ||
* **fallback:** In case of a fallback it now shows the proper absolute key. ([d0bf9f0](https://github.com/martinheidegger/i18n-core/commit/d0bf9f0)) | ||
* **simple:** Fixed simple mustache lookups for escaped content. ([0114a92](https://github.com/martinheidegger/i18n-core/commit/0114a92)) | ||
<a name="3.1.0"></a> | ||
@@ -7,0 +18,0 @@ # [3.1.0](https://github.com/martinheidegger/i18n-core/compare/v3.0.0...v3.1.0) (2017-05-29) |
'use strict' | ||
function addPrefixRecursive (node, key) { | ||
var prefix = node.currentPrefix | ||
while (node !== node.absRoot) { | ||
prefix = node.absRoot.currentPrefix + prefix | ||
node = node.absRoot | ||
} | ||
return addPrefix(prefix, key) | ||
} | ||
function addPrefix (prefix, key) { | ||
@@ -9,6 +18,6 @@ return key !== null && key !== undefined ? prefix + key : prefix | ||
get: function (key) { | ||
return this.parent.get(addPrefix(this.currentPrefix, key)) | ||
return this.parent.get(addPrefixRecursive(this, key)) | ||
}, | ||
has: function has (key) { | ||
var value = this.parent.get(addPrefix(this.currentPrefix, key)) | ||
var value = this.parent.get(addPrefixRecursive(this, key)) | ||
return value !== null && value !== undefined | ||
@@ -18,3 +27,3 @@ }, | ||
var prefixed = addPrefix(this.currentPrefix, key) | ||
return this.translator(this.parent.get(prefixed), prefixed, namedValues, args) | ||
return this.translator(this.parent.get(prefixed), addPrefixRecursive(this, key), namedValues, args) | ||
}, | ||
@@ -31,3 +40,3 @@ translateFirst: function (keys, fallbackKey, namedValues, args) { | ||
} | ||
return this.translator(null, addPrefix(this.currentPrefix, fallbackKey), namedValues, args) | ||
return this.translator(null, addPrefixRecursive(this, fallbackKey), namedValues, args) | ||
}, | ||
@@ -34,0 +43,0 @@ absPrefix: function (prefix, allowSubModification) { |
@@ -6,3 +6,3 @@ 'use strict' | ||
if (/^{.*}$/.test(param)) { | ||
param = param.substring(0, param.length - 1) | ||
param = param.substring(1, param.length - 1) | ||
} | ||
@@ -9,0 +9,0 @@ var val = namedValues[param] |
{ | ||
"name": "i18n-core", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Basic i18n translation.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -240,2 +240,27 @@ # i18n-core | ||
Prefixing every absolute lookup with `abs` can get tedious that is why there is | ||
also the possibility to use `absSection` that, like `section`, returns a new | ||
translation object where every call assumes a particular absolute section. | ||
```javascript | ||
var translate = i18n_core({ | ||
en: { | ||
sectionA: { | ||
title: "Curriculum Vitae" | ||
}, | ||
menu: { | ||
about: "About Me" | ||
} | ||
} | ||
}) | ||
var lang = translate.section('en', true).lock() | ||
var sectionA = lang.section('sectionA') | ||
sectionA('title') // Curriculum Vitae | ||
var menu = sectionA.absSection('menu') | ||
menu('about') // About Me | ||
``` | ||
For your convenience there is also the `.root()` alias for `.absSection('')`. | ||
## Core API's | ||
@@ -271,3 +296,3 @@ | ||
// Creates a api node where each key is prefixed | ||
// Creates an api node where each key is prefixed | ||
// prefix .............. prefix to be set for each translation request | ||
@@ -277,2 +302,7 @@ // allowModification ... allows changePrefix API | ||
// Creates an api node where each key is prefixed to an absolute root | ||
// prefix .............. prefix to be set for each translation request | ||
// allowModification ... allows changePrefix API | ||
core.absPrefix(prefix, allowModification) | ||
// Changes the prefix of the API (undefined when modification forbidden) | ||
@@ -279,0 +309,0 @@ core.changePrefix(prefix) |
@@ -56,2 +56,23 @@ 'use strict' | ||
test('section lookup', function (t) { | ||
var translate = i18n({ | ||
en: { | ||
sectionA: { | ||
title: "Curriculum Vitae" | ||
}, | ||
menu: { | ||
about: "About Me" | ||
} | ||
} | ||
}) | ||
var lang = translate.section('en', true).lock() | ||
var sectionA = lang.section('sectionA') | ||
t.equals(lang('sectionA.title'), 'Curriculum Vitae') | ||
t.equals(sectionA('title'), 'Curriculum Vitae') | ||
var menu = sectionA.absSection('menu') | ||
t.equals(lang('menu.about'), 'About Me') | ||
t.equals(menu('about'), 'About Me') | ||
t.end() | ||
}) | ||
test('basic file lookup is used when string is given', function (t) { | ||
@@ -58,0 +79,0 @@ t.equals(i18n(fsFolder).section('en').__('b'), 'c') |
@@ -24,2 +24,8 @@ 'use strict' | ||
test('fallback should show the absolute locks', function (t) { | ||
var __ = i18n().section('en').lock().absSection('b.a') | ||
t.equals(__('c'), 'en.b.a.c') | ||
t.end() | ||
}) | ||
test('custom child fallback should not work!', function (t) { | ||
@@ -26,0 +32,0 @@ var translator = i18n().section('en') |
Sorry, the diff of this file is not supported yet
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
319
297538
48
3979