Open spatarel opened 3 years ago
If you put I18n.t in active_scaffold block, is evaluated when app starts, so language doesn't change. You must set a symbol there, then active_scaffold will translate it, it will look for symbol under active_scaffold scope.
ActiveScaffold::Registry.cache is caching translation for current action, because when you have a long list, with many rows with same actions, it's faster to translate one and then use interpolation to replace %{label}, than translate many times.
It works like a charm! Thank you!
I will write down what I did, in case other people are interested in the topic:
#/config/locales/ro.yml
ro:
active_scaffold:
some_action_confirmation: 'RO message'
#/config/locales/en.yml
en:
active_scaffold:
some_action_confirmation: 'EN message'
#/app/controllers/some_table_controller.rb
class SomeTableController < ApplicationController
active_scaffold :some_table do |conf|
conf.action_links.add :some_action,
type: :collection, crud_type: :update,
method: :put, position: false,
confirm: :some_action_confirmation
end
end
I suppose there's no chance for Proc support, right?
I could accept a patch supporting proc, but I don't know if it would be any improvement
How to replicate:
Expected behaviour: The confirmation message should be translated in
ro
oren
, depdending on the subdomain.Actual behaviour: The confirmation message is translated in the default language.
Why is this happening?
set_locale
method runs afteractive_scaffold
is configured.How to fix it?
Option 1: Allow
confirm
parameter to be either a string or a Proc. Then this code should work:Option 2: Perhaps there is some other way of sending that confirmation message. But I don't understand what this line does:
ActiveScaffold::Registry.cache(:translations, @confirm) { as_(@confirm) } % {label: label}
Conclusion: I would choose Option 1, since even if there is already support for Option 2, Option 1 offers more flexibility.