From 4c59601faabc4ef6753f4b741f64ee453a46918b Mon Sep 17 00:00:00 2001 From: Zlatko Fedor Date: Sat, 28 Nov 2015 21:15:46 +0100 Subject: [PATCH] Release 0.2.12 --- README.md | 1 + dist/filters/plural.js | 11 ++++++++++- package.json | 2 +- src/filters/plural.js | 11 ++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8bbc29e..e98b7f9 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ npm install translate-maker # Features - Build on standards ([ICU Message syntax](http://userguide.icu-project.org/formatparse/messages), [Unicode CLDR](http://cldr.unicode.org/)) +- Support 190+ languages - JSON Structure - Nested and reference translations - Variables diff --git a/dist/filters/plural.js b/dist/filters/plural.js index da53db1..dd1557c 100644 --- a/dist/filters/plural.js +++ b/dist/filters/plural.js @@ -14,8 +14,17 @@ var _cldr = require('cldr'); var _cldr2 = _interopRequireDefault(_cldr); +var cachePlural = null; + function plural(locale, count) { - var fn = _cldr2['default'].extractPluralRuleFunction(locale); + if (!cachePlural || cachePlural.locale !== locale) { + cachePlural = { + locale: locale, + fn: _cldr2['default'].extractPluralRuleFunction(locale) + }; + } + + var fn = cachePlural.fn; return fn(count); } diff --git a/package.json b/package.json index 735cb8e..ddbe466 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "translate-maker", - "version": "0.2.11", + "version": "0.2.12", "description": "Universal translation library", "main": "dist/index.js", "keywords": [ diff --git a/src/filters/plural.js b/src/filters/plural.js index c8616f5..78ddea4 100644 --- a/src/filters/plural.js +++ b/src/filters/plural.js @@ -1,8 +1,17 @@ import find from 'lodash/collection/find'; import cldr from 'cldr'; +let cachePlural = null; + function plural(locale, count) { - const fn = cldr.extractPluralRuleFunction(locale); + if (!cachePlural || cachePlural.locale !== locale) { + cachePlural = { + locale, + fn: cldr.extractPluralRuleFunction(locale), + }; + } + + const fn = cachePlural.fn; return fn(count); }