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

**URL:** <https://www.ruby-forum.com/t/removing-accents-from-sentences-ex-url-creations-whats/112835>\
**Category:** Rails I18n\
**Created:** [August 23, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/removing-accents-from-sentences-ex-url-creations-whats/112835 "2007-08-23T18:00:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [August 23, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/removing-accents-from-sentences-ex-url-creations-whats/112835/1 "2007-08-23T18:00:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [September 8, 2007, 12:56am UTC](https://www.ruby-forum.com/t/removing-accents-from-sentences-ex-url-creations-whats/112835/2 "2007-09-08T00:56:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [November 16, 2007, 11:23am UTC](https://www.ruby-forum.com/t/removing-accents-from-sentences-ex-url-creations-whats/112835/3 "2007-11-16T11:23:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [November 16, 2007, 11:38am UTC](https://www.ruby-forum.com/t/removing-accents-from-sentences-ex-url-creations-whats/112835/4 "2007-11-16T11:38:58Z")

</div>

Hi,

On Nov 16, 2007 5:23 AM, Johan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

There’s a missing dasherize method here, no?

-Pat
