Skip to content

Commit

Permalink
Fix logic for deprecation warnings when using deprecated translation key
Browse files Browse the repository at this point in the history
  • Loading branch information
olejrosendahl committed Mar 22, 2015
1 parent 9a56e0d commit 0e322ac
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/datagrid/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ module Translation
include ActionView::Helpers::TranslationHelper

def translate_from_namespace(namespace, grid_class, key)
deprecated_namespace = :"datagrid.#{grid_class.param_name}.#{namespace}.#{key}"
deprecated_translation_key = :"#{grid_class.param_name}.#{namespace}.#{key}"

Datagrid::Utils.warn_once(
"Deprecated translation namespace. Use 'datagrid.#{grid_class.model_name.i18n_key}' instead"
) if I18n.exists? deprecated_namespace
if grid_class.name.include?("::") && I18n.exists?(deprecated_translation_key)
Datagrid::Utils.warn_once(
"Deprecated translation namespace. Use 'datagrid.#{grid_class.model_name.i18n_key}' instead"
)
end

lookups = [
:"datagrid.#{grid_class.model_name.i18n_key}.#{namespace}.#{key}",
deprecated_namespace,
:"#{grid_class.model_name.i18n_key}.#{namespace}.#{key}",
deprecated_translation_key,
key.to_s.humanize
]
t(lookups.shift, default: lookups).presence
t(lookups.shift, scope: "datagrid", default: lookups).presence
end

end
Expand Down

0 comments on commit 0e322ac

Please sign in to comment.