You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :set_locale
def set_locale
if request.subdomains.first == 'ro'
I18n.locale = 'ro'
elsif request.subdomains.first == 'en'
I18n.locale = 'en'
else
I18n.locale = 'en'
end
end
end
#/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: I18n.t('some_table.some_action.confirmation_message')
end
end
Expected behaviour: The confirmation message should be translated in ro or en, 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:
#/active_scaffold/lib/active_scaffold/data_structures/action_link.rb
def confirm(label = '')
return @confirm if !confirm? || @confirm.is_a?(String)
return @confirm.call if !confirm? || @confirm.is_a?(Proc) # this line is new
ActiveScaffold::Registry.cache(:translations, @confirm) { as_(@confirm) } % {label: label}
end
#/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: -> { I18n.t('some_table.some_action.confirmation_message') } # this line is changed
end
end
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.
The text was updated successfully, but these errors were encountered:
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.
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.
The text was updated successfully, but these errors were encountered: