diff --git a/app/controllers/concerns/spree/admin/translatable.rb b/app/controllers/concerns/spree/admin/translatable.rb index 0f42658f1d..71e6abca89 100644 --- a/app/controllers/concerns/spree/admin/translatable.rb +++ b/app/controllers/concerns/spree/admin/translatable.rb @@ -13,20 +13,14 @@ def edit_translations private def save_translation_values - translation_params = params[:translation] - active_translations = Set.new - current_store.supported_locales_list.each do |locale| - translation_params.each do |attribute, translations| - if !translations[locale].blank? - active_translations << locale - end - end - end + translation_params = params[:translation].to_h - active_translations = active_translations.to_a + current_store_locales = current_store.supported_locales_list + params_locales = translation_params.flat_map { |_attribute, translations| translations.compact_blank.keys } + locales_to_update = current_store_locales & params_locales - active_translations.each do |locale| - translation = @object.translations.find_or_create_by(locale: locale) + locales_to_update.each do |locale| + translation = @object.translations.find_or_initialize_by(locale: locale) translation_params.each do |attribute, translations| translation.public_send("#{attribute}=", translations[locale]) end