Skip to content

Commit

Permalink
add accents dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed Apr 16, 2015
1 parent ac25f39 commit ecea421
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use strict';

module.exports = function(locale, options) {
options = options || {};
options.dictionary = options.dictionary || 'accents';

if(typeof options.dictionary === 'string'){
options.dictionary = dictionaries[options.dictionary];
}

var regexs = {};
for (var findString in options.dictionary) {
//don't replace characters inside html tags (between `<` and `>`)
Expand All @@ -17,3 +24,13 @@ module.exports = function(locale, options) {
function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
}

var dictionaries = {
'accents': {
'a': 'á',
'e': 'é',
'i': 'í',
'o': 'ó',
'u': 'ú'
}
};
22 changes: 22 additions & 0 deletions test/spec.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,26 @@ describe('s18n.map()', function() {
});
});

it('should default to the `accents` dictionary', function() {
var locale = {
'3c82f755': 'This is a test.'
};
var mappedLocale = s18n.map(locale);
assert.deepEqual(mappedLocale, {
'3c82f755': 'Thís ís á tést.'
});
});

it('should accept the `accents` dictionary', function() {
var locale = {
'3c82f755': 'This is a test.'
};
var mappedLocale = s18n.map(locale, {
dictionary: 'accents'
});
assert.deepEqual(mappedLocale, {
'3c82f755': 'Thís ís á tést.'
});
});

});

0 comments on commit ecea421

Please sign in to comment.