Removing accents from sentences (ex: url creations) - what's

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

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

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

Hi,

On Nov 16, 2007 5:23 AM, Johan S. [email protected] wrote:

self.gsub(/[^a-z._0-9 -]/i, "").tr(".", "_").gsub(/(\s+)/, "_").dasherize.downcase

end
end

There’s a missing dasherize method here, no?

-Pat