The default value of Rails i18n

There is a full English translation in my current application, but I can’t make sure that the additional languages ​​are fully implemented.

This leads to warnings about translation, or rather, lines like "de, install, steps, language"

Is there any way to tell the rails to use the English translation if there is no German (in this example)?

+3
source share
6 answers

@tsdbrown is a good suggestion. Mine is a little more simplified. For example, when you create your German resource file, one way to get closer to it is to start with your English file and transfer it to your translators. All that they do not translate still exists, only in English. Then you do not have this problem at all. Another advantage of using this method is that you guarantee that you want to completely translate the file, you do not need to do a giant search and compare to add missing lines.

+2
source

We have this in config/initializers/i18n.rb:

module I18n
  # For MissingTranslationData, fall back to the default locale and then to the last key.
  # For other exceptions, use the default_exception_handler.
  def self.fallback_exception_handler(exception, locale, key, options)
    options ||= {}
    if !Rails.env.development? && exception.is_a?(MissingTranslationData)
      if locale == self.default_locale
        send(:normalize_translation_keys, locale, key, options[:scope]).last.to_s
      else
        self.t(key, options.merge(:locale => self.default_locale))
      end
    else
      send :default_exception_handler, exception, locale, key, options
    end
  end

end

I18n.exception_handler = :fallback_exception_handler

Please note that he will not back down in development, in design (so you will notice the lack of translations).

, Rails 2. , Rails 3.

+3

NinjaCat. Henrik +1!

( de) , +++, .

:

I18N , , Rails I18N - dev-, I18N , - , , , , ... ( , L10N, - ).

http://unixgods.org/~tilo/Rails/where_is_Rails_trying_to_lookup_L10N_strings.html

. :

Rails/I18n:

+1

!

Rails " " .

Rails , : , config/application.rb.

+1

Source: https://habr.com/ru/post/1759859/


All Articles