# Transform non-english text

**URL:** <https://www.ruby-forum.com/t/transform-non-english-text/82313>\
**Category:** Ruby\
**Created:** [January 19, 2007, 10:19am UTC](https://www.ruby-forum.com/t/transform-non-english-text/82313 "2007-01-19T10:19:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![migrate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@migrate](https://www.ruby-forum.com/u/migrate)\
**Post date:** [January 19, 2007, 10:19am UTC](https://www.ruby-forum.com/t/transform-non-english-text/82313/1 "2007-01-19T10:19:12Z")

</div>

Hello,  
I have a Ruby aplication that deals with non-english text and I want to  
transform some of that text to [^a-zA-Z0-9].  
Examples:  
bÃºsqueda -\> busqueda  
presenÃ§as -\> presencas  
fÃ¼r -\> fur  
aviÃ£o1 -\> aviao1

Call anyone help me?

Thanks.  
Best regards,  
Migrate

---

<div class="post-metadata">

**Author:** ![migrate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@migrate](https://www.ruby-forum.com/u/migrate)\
**Post date:** [January 19, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/transform-non-english-text/82313/2 "2007-01-19T16:29:31Z")

</div>

Le 19 janvier 2007 à 10:19, Hu Ma a écrit :

> Hello,  
> I have a Ruby aplication that deals with non-english text and I want to  
> transform some of that text to [^a-zA-Z0-9].

You could try with Iconv to convert from your encoding to ASCII. Quick  
example :

> > require “iconv”  
> > =\> true
> 
> > Iconv.iconv(“ascii//translit”, “iso-8859-1”, “aéioù”)  
> > =\> [“a’eio`u”]
> 
> > Iconv.iconv(“ascii//translit”, “iso-8859-1”, “aéiou”)[0].tr(’^a-z’, ‘’)  
> > =\> “aeiou”

Fred

---

<div class="post-metadata">

**Author:** ![migrate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@migrate](https://www.ruby-forum.com/u/migrate)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/transform-non-english-text/82313/3 "2007-01-19T16:30:08Z")

</div>

I don’t think there is a unified mapping table to transform  
non-[^a-zA-Z0-9]  
characters into a specific one of them. But if you can concider to write  
a  
map yourself try something like:

class String  
MAP = [[/Ã¼/, ‘u’],  
[/Ã¶/, ‘o’]]

def eng\_char  
res = String.new(self)  
MAP.each { |r| res = res.gsub(r[0],r[1]) }  
return res  
end

end

s = “abÃ¼cÃ¼Ã¶Ã¶”  
puts s + " =\> " + s.eng\_char

* * *

Will output:

abÃ¼cÃ¼Ã¶Ã¶ =\> abucuoo

Martin

---

<div class="post-metadata">

**Author:** ![migrate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@migrate](https://www.ruby-forum.com/u/migrate)\
**Post date:** [January 23, 2007, 9:26am UTC](https://www.ruby-forum.com/t/transform-non-english-text/82313/4 "2007-01-23T09:26:18Z")

</div>

F. Senault wrote:

> > > require “iconv”  
> > > =\> true
> > 
> > > Iconv.iconv(“ascii//translit”, “iso-8859-1”, “aéioù”)  
> > > =\> [“a’eio`u”]
> > 
> > > Iconv.iconv(“ascii//translit”, “iso-8859-1”, “aéiou”)[0].tr(’^a-z’, ‘’)  
> > > =\> “aeiou”

iconv translit is really nice… when it works. It works on our FreeBSD  
server but not on my ubuntu dev machine. Your mileage may vary.

Daniel

---

<div class="post-metadata">

**Author:** ![migrate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@migrate](https://www.ruby-forum.com/u/migrate)\
**Post date:** [January 20, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/transform-non-english-text/82313/5 "2007-01-20T12:02:26Z")

</div>

Hello,

Thanks for your help.

I will try both approaches to see what fits best.

Best regards,  
Migrate

Martin B. wrote:

> I don’t think there is a unified mapping table to transform  
> non-[^a-zA-Z0-9]  
> characters into a specific one of them. But if you can concider to write  
> a  
> map yourself try something like:
> 
> class String  
> MAP = [[/Ã¼/, ‘u’],  
> [/Ã¶/, ‘o’]]
> 
> def eng\_char  
> res = String.new(self)  
> MAP.each { |r| res = res.gsub(r[0],r[1]) }  
> return res  
> end
> 
> end
> 
> s = “abÃ¼cÃ¼Ã¶Ã¶”  
> puts s + " =\> " + s.eng\_char
> 
> * * *
> 
> Will output:
> 
> abÃ¼cÃ¼Ã¶Ã¶ =\> abucuoo
> 
> Martin
