0
votes

Can I use a default I18n config for lookups if localisation file lookup fails?

As part of Rails, http://guides.rubyonrails.org/i18n.html#how-i18n-in-ruby-on-rails-works

As part of this solution, every static string in the Rails framework — e.g. Active Record validation messages, time and date formats — has been internationalized, so localization of a Rails application means “over-riding” these defaults.

So, when I add my own localisation files, I lose the default rails error text for ActiveRecord. e.g. given the following code within a Model

validates_length_of :name, :maximum => 50

When this fails, I get

translation missing: en-gb, activerecord, errors, models, model_name, attributes, name, too_long

Two possible fixes :

  1. Add :message to each and every validates_* method? e.g.

    validates_length_of :name, :maximum => 50, :message => "is too long (maximum is %{count} characters)"
    

    The problem with this is there are quite a few calls, and people adding new code would have to have remember to add the text. (And I dont think variable substitution works here!)

  2. Add the set of defaults that rails uses in each and every locale config file, e.g

    errors:
      messages:
        less_than: must be less than %{count}
    

    The problem here is that the same text has to be added to every locale file (as I am not interested in translating these), this is not that big off a deal, but seems odd.

Which, if any, routes are advised? Any other ideas or suggestions?

Is there no default/fallback file that the I18n uses, i.e. if the lookup cannot be found in the locale file?

(Using rails 2.3.5)

1

1 Answers

1
votes

I find the best thing here is to just include the rails-i18n gem in your project so that you have translations in all available locales. And then in your application's translation files, just override the ones you need.

Note : You'll need your project to use the same locales as defined by the gem, so in your example you'd want to use en-GB rather than en-gb.