列出具有完整键的 Rails I18n 字符串 [英] List Rails I18n strings with full keys

查看:9
本文介绍了列出具有完整键的 Rails I18n 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'd like to be able to generate a complete list of all the I18n keys and values for a locale including the full keys. In other words if I have these files:

config/locales/en.yml

en:
  greeting:
    polite: "Good evening"
    informal: "What's up?"

config/locales/second.en.yml

en:
  farewell:
    polite: "Goodbye"
    informal: "Later"

I want the following output:

greeting.polite: "Good evening"
greeting.informal: "What's up?"
farewell.polite: "Goodbye"
farewell.informal: "Later"

How do I do this?

解决方案

Once loaded into memory it's just a big Hash, which you can format any way you want. to access it you can do this:

I18n.backend.send(:translations)[:en]

To get a list of available translations (created by you or maybe by plugins and gems)

I18n.available_locales

这篇关于列出具有完整键的 Rails I18n 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆