Permalink
Browse files

fixes for v1.5.10

  • Loading branch information...
1 parent ec292c2 commit 2cad271ac7200d2082da1078655b27f4cf2fe2bf @jamuhl jamuhl committed Dec 20, 2012
Showing with 328 additions and 188 deletions.
  1. +4 −2 README.md
  2. +1 −1 grunt.js
  3. +70 −1 spec/functions.translation.spec.js
  4. +3 −1 spec/spec.js
  5. +3 −0 src/i18next.helpers.js
  6. +4 −0 src/i18next.init.js
  7. +169 −180 src/i18next.plurals.js
  8. +1 −1 src/i18next.translate.js
  9. +73 −2 test/test.js
View
@@ -109,9 +109,11 @@ In the folder you find one static sample.
# Building
To build your own copy of i18next, check out the repository and:
+ git clone https://github.com/jamuhl/i18next.git
cd i18next
- npm install grunt grunt-contrib grunt-rigger
- node_modules/grunt/bin/grunt
+ npm install grunt -g
+ npm install
+ grunt
The grunt command will build i18next into the bin/ and release/ folders.
View
@@ -1,7 +1,7 @@
/*global module:false*/
module.exports = function(grunt) {
- var version = '1.5.9';
+ var version = '1.5.10pre';
grunt.loadNpmTasks('grunt-rigger');
grunt.loadNpmTasks('grunt-contrib');
@@ -148,6 +148,42 @@ describe('translation functionality', function() {
});
+ describe('default i18next way - different prefix/suffix', function() {
+
+ var resStore = {
+ dev: { translation: { } },
+ en: { translation: { } },
+ 'en-US': {
+ translation: {
+ interpolationTest1: 'added *toAdd*',
+ interpolationTest2: 'added *toAdd* *toAdd* twice',
+ interpolationTest3: 'added *child.one* *child.two*',
+ interpolationTest4: 'added *child.grandChild.three*'
+ }
+ }
+ };
+
+ beforeEach(function(done) {
+ i18n.init( $.extend(opts, {
+ resStore: resStore,
+ interpolationPrefix: '*',
+ interpolationSuffix: '*'
+ }), function(t) { done(); });
+ });
+
+ it('it should replace passed in key/values', function() {
+ expect(i18n.t('interpolationTest1', {toAdd: 'something'})).to.be('added something');
+ expect(i18n.t('interpolationTest2', {toAdd: 'something'})).to.be('added something something twice');
+ expect(i18n.t('interpolationTest3', { child: { one: '1', two: '2'}})).to.be('added 1 2');
+ expect(i18n.t('interpolationTest4', { child: { grandChild: { three: '3'}}})).to.be('added 3');
+ });
+
+ it('it should replace passed in key/values on defaultValue', function() {
+ expect(i18n.t('interpolationTest5', {defaultValue: 'added *toAdd*', toAdd: 'something'})).to.be('added something');
+ });
+
+ });
+
describe('using sprintf', function() {
var resStore = {
@@ -266,7 +302,7 @@ describe('translation functionality', function() {
});
});
- describe('extended usage - multiple plural forms', function() {
+ describe('extended usage - multiple plural forms - ar', function() {
var resStore = {
dev: { translation: { } },
ar: { translation: {
@@ -300,6 +336,39 @@ describe('translation functionality', function() {
});
});
+ describe('extended usage - multiple plural forms - ru', function() {
+ var resStore = {
+ dev: { translation: { } },
+ ru: { translation: {
+ key: '1,21,31',
+ key_plural_2: '2,3,4',
+ key_plural_5: '0,5,6'
+ }
+ },
+ 'ru-??': { translation: { } }
+ };
+
+ beforeEach(function(done) {
+ i18n.init( $.extend(opts, { lng: 'ru', resStore: resStore }),
+ function(t) { done(); });
+ });
+
+ it('it should provide correct plural forms', function() {
+ expect(i18n.t('key', {count: 0})).to.be('0,5,6');
+ expect(i18n.t('key', {count: 1})).to.be('1,21,31');
+ expect(i18n.t('key', {count: 2})).to.be('2,3,4');
+ expect(i18n.t('key', {count: 3})).to.be('2,3,4');
+ expect(i18n.t('key', {count: 4})).to.be('2,3,4');
+ expect(i18n.t('key', {count: 104})).to.be('2,3,4');
+ expect(i18n.t('key', {count: 11})).to.be('0,5,6');
+ expect(i18n.t('key', {count: 24})).to.be('2,3,4');
+ expect(i18n.t('key', {count: 25})).to.be('0,5,6');
+ expect(i18n.t('key', {count: 99})).to.be('0,5,6');
+ expect(i18n.t('key', {count: 199})).to.be('0,5,6');
+ expect(i18n.t('key', {count: 100})).to.be('0,5,6');
+ });
+ });
+
});
describe('context usage', function() {
View
@@ -20,7 +20,9 @@ describe('i18next', function() {
returnObjectTrees: false,
debug: true,
selectorAttr: 'data-i18n',
- postProcess: ''
+ postProcess: '',
+ interpolationPrefix: '__',
+ interpolationSuffix: '__'
};
});
View
@@ -395,5 +395,8 @@ var f = {
if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng);
return languages;
+ },
+ regexEscape: function(str) {
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
};
View
@@ -14,6 +14,10 @@ function init(options, cb) {
o.ns = { namespaces: [o.ns], defaultNs: o.ns};
}
+ // escape prefix/suffix
+ o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix);
+ o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix);
+
if (!o.lng) o.lng = f.detectLanguage();
if (o.lng) {
// set cookie with lng set (as detectLanguage will set cookie on need)
Oops, something went wrong.

0 comments on commit 2cad271

Please sign in to comment.