How to retrieve all translations from yml files in Rails I18n

前端 未结 6 1159
Happy的楠姐
Happy的楠姐 2020-12-24 11:38

I\'m guessing that rails stores all the parsed translations yml files in a sort of array/hash. Is there a way to access this?

For example, if I\'ve a file:



        
6条回答
  •  滥情空心
    2020-12-24 12:36

    If you are using I18n::Fallbacks unfortunately you can't use I18n.t('.') as it just returns the contents current locale (eg. 'en-GB') and nothing from any of the fallback locales (eg 'en'). To get round this you can iterate over the fallbacks and use deep_merge! to combine them.

    module I18n
      class << self
        def all
          fallbacks[I18n.locale].reverse.reduce({}) do |translations, fallback|
            translations.deep_merge!(backend.translate(fallback, '.'))
          end
        end
      end
    end
    

提交回复
热议问题