diff --git a/lib/map.js b/lib/map.js index 6913e9c..72069b2 100644 --- a/lib/map.js +++ b/lib/map.js @@ -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 `>`) @@ -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': 'ú' + } +}; diff --git a/test/spec.map.js b/test/spec.map.js index bc196fc..66ebd35 100644 --- a/test/spec.map.js +++ b/test/spec.map.js @@ -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.' + }); + }); + });