Closed rafaelfaria closed 9 years ago
Maybe something like this
var slug = function(str) { str = str.replace(/^\s+|\s+$/g, ''); // trim str = str.toLowerCase();
// remove accents, swap ñ for n, etc var from = "ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;"; var to = "aaaaaeeeeeiiiiooooouuuunc------"; for (var i=0, l=from.length ; i<l ; i++) { str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i)); }
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars .replace(/\s+/g, '-') // collapse whitespace and replace by - .replace(/-+/g, '-'); // collapse dashes
return str; };
?
OK, I added a transliteration option so you can translate from character(s) to any character(s). The default settings are as such:
transliteration: [
{from: 'àáâäã', to: 'a'}
{from: 'æ', to: 'ae'}
{from: 'ç', to: 'c'}
{from: 'èéêëẽ', to: 'e'}
{from: 'ìíîï', to: 'i' }
{from: 'ñ', to: 'n' }
{from: 'òóôöõ', to: 'o'}
{from: 'ùúûü', to: 'u'}
]
Please update to the latest version (0.2.0) and see if this is working for you.
@rafaelfaria - is version 0.2.0 working for you?
@todda00 like a charm! :)
Is this configurable?
Thank you! :)
Yes, you can set a custom translation set, see the Transliteration section of the readme for details.
Is there any option to keep the accents on the vowel? Portuguese words has heaps of accents and i don't know how to deal with it.
For instance. Suécia, should be suecia, not sucia. Coração, should be coracao, not corao.
thanks in advanced