How to retrieve all translations from yml files in Rails I18n

前端 未结 6 1152
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:21

    If you're doing this in a rake task, remember to include the enviroment, or otherwise it will not load your own locales which lives under config/locales/

    require "./config/environment.rb" # Do not forget this
    
    namespace :i18n do
      desc "Import I18n to I18n_active_record"
      task :setup do
        I18n.t(:foo)
        translations = I18n.backend.send(:translations)
      end
    end
    

提交回复
热议问题