I use Gettext, as it provides an elegant (and, for translators,
familiar) way of localizing. Make sure to read the localization
manual on the Rails site before you do anything else:
http://manuals.rubyonrails.com/read/chapter/82
In most cases that is enough, but if you also need to localize
dynamic content (which most people don''t, but I occasionally have
to), it gets a bit trickier. I usually solve that by storing hashes
instead of strings, where the language code is used as key, in the DB.
Error messages are a bit messy to translate as well. You can either
ditch the automatically generated messages entirely and define error
messages explicitly, like this:
class MyModel < ActiveRecord::Base
validates_lengh_of :username, :min => 4, :message => _("Username
must be at least 4 characters long")
end
You would then need to use ActiveRecord::Errors#each instead of
#each_full when displaying the error messages. Or, alternatively, you
could do like me and hijack the dynamically generated error messages.
It''s a bit hackish and you need to find a way of predicting which
error messages that will be generated, but the worst thing that can
happen is that a message slips through without being translated. You
can find a modified version of ActiveRecordHelper#error_messages_for
on my blog that does just that:
http://samuelk.info/articles/2005/05/18/translating-rails-apps
(that way, you can simply use <%= error_messages_for(@some_object) %>
and get translated output)
//samuel
8 jul 2005 kl. 11.04 skrev Philippe Creytens:
> Hi
>
> I am a newbie on Rails. I am trying to figure out how
> to implement a multiple language site. How do you deal
> with navigation, error messages coming from Rails etc.
>
> Anybody have practical suggestions?
>
> Tnx
>
> -- PC
>
> -- PC
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________
Samuel Kvarnbrink
mail: samuel.kvarnbrink-SiIintg/mUyhy6ZWzZ/+Cw@public.gmane.org
blog: http://samuelk.info
Hofstadter''s Law:
"It always takes longer than you expect, even if
you take into account Hofstadter''s Law."