From 12c858ec8edc694feb612ab72b5a09ae436d7940 Mon Sep 17 00:00:00 2001 From: cpfarher Date: Thu, 13 Jul 2017 18:20:25 -0300 Subject: [PATCH 1/3] add I18n to resources --- config/locales/en.yml | 10 ++++++++++ config/locales/es.yml | 10 ++++++++++ .../dsl.rb | 17 ++++++++++------- .../resource_extension.rb | 4 ++-- .../version.rb | 2 +- 5 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 config/locales/en.yml create mode 100644 config/locales/es.yml diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..c911b0c --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,10 @@ +active_admin_scoped_collection_actions: + sidebar_msg: 'This batch operations affect selected records. Or if none is selected, it will involve all records by current filters and scopes.' + confirm_action_message: 'Are you sure?' + actions: + delete: 'Delete batch' + update: 'Update batch' + no_permissions_msg: 'Access denied' + batch_update_status_msg: 'Batch update done' + batch_destroy_status_msg: 'Batch destroy done' + fail_on_destroy_msg: 'Cant be destroyed' \ No newline at end of file diff --git a/config/locales/es.yml b/config/locales/es.yml new file mode 100644 index 0000000..4e00289 --- /dev/null +++ b/config/locales/es.yml @@ -0,0 +1,10 @@ +active_admin_scoped_collection_actions: + sidebar_msg: 'Estas operaciones afectan las filas seleccionadas o en caso que no halla seleccionado ninguna, afectará a todo los registros afectados por los filtros aplicados.' + confirm_action_message: '¿Está seguro que quiere realizar esta acción?' + actions: + delete: 'Batch Borrado' + update: 'Batch Actualizado' + no_permissions_msg: 'Permiso denegado' + batch_update_status_msg: 'Batch actualizado correctamente' + batch_destroy_status_msg: 'Batch destruido correctamente' + fail_on_destroy_msg: 'No se puede eliminar' \ No newline at end of file diff --git a/lib/active_admin_scoped_collection_actions/dsl.rb b/lib/active_admin_scoped_collection_actions/dsl.rb index ddc8cba..d9052f6 100644 --- a/lib/active_admin_scoped_collection_actions/dsl.rb +++ b/lib/active_admin_scoped_collection_actions/dsl.rb @@ -3,10 +3,13 @@ module DSL def scoped_collection_action(name, options = {}, &block) if name == :scoped_collection_destroy - options[:title] = 'Delete batch' if options[:title].nil? + + + + options[:title] = I18n.t('active_admin_scoped_collection_actions.actions.delete') if options[:title].nil? add_scoped_collection_action_default_destroy(options, &block) elsif name == :scoped_collection_update - options[:title] = 'Update batch' if options[:title].nil? + options[:title] = I18n.t('active_admin_scoped_collection_actions.actions.update') if options[:title].nil? add_scoped_collection_action_default_update(options, &block) else batch_action(name, if: proc { false }, &block) @@ -19,7 +22,7 @@ def scoped_collection_action(name, options = {}, &block) def add_scoped_collection_action_default_update(options, &block) batch_action :scoped_collection_update, if: proc { false } do unless authorized?(:batch_edit, resource_class) - flash[:error] = 'Access denied' + flash[:error] = I18n.t('active_admin_scoped_collection_actions.actions.no_permissions_msg') render nothing: true, status: :no_content and next end if !params.has_key?(:changes) || params[:changes].empty? @@ -36,7 +39,7 @@ def add_scoped_collection_action_default_update(options, &block) end end if errors.empty? - flash[:notice] = 'Batch update done' + flash[:notice] = I18n.t('active_admin_scoped_collection_actions.batch_update_status_msg') else flash[:error] = errors.join(". ") end @@ -49,7 +52,7 @@ def add_scoped_collection_action_default_update(options, &block) def add_scoped_collection_action_default_destroy(_, &block) batch_action :scoped_collection_destroy, if: proc { false } do |_| unless authorized?(:batch_destroy, resource_class) - flash[:error] = 'Access denied' + flash[:error] = I18n.t('active_admin_scoped_collection_actions.actions.no_permissions_msg') render nothing: true, status: :no_content and next end if block_given? @@ -58,11 +61,11 @@ def add_scoped_collection_action_default_destroy(_, &block) errors = [] scoped_collection_records.find_each do |record| unless destroy_resource(record) - errors << "#{record.attributes[resource_class.primary_key]} | Cant be destroyed}" + errors << "#{record.attributes[resource_class.primary_key]} | #{I18n.t('active_admin_scoped_collection_actions.fail_on_destroy_msg')}}" end end if errors.empty? - flash[:notice] = 'Batch destroy done' + flash[:notice] = I18n.t('active_admin_scoped_collection_actions.batch_destroy_status_msg') else flash[:error] = errors.join(". ") end diff --git a/lib/active_admin_scoped_collection_actions/resource_extension.rb b/lib/active_admin_scoped_collection_actions/resource_extension.rb index 969035d..77f305b 100644 --- a/lib/active_admin_scoped_collection_actions/resource_extension.rb +++ b/lib/active_admin_scoped_collection_actions/resource_extension.rb @@ -51,7 +51,7 @@ def scoped_collection_sidebar_condition def scoped_collection_actions_sidebar_section ActiveAdmin::SidebarSection.new :collection_actions, only: :index, if: scoped_collection_sidebar_condition do - div 'This batch operations affect selected records. Or if none is selected, it will involve all records by current filters and scopes.' + div I18n.t('active_admin_scoped_collection_actions.sidebar_msg') active_admin_config.scoped_collection_actions.each do |key, options={}| b_title = options.fetch(:title, ::ActiveSupport::Inflector.humanize(key)) @@ -64,7 +64,7 @@ def scoped_collection_actions_sidebar_section if options[:form].present? b_data[:inputs] = options[:form].is_a?(Proc) ? options[:form].call : options[:form] end - b_data[:confirm] = options.fetch(:confirm, 'Are you sure?') + b_data[:confirm] = options.fetch(:confirm, I18n.t('active_admin_scoped_collection_actions.confirm_action_message')) b_options[:data] = b_data.to_json button b_title, b_options end diff --git a/lib/active_admin_scoped_collection_actions/version.rb b/lib/active_admin_scoped_collection_actions/version.rb index a743813..fbb59ed 100644 --- a/lib/active_admin_scoped_collection_actions/version.rb +++ b/lib/active_admin_scoped_collection_actions/version.rb @@ -1,3 +1,3 @@ module ActiveAdminScopedCollectionActions - VERSION = "0.3.0" + VERSION = "0.3.1" end From 7352108031b4ee09b04b686bd573dee50d979887 Mon Sep 17 00:00:00 2001 From: cpfarher Date: Fri, 14 Jul 2017 07:37:18 -0300 Subject: [PATCH 2/3] fix translation --- config/locales/en.yml | 21 +++++++++++---------- config/locales/es.yml | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index c911b0c..a8c6eb7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,10 +1,11 @@ -active_admin_scoped_collection_actions: - sidebar_msg: 'This batch operations affect selected records. Or if none is selected, it will involve all records by current filters and scopes.' - confirm_action_message: 'Are you sure?' - actions: - delete: 'Delete batch' - update: 'Update batch' - no_permissions_msg: 'Access denied' - batch_update_status_msg: 'Batch update done' - batch_destroy_status_msg: 'Batch destroy done' - fail_on_destroy_msg: 'Cant be destroyed' \ No newline at end of file +en: + active_admin_scoped_collection_actions: + sidebar_msg: 'This batch operations affect selected records. Or if none is selected, it will involve all records by current filters and scopes.' + confirm_action_message: 'Are you sure?' + actions: + delete: 'Delete batch' + update: 'Update batch' + no_permissions_msg: 'Access denied' + batch_update_status_msg: 'Batch update done' + batch_destroy_status_msg: 'Batch destroy done' + fail_on_destroy_msg: 'Cant be destroyed' \ No newline at end of file diff --git a/config/locales/es.yml b/config/locales/es.yml index 4e00289..b2e2a87 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,10 +1,11 @@ -active_admin_scoped_collection_actions: - sidebar_msg: 'Estas operaciones afectan las filas seleccionadas o en caso que no halla seleccionado ninguna, afectará a todo los registros afectados por los filtros aplicados.' - confirm_action_message: '¿Está seguro que quiere realizar esta acción?' - actions: - delete: 'Batch Borrado' - update: 'Batch Actualizado' - no_permissions_msg: 'Permiso denegado' - batch_update_status_msg: 'Batch actualizado correctamente' - batch_destroy_status_msg: 'Batch destruido correctamente' - fail_on_destroy_msg: 'No se puede eliminar' \ No newline at end of file +es: + active_admin_scoped_collection_actions: + sidebar_msg: 'Estas operaciones afectan las filas seleccionadas o en caso que no halla seleccionado ninguna, afectará a todo los registros afectados por los filtros aplicados.' + confirm_action_message: '¿Está seguro que quiere realizar esta acción?' + actions: + delete: 'Batch Borrado' + update: 'Batch Actualizado' + no_permissions_msg: 'Permiso denegado' + batch_update_status_msg: 'Batch actualizado correctamente' + batch_destroy_status_msg: 'Batch destruido correctamente' + fail_on_destroy_msg: 'No se puede eliminar' \ No newline at end of file From 92611b27b25be7f25a0eae749c8fe395015e0863 Mon Sep 17 00:00:00 2001 From: cpfarher Date: Fri, 14 Jul 2017 07:38:15 -0300 Subject: [PATCH 3/3] bump version --- lib/active_admin_scoped_collection_actions/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_admin_scoped_collection_actions/version.rb b/lib/active_admin_scoped_collection_actions/version.rb index fbb59ed..ac6696c 100644 --- a/lib/active_admin_scoped_collection_actions/version.rb +++ b/lib/active_admin_scoped_collection_actions/version.rb @@ -1,3 +1,3 @@ module ActiveAdminScopedCollectionActions - VERSION = "0.3.1" + VERSION = "0.3.2" end