[typo] to_url and remove_accents

Cristiano Dias crisdias at crisdias.com
Fri Nov 11 12:06:29 EST 2005

Hey there,

I am porting my blog (in Portuguese) to Typo and noticed that to_url
ignores characters with accents, like "ã", "á", "ç", etc.

If the idea behind to_url is to have a nice-looking URL in the browser
we need to get rid of these special characters, otherwise they will
show up as % entities in the URL box.

Having no idea if this is the best approach for the problem I created
a "remove_accents" function which I added to lib/transforms.rb.

Since I have no idea on how to submit a patch and this function is
really small I am going to post it here. 8-)

def remove_accents
	return if self.nil?
	temp = self.clone
	trans = [ [195,161,'a'],[195,160,'a'],[195,163,'a'],[195,162,'a'],[195,169,'e'],[195,170,'e'],[195,173,'i'],[195,179,'o'],[195,180,'o'],[195,181,'o'],[195,186,'u'],[195,188,'u'],[195,167,'c'],[195,129,'A'],[195,128,'A'],[195,131,'A'],[195,130,'A'],[195,137,'E'],[195,138,'E'],[195,141,'I'],[195,147,'O'],[195,148,'O'],[195,149,'O'],[195,154,'U'],[195,156,'U'],[195,135,'C']
	trans.each do |t|
		temp.gsub! sprintf("%c%c",t[0],t[1]),t[2]

Line 4 creates an array for each 2-byte Unicode entity and its
translation. It is important to point out that I have only covered
characters used in Portuguese, so it might be a good idea for people
in the list to contribute with more codes, like the ones for "ñ", for
example. Comments would make me very happy, since I am just starting
in this whole Ruby+Rails thing. :-)

I hope this helps,

CrisDias, o Síndico
www.vilago.com.br -- Seu site vai gostar de morar aqui

More information about the Typo-list mailing list