Add feature to delete a translation

To delete a translation, a link has been added. This
link works for the selected language. It hides all the
things related to a language (the tab and the text_area)
and empties the text area, so that the value is blank
in the param hash. A variable called `delete_translations[]`
is changed.

e.g. If admin wants to remove English language,
delete_translations[:en] will be 1; if not, it will be 0.

When the milestone is updated, there is a before_action
callback that cleans the selected languages for deletion
(looking the delete_translations[] variable).
Because of the deleted translations are blank in param hash,
them won't be saved in DB.
This commit is contained in:
iagirre
2018-04-12 09:58:02 +02:00
parent f7486b9238
commit b318c2be46
7 changed files with 55 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ module Translatable
included do
before_action :set_translation_locale
before_action :delete_translations, only: [:update]
end
private
@@ -16,4 +17,15 @@ module Translatable
Globalize.locale = I18n.locale
end
end
def delete_translations
locales = Budget::Investment::Milestone.globalize_locales.
select { |k, v| params[:delete_translations].include?(k.to_sym) && params[:delete_translations][k] == "1" }
milestone = Budget::Investment::Milestone.find(params[:id])
locales.each do |l|
Globalize.with_locale(l) do
milestone.translation.destroy
end
end
end
end