guncebektas / meteor-friendly-slugs

Meteor package to generate URL friendly slugs from a field with auto-incrementation to ensure unique URLs.
65 stars 15 forks source link

accents #2

Closed rafaelfaria closed 9 years ago

rafaelfaria commented 9 years ago

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

rafaelfaria commented 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; };

?

todda00 commented 9 years ago

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.

todda00 commented 9 years ago

@rafaelfaria - is version 0.2.0 working for you?

rafaelfaria commented 9 years ago

@todda00 like a charm! :)

Is this configurable?

Thank you! :)

todda00 commented 9 years ago

Yes, you can set a custom translation set, see the Transliteration section of the readme for details.