Skip to content

Commit

Permalink
Use Globalize instead of I18n for translating globalize fields
Browse files Browse the repository at this point in the history
  • Loading branch information
benhutton committed Nov 15, 2014
1 parent 91ccc0a commit 88e20cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
6 changes: 3 additions & 3 deletions app/views/rails_admin/main/globalize.html.haml
Expand Up @@ -31,7 +31,7 @@
= raw @object.send(t)

.span8
- I18n.with_locale target_locale do
- Globalize.with_locale target_locale do
= render :partial => "globalize_field", :locals => { :object => @object, :form => form, :field => rails_admin_fields[t] }

- if @associated_translations
Expand All @@ -55,7 +55,7 @@
.original-content= raw obj.send(t)

.span8
- I18n.with_locale target_locale do
- Globalize.with_locale target_locale do
= render :partial => "globalize_field", :locals => {:field => field, :object => obj, :form => subform}

- @sub_associated_translations = collection.first.class.associated_model_to_globalize rescue nil
Expand All @@ -80,7 +80,7 @@
.original-content= raw sub_obj.send(t)

.span8
- I18n.with_locale target_locale do
- Globalize.with_locale target_locale do
= render :partial => "globalize_field", :locals => {:field => field, :object => sub_obj, :form => subsubform}

- if @sub_associated_translations[:has_one].present?
Expand Down
32 changes: 14 additions & 18 deletions lib/rails_admin_globalize.rb
Expand Up @@ -43,25 +43,21 @@ class Globalize < Base

if request.get?
@target_locale = params[:target_locale] || @available_locales.first || I18n.locale

else
loc = @current_locale = I18n.locale
I18n.locale = @target_locale = params[:target_locale]

sanitize_params_for!(:update)

@object.set_attributes(params[@abstract_model.param_key])
@authorization_adapter && @authorization_adapter.attributes_for(:update, @abstract_model).each do |name, value|
@object.send("#{name}=", value)
end

if @object.save
I18n.locale = loc
flash[:notice] = I18n.t("rails_admin.globalize.success")
redirect_to back_or_index
else
I18n.locale = loc
flash[:alert] = I18n.t("rails_admin.globalize.error")
::Globalize.with_locale params[:target_locale] do
sanitize_params_for!(:update)

@object.set_attributes(params[@abstract_model.param_key])
@authorization_adapter && @authorization_adapter.attributes_for(:update, @abstract_model).each do |name, value|
@object.send("#{name}=", value)
end

if @object.save
flash[:notice] = I18n.t("rails_admin.globalize.success")
redirect_to back_or_index
else
flash[:alert] = I18n.t("rails_admin.globalize.error")
end
end
end
@object.inspect
Expand Down

0 comments on commit 88e20cc

Please sign in to comment.