Hi! I could not find it so far - but maybe rails i18n is the right list for that question: is there something already available somewhere in the ruby space to remove accents and other diacritics from a string ? (like: translation éphémère to ephemere, etc) I've seen the mephisto PermalinkFu trick (iconv from utf-8 to ascii//ignore//translit) but it doesn't work on my workstation. I've attached DiacriticsFu which I wrote and is working fine for me - I'd be happy to find something cleaner, cross-platform, and which does not rely on Rails like this implementation (it would most likely work with unicode hacks) any hint, comment, link, idea ? cheers Thibaut
on 23.08.2007 18:00
on 08.09.2007 00:56
Same question as you Guillaume. Thibaut Barrère wrote: > Hi! > > I could not find it so far - but maybe rails i18n is the right list for > that > question: is there something already available somewhere in the ruby > space > to remove accents and other diacritics from a string ? (like: > translation > éphémère to ephemere, etc) > > I've seen the mephisto PermalinkFu trick (iconv from utf-8 to > ascii//ignore//translit) but it doesn't work on my workstation. > > I've attached DiacriticsFu which I wrote and is working fine for me - > I'd be > happy to find something cleaner, cross-platform, and which does not rely > on > Rails like this implementation (it would most likely work with unicode > hacks) > > any hint, comment, link, idea ? > > cheers > > Thibaut
on 16.11.2007 11:23
I wrote this extension to String a long time ago. I think it does what
you want.
require 'iconv'
class String
def pretty_url
Iconv.iconv("ASCII//IGNORE//TRANSLIT", "UTF-8", self).join.sanitize
rescue
self.sanitize
end
def sanitize
self.gsub(/[^a-z._0-9 -]/i, "").tr(".", "_").gsub(/(\s+)/,
"_").dasherize.downcase
end
end
Thibaut Barrère wrote:
> Hi!
>
> I could not find it so far - but maybe rails i18n is the right list for
> that
> question: is there something already available somewhere in the ruby
> space
> to remove accents and other diacritics from a string ? (like:
> translation
> éphémère to ephemere, etc)
>
> I've seen the mephisto PermalinkFu trick (iconv from utf-8 to
> ascii//ignore//translit) but it doesn't work on my workstation.
>
> I've attached DiacriticsFu which I wrote and is working fine for me -
> I'd be
> happy to find something cleaner, cross-platform, and which does not rely
> on
> Rails like this implementation (it would most likely work with unicode
> hacks)
>
> any hint, comment, link, idea ?
>
> cheers
>
> Thibaut
on 16.11.2007 11:38
Hi, On Nov 16, 2007 5:23 AM, Johan Stille <johan@withaspoon.se> wrote: > self.gsub(/[^a-z._0-9 -]/i, "").tr(".", "_").gsub(/(\s+)/, "_").dasherize.downcase > end > end There's a missing dasherize method here, no? -Pat