# "private method \`gsub'" error caused by addition of a line

**URL:** <https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237>\
**Category:** Rails I18n\
**Created:** [April 20, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237 "2010-04-20T12:12:39Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 1:32pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/21 "2010-04-22T13:32:12Z")

</div>

The problem is that I18n can’t choose anything, because when the file  
is read, the second one overwrites the first one. This is done outside  
I18n.  
It’s logical too, because you’re actually saying something like this:  
{ :foo =\> 1, :foo =\> 2 } which will always result in { :foo =\> 2 }.

Gem authors should put their locales in front of the load\_paths, so  
that the locales from gems are overwritten by your own locales.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 1:44pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/22 "2010-04-22T13:44:30Z")

</div>

Hi Max, Iain.

I guess you misunderstood what is happening here… But you are right  
that I18n can give better hints instead of failing that way.

The key is not defined twice, I guess. I would guess that I18n searchs  
for a translation of a key with the name of the route (or are you using  
some plugin that does translate the route?). If it is a common behavior  
of I18n, it could be written to verify if the value is a String before  
calling gsub. It could assume the default (not translating the key)  
otherwise.

I’ll take a look at the documentation to see how I18n behaves about  
route translations.

Rodrigo.

Em 22-04-2010 08:30, Iain H. escreveu:

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 1:49pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/23 "2010-04-22T13:49:24Z")

</div>

Rodrigo Rosenfeld R. wrote:

> The key is not defined twice, I guess. I would guess that I18n searchs  
> for a translation of a key with the name of the route (or are you using  
> some plugin that does translate the route?).

No, this is all just the default I18n behaviour.

thanks for helping investigate 🙂  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 2:10pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/24 "2010-04-22T14:10:47Z")

</div>

I am a colossal ass. I am using the translate\_routes plugin and  
completely forgot. That’ll be the source of all of these problems,  
nothing to do with I18n. I’m going to go and punch myself in the balls  
a few times.

Sorry for all the confusion guys, and thanks again for your help.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 2:00pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/25 "2010-04-22T14:00:54Z")

</div>

Em 22-04-2010 08:49, Max W. escreveu:

> 

I’m not sure about this. I think I18n won’t translate routes  
automatically… Are you really sure you are not using any of these  
plugins:

translate\_routes: [GitHub - raul/translate\_routes: Rails plugin to translate your URLs and routing helpers on an clean way.](http://github.com/raul/translate_routes)  
locale\_rails: [http://www.yotabanana.com/hiki/ruby-locale-rails.html](http://www.yotabanana.com/hiki/ruby-locale-rails.html)

I created a fresh new Rails app and generated a new controller named  
TestsController. I modified the en.yml to look like this:

en:  
tests:  
hi: ola  
test  
hi: ola

Rails didn’t failed to start. So I guess this behavior is due to some  
plugin. Could you send us your plugin list or your error stacktrace?

Rodrigo.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/26 "2010-04-22T14:21:37Z")

</div>

Rodrigo Rosenfeld R. wrote:

> Em 22-04-2010 09:10, Max W. escreveu:
> 
> > I am a colossal ass. I am using the translate\_routes plugin and  
> > completely forgot. That’ll be the source of all of these problems,  
> > nothing to do with I18n. I’m going to go and punch myself in the balls  
> > a few times.
> > 
> > Sorry for all the confusion guys, and thanks again for your help.
> 
> Don’t torture yourself. Do something more useful instead: fill an issue  
> in their github Issues page stating this problem. They could improve  
> their plugin for not breaking the application on these cases… Or you  
> could save your energy avoiding puching your balls and try to write some  
> patch to the plugin that verify if the translation is a string before  
> using it… 🙂
> 
> Best regards,
> 
> Rodrigo.

thanks rodrigo, that does sound like a better use of my time and energy.

cheers, max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 22, 2010, 2:17pm UTC](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237/27 "2010-04-22T14:17:53Z")

</div>

Em 22-04-2010 09:10, Max W. escreveu:

> I am a colossal ass. I am using the translate\_routes plugin and  
> completely forgot. That’ll be the source of all of these problems,  
> nothing to do with I18n. I’m going to go and punch myself in the balls  
> a few times.
> 
> Sorry for all the confusion guys, and thanks again for your help.

Don’t torture yourself. Do something more useful instead: fill an issue  
in their github Issues page stating this problem. They could improve  
their plugin for not breaking the application on these cases… Or you  
could save your energy avoiding puching your balls and try to write some  
patch to the plugin that verify if the translation is a string before  
using it… 🙂

Best regards,

Rodrigo.

[Previous page](https://www.ruby-forum.com/t/private-method-gsub-error-caused-by-addition-of-a-line/187237.md?page=1)
