<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>http://regedor.com/ &#187; Inflections</title>
	<atom:link href="http://regedor.com/tag/inflections/feed/" rel="self" type="application/rss+xml" />
	<link>http://regedor.com</link>
	<description>Just another weblog written by an human</description>
	<lastBuildDate>Mon, 02 Nov 2009 19:42:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='regedor.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/7fc9f61f922100cfbf3dcbd3d66a0986?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>http://regedor.com/ &#187; Inflections</title>
		<link>http://regedor.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://regedor.com/osd.xml" title="http://regedor.com/" />
	<atom:link rel='hub' href='http://regedor.com/?pushpress=hub'/>
		<item>
		<title>Rewrite humanize</title>
		<link>http://regedor.com/2009/01/30/rewrite-humanize/</link>
		<comments>http://regedor.com/2009/01/30/rewrite-humanize/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 21:12:10 +0000</pubDate>
		<dc:creator>Regedor</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Inflections]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://miguelregedor.wordpress.com/?p=68</guid>
		<description><![CDATA[I have an application with all tables and field names in English, but the whole views now need to be in Portuguese. Because I&#8217;m always using the humanize method, a simple solutions should emerge. First solution: class Ticket HUMANIZED_ATTRIBUTES = { :category &#62; "Categoria", :title &#62; "Assunto" } def self.human_attribute_name(attr) HUMANIZED_ATTRIBUTES[attr.to_sym] &#124;&#124; super end end [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=regedor.com&amp;blog=2140217&amp;post=68&amp;subd=miguelregedor&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have an application with all tables and field names in English, but the whole views now need to be in Portuguese.</p>
<p>Because I&#8217;m always using the humanize method, a simple solutions should emerge.</p>
<p>First solution:<br />
<code></p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#800000;font-weight:bold;'>class</span> Ticket
  HUMANIZED_ATTRIBUTES <span style='color:#808030;'>=</span> <span style='color:#800080;'>{</span>
    :category &gt; <span style='color:#0000e6;'>"Categoria"</span>,
    :title &gt; <span style='color:#0000e6;'>"Assunto"</span>
  <span style='color:#800080;'>}</span>
  <span style='color:#800000;font-weight:bold;'>def</span> self<span style='color:#808030;'>.</span>human_attribute_name<span style='color:#808030;'>(</span>attr<span style='color:#808030;'>)</span>
    HUMANIZED_ATTRIBUTES<span style='color:#808030;'>[</span>attr<span style='color:#808030;'>.</span>to_sym<span style='color:#808030;'>]</span> || <span style='color:#800000;font-weight:bold;'>super</span>
  <span style='color:#800000;font-weight:bold;'>end</span>
<span style='color:#800000;font-weight:bold;'>end</span>
</pre>
<p></code><br />
Setting the human_attribue_name in each model works ok,<br />
but if like in my case, you have 20 models and all of them have a description, title,&#8230; much duplication&#8230;</p>
<p>So I thought in doing something similar to this in my enviroment.rb:<br />
<code></p>
<pre style='color:#000000;background:#ffffff;'>Inflector<span style='color:#808030;'>.</span>inflections <span style='color:#800000;font-weight:bold;'>do</span> |inflect|
  inflect<span style='color:#808030;'>.</span>plural <span style='color:#808030;'>/</span>^<span style='color:#808030;'>(</span>foo<span style='color:#808030;'>)</span>$<span style='color:#808030;'>/</span>i, <span style='color:#0000e6;'>'\1ze'</span>
  inflect<span style='color:#808030;'>.</span>singular <span style='color:#808030;'>/</span>^<span style='color:#808030;'>(</span>foo<span style='color:#808030;'>)</span>ze<span style='color:#808030;'>/</span>i, <span style='color:#0000e6;'>'\1'</span>
<span style='color:#800000;font-weight:bold;'>end</span>
</pre>
<p> </code><br />
But for the humanized method instead of pluralize. Yah It would make sense that way, but rails doesn&#8217;t provide that feature. You can go <a href="http://github.com/rails/rails/commit/4f75840d72b96fff34d65b59480da7d6c7494120#diff-1">here</a> to find a patch for getting that functionality into your rails, I hope they get that into the core&#8230; anyway If didn&#8217;t want to download the patch, how do I solve the problem?</p>
<p>Maybe a rubbish solution but perfect to get what I was needing, translate my views with few lines of code!<br />
What I&#8217;ve done? Just added those lines into my environment.rb<br />
<code></p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#800000;font-weight:bold;'>class</span> <span style='color:#400000;'>String</span>
  <span style='color:#800000;font-weight:bold;'>def</span> humanize
    <span style='color:#800080;'>{</span>:movie              <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Filme"</span>,
     :movies             <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Filmes"</span>,
     :name               <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Nome"</span>,
     :title              <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Título"</span>,
     :synopsis           <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Sinopse"</span>,
     :genre              <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Genero"</span>,
     :author             <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Autor"</span>,
     :authors            <span style='color:#808030;'>=</span>&gt; <span style='color:#0000e6;'>"Autores"</span>
     <span style='color:#808030;'>.</span><span style='color:#808030;'>.</span><span style='color:#808030;'>.</span>
    <span style='color:#800080;'>}</span><span style='color:#808030;'>[</span><span style='color:#800000;font-weight:bold;'>self</span><span style='color:#808030;'>.</span><span style='color:#400000;'>gsub</span><span style='color:#808030;'>(</span><span style='color:#808030;'>/</span>_id$<span style='color:#808030;'>/</span>, <span style='color:#0000e6;'>""</span><span style='color:#808030;'>)</span><span style='color:#808030;'>.</span>to_sym<span style='color:#808030;'>]</span> || <span style='color:#800000;font-weight:bold;'>super</span>
  <span style='color:#800000;font-weight:bold;'>end</span>
<span style='color:#800000;font-weight:bold;'>end</span>
</pre>
<p></code><br />
I simply redefined the humanize method for whole strings. It works perfectly in my case, because I&#8217;m always calling humanize in my views.</p>
<p>keep humanizing the world!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/miguelregedor.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/miguelregedor.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/miguelregedor.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/miguelregedor.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/miguelregedor.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/miguelregedor.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/miguelregedor.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/miguelregedor.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=regedor.com&amp;blog=2140217&amp;post=68&amp;subd=miguelregedor&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://regedor.com/2009/01/30/rewrite-humanize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/80583db5af674ca20393f42a20101129?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Regedor</media:title>
		</media:content>
	</item>
	</channel>
</rss>