Does anyone have a JavaScript that they use in IDM that will take in a string and replace all accented characters with their non-accented equivalents? I've found a few online in non-IDM forums, like Stack Overflow or GitHub, that claim to work but when I plug them into IDM, they don't work.
If anyone has such a script that they use and know will work in IDM, I'd appreciate the knowledge transfer.
Request clarification before answering.
Here is the script that I have tested and seems to work for me. This was actually developed by a co-worker of mine. Hopefully it can save someone some time someday.
// Main function: Z_removeAccent
function Z_removeAccent(strAccents) {
var strAccents = strAccents.split('');
var strAccentsOut = new Array();
var strAccentsLen = strAccents.length;
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
for (var y = 0; y < strAccentsLen; y++) {
if (accents.indexOf(strAccents[y]) != -1) {
strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
} else
strAccentsOut[y] = strAccents[y];
}
strAccentsOut = strAccentsOut.join('');
strAccentsOut = strAccentsOut.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
strAccentsOut = strAccentsOut.replace(/ /g, '');
return strAccentsOut;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It covers the most common ones but in looking at it, I can see that there are some that will not work right. For instance, the German ß isn't accounted for here and the Æ character wouldn't be handled with this script either. If you want to add characters for translation in this script, you simply append them to the end of the, "accents" and, "accentsOut" variables.
For instance, to translate the ß to a B, you would do this:
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽžß';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZzB";
In reality, you would probably want to translate the ß to the letter, "s" since that's the sound the ß actually makes when speaking German, but you get the idea.
A more correct conversion for "ß" would be "ss", but that would give you the same issue as with trying to convert Æ or other digraphs using this method. For what its worth, my script below does handle both these and other similar cases.
I know this script 🙂
I found a script very similar to what you shared online and when I tried to use it, it didn't work. This is why I passed it over when you shared it below. Maybe I was calling it improperly in my environment. If it works for you then clearly I wasn't using it the correct way. I will revisit that script if my needs call for it down the line. Many thanks for your input.
LOL... Yes, you should recognize this one. Ya know, when I had this issue, I did not reach out to your team's IDM support and perhaps I should have done that. As a consultant, I still have some hesitation in asking the client for assistance because we're the consulting firm being hired for our expertise. We're supposed to have the answers. In my mind when I ask the client for help, it's like admitting to them that maybe we're not the experts we claim to be.
That said, nobody is perfect and no one knows it all, especially when it comes to IDM. I shouldn't assume the client expects us to be superhuman. Perhaps in this situation I shouldn't have been so reserved and I should have asked your team for assistance. I will remember this as the project moves forward. 🙂
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.