Ruby Forum Rails I18n > removing accents from sentences (ex: url creations) - what's

Posted by Thibaut Barrère (thbar)
on 23.08.2007 18:00
Attachment: diacritics_fu.rb (167 Bytes)
Attachment: diacritics_fu_spec.rb (922 Bytes)
(Received via mailing list)
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
Posted by Guillaume Differenthink (differenthink)
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
Posted by Johan Stille (withaspoon)
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
Posted by Patrick Hall (Guest)
on 16.11.2007 11:38
(Received via mailing list)
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