百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

i18n-debug

> 后端框架
开源

您曾经想过 Rails、一个 gem 或您的应用程序查找哪些翻译吗?不用再想了!

186 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

您曾经想过 Rails、一个 gem 或您的应用程序查找哪些翻译吗?不用再想了!

Ruby I18n Debug

Build Status Gem Version

Ever wondered which translations are being looked up by Rails, a gem, or simply your app? Wonder no more!

Rails' implicit translations, for instance, are a nice feature. But sometimes getting the key to, let's say, the BillingAddress' street attribute in a nested form inside an Order can be quite tricky to get right on the first try. The key for this example would be activerecord.attributes.order/billing_address.street. Good luck figuring that out!

With this gem you can easily see which translations are being looked up. The key above would have created the following debug log entry:

[i18n-debug] activerecord.attributes.order/billing_address.name => nil

After setting the translation for that key you just discovered, the log entry changes to this:

[i18n-debug] activerecord.attributes.order/billing_address.name => "Order billing name"

Installation

Simply add the gem to your Gemfile. You probably only want this in development. Thus, place it inside the development group.

ruby
gem 'i18n-debug', group: :development

If you need support for ruby <= 2.0, make sure to use version 1.0.0.

Usage

This gem works straight out of the box. If Rails is available, it will log using Rails.logger.debug. Otherwise it will log using Logger.new($stdout).debug.

If you wish to use a custom logger, simply set it as follows (make sure it responds to debug):

ruby
I18n::Debug.logger = my_custom_logger

Every lookup invokes the lambda I18n::Debug.on_lookup with the key and the translation value as arguments. The default lambda simply logs it to the logger mentioned above. If you want to change the logging format or do something totally different, simply set your own handler to do so:

ruby
# Collect stats on I18n key usage.
i18n_stats = Hash.new { |stats, key| stats[key] = 0 }

I18n::Debug.on_lookup do |key, value|
  i18n_stats[key] += 1 if value
end

Additional Information

Dependencies

  • i18n

Author

Philipe Fatio (fphilipe)

License

MIT License. Copyright 2014 Philipe Fatio

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubydebugi18nrailsruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架