I think i found what is causing it, and if i’m right it’s a gotcha of
the highest order. The rule seems to be
“In your .yml file you cannot have a top-level key which has the
same name as one of your controllers and which points to a further
nested set of key-value pairs”
It seems that the controller names (or maybe resource names from
routes.rb) are pushed into the hash of translated terms automatically,
as part of the general mechanism of I18n - i guess this is what hooks
into routes to give you translated urls? I should have guessed this
before because i noticed that if i had these as top-level pairs in my
en.yml file:
en:
#url translations
users: users
account: account
quizzes: quizzes
questions: questions
user_session: user_session
these are all controllers in my app, and i automatically get translated
urls without having to do anything, if the urls contain these words. I
also have a taggings controller, so when i had this:
title:
main: Who Wants To Be A Millionaire? For Schools
taggings:
save_failed: Could not add this tag because {{message}}
flashes:
quiz:
saved: Your quiz has been saved
…the part that was breaking was that i added a top level key,
“taggings”, which points to another hash {“save_failed” => “Could not
add this tag because {{message}}”}. The actual bug was caused because
rails was expecting this to be a string, probably because of the
automatically added entry for “taggings” which DOES point to a string
(i’m guessing “taggings” is the default). So, it calls gsub on it,
it’s a hash rather than a string, and you get the error because you
can’t call gsub on a hash (it’s a private method).
That’s also why indenting it to be under flashes was fine: it doesn’t
fight with the default top level “taggings” key any more and there’s no
problem.
Does that make sense? I’m not sure if i explained it well.
So, another way to state my rule is:
“Controller names CAN be used as top level keys, and must point to a
simple value rather than another hash. If present, these will be
translated in urls.”
or
“If you have a top level key which is the same name as one of your
controllers/resources, and it has further nested translations below it,
kiss your app goodbye”