Created
March 7, 2012 15:03
-
-
Save isholgueras/1993676 to your computer and use it in GitHub Desktop.
Transliteration in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var normalize = (function() { | |
var from = "ÃÀÁÄÂÈÉËÊÌÍÏÎÒÓÖÔÙÚÜÛãàáäâèéëêìíïîòóöôùúüûÑñÇç", | |
to = "AAAAAEEEEIIIIOOOOUUUUaaaaaeeeeiiiioooouuuunncc", | |
mapping = {}; | |
for(var i = 0, j = from.length; i < j; i++ ) | |
mapping[ from.charAt( i ) ] = to.charAt( i ); | |
return function( str ) { | |
var ret = []; | |
for( var i = 0, j = str.length; i < j; i++ ) { | |
var c = str.charAt( i ); | |
if( mapping.hasOwnProperty( str.charAt( i ) ) ) | |
ret.push( mapping[ c ] ); | |
else | |
ret.push( c ); | |
} | |
return ret.join( '' ); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment