It's been many years since I first arrived to this question as I had the exact same problem. The problem hasn't grown smaller, I am more frustrated than ever.
Here is an experimental project, it hooks into the translate lookup and increments the translation key counter in Redis:
https://github.com/paladinsoftware/i18n-counter
The idea is that you can pull the stats and compare. (WIP for the moment, I would love help ofc)
You may ask: "won't that slow down the lookups?"
And you are right of course, but the overhead is hardly noticeable, check out this benchmark.
require 'benchmark'
n = 100000
Benchmark.bm do |x|
x.report { ENV['ENABLE_I18N_COUNTER'] = 'true'; n.times do ; I18n.translate('application.contract_not_available.header'); end }
x.report { ENV['ENABLE_I18N_COUNTER'] = 'false'; n.times do ; I18n.translate('application.contract_not_available.header'); end }
end
---------------------------------------------
| Benchmark | Seconds | Sec pr translation |
|------------| --------- | ------------------ |
| with redis | 48.280000 | 0.0004828 |
| without | 9.010000 | 0.0000901 |
---------------------------------------------
The overhead being about 3 ms pr lookup. It boils down to the number of lookups you do per page/request.
I18n.t(method_returning_the_key)
. It is possible to ignore such keys withconfig/i18n-tasks.yml
. – Purkey