Skip to content

Commit

Permalink
Merge pull request #53 from kevinold/selector-attr
Browse files Browse the repository at this point in the history
allow for configurable selector attribute, defaulting to data-i18n
  • Loading branch information
jamuhl committed Dec 4, 2012
2 parents 87606e2 + 84fb780 commit 6683d4c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions spec/jquery.spec.js
Expand Up @@ -63,7 +63,7 @@ describe('jQuery integration / specials', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="simpleTest"></button></div>');

i18n.init( $.extend(opts, { resStore: resStore }),
function(t) { done(); });
Expand All @@ -90,7 +90,7 @@ describe('jQuery integration / specials', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="[title]simpleTest;simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="[title]simpleTest;simpleTest"></button></div>');

i18n.init( $.extend(opts, { resStore: resStore }),
function(t) { done(); });
Expand All @@ -117,7 +117,7 @@ describe('jQuery integration / specials', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="[title]simpleTest;simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="[title]simpleTest;simpleTest"></button></div>');

i18n.init( $.extend(opts, { resStore: resStore }),
function(t) { done(); });
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('jQuery integration / specials', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="[title]simpleTest;simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="[title]simpleTest;simpleTest"></button></div>');

i18n.init( $.extend(opts, {
resStore: resStore,
Expand All @@ -184,4 +184,4 @@ describe('jQuery integration / specials', function() {

});

});
});
3 changes: 2 additions & 1 deletion spec/spec.js
Expand Up @@ -19,6 +19,7 @@ describe('i18next', function() {
getAsync: true,
returnObjectTrees: false,
debug: true,
selectorAttr: 'data-i18n',
postProcess: ''
};
});
Expand All @@ -29,4 +30,4 @@ describe('i18next', function() {
//= functions.translation.spec.js
//= jquery.spec.js

});
});
3 changes: 2 additions & 1 deletion src/i18next.defaults.js
Expand Up @@ -10,6 +10,7 @@ var o = {
ns: 'translation',
nsseparator: ':',
keyseparator: '.',
selectorAttr: 'data-i18n',
debug: false,

resGetPath: 'locales/__lng__/__ns__.json',
Expand Down Expand Up @@ -41,4 +42,4 @@ var o = {
useCookie: true,

postProcess: undefined
};
};
6 changes: 3 additions & 3 deletions src/i18next.jquery.js
Expand Up @@ -32,7 +32,7 @@ function addJqueryFunct() {
}

function localize(ele, options) {
var key = ele.attr('data-i18n');
var key = ele.attr(o.selectorAttr);
if (!key) return;

if (!options && o.useDataAttrOptions === true) {
Expand Down Expand Up @@ -61,10 +61,10 @@ function addJqueryFunct() {
localize($(this), options);

// localize childs
var elements = $(this).find('[data-i18n]');
var elements = $(this).find('[' + o.selectorAttr + ']');
elements.each(function() {
localize($(this), options);
});
});
};
}
}
10 changes: 6 additions & 4 deletions test/test.js
Expand Up @@ -19,6 +19,7 @@ describe('i18next', function() {
getAsync: true,
returnObjectTrees: false,
debug: true,
selectorAttr: 'data-i18n',
postProcess: ''
};
});
Expand Down Expand Up @@ -1040,7 +1041,7 @@ describe('i18next', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="simpleTest"></button></div>');

i18n.init( $.extend(opts, { resStore: resStore }),
function(t) { done(); });
Expand All @@ -1067,7 +1068,7 @@ describe('i18next', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="[title]simpleTest;simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="[title]simpleTest;simpleTest"></button></div>');

i18n.init( $.extend(opts, { resStore: resStore }),
function(t) { done(); });
Expand All @@ -1094,7 +1095,7 @@ describe('i18next', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="[title]simpleTest;simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="[title]simpleTest;simpleTest"></button></div>');

i18n.init( $.extend(opts, { resStore: resStore }),
function(t) { done(); });
Expand Down Expand Up @@ -1139,7 +1140,7 @@ describe('i18next', function() {
};

beforeEach(function(done) {
setFixtures('<div id="container"><button id="testBtn" data-i18n="[title]simpleTest;simpleTest"></button></div>');
setFixtures('<div id="container"><button id="testBtn" ' + opts.selectorAttr + '="[title]simpleTest;simpleTest"></button></div>');

i18n.init( $.extend(opts, {
resStore: resStore,
Expand All @@ -1162,5 +1163,6 @@ describe('i18next', function() {
});

});


});

0 comments on commit 6683d4c

Please sign in to comment.