From 7c9f0d0823bdce9a011d3bdd2823e15ffb7c1311 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 19 Jul 2009 19:02:31 +0200 Subject: updated globalize2 plugin --- .../lib/globalize/model/active_record/adapter.rb | 2 +- .../globalize/model/active_record/translated.rb | 23 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'vendor/plugins/globalize2/lib') diff --git a/vendor/plugins/globalize2/lib/globalize/model/active_record/adapter.rb b/vendor/plugins/globalize2/lib/globalize/model/active_record/adapter.rb index 71faebd..93355b8 100644 --- a/vendor/plugins/globalize2/lib/globalize/model/active_record/adapter.rb +++ b/vendor/plugins/globalize2/lib/globalize/model/active_record/adapter.rb @@ -73,7 +73,7 @@ module Globalize translations = @record.globalize_translations end result, requested_locale = nil, locale - + # Walk through the fallbacks, starting with the current locale itself, and moving # to the next best choice, until we find a match. # Check the @globalize_set_translations cache first to see if we've just changed the diff --git a/vendor/plugins/globalize2/lib/globalize/model/active_record/translated.rb b/vendor/plugins/globalize2/lib/globalize/model/active_record/translated.rb index c7ae9e9..f8fb230 100644 --- a/vendor/plugins/globalize2/lib/globalize/model/active_record/translated.rb +++ b/vendor/plugins/globalize2/lib/globalize/model/active_record/translated.rb @@ -23,10 +23,15 @@ module Globalize include InstanceMethods extend ClassMethods - alias_method_chain :reload, :globalize self.globalize_proxy = Globalize::Model::ActiveRecord.create_proxy_class(self) - has_many :globalize_translations, :class_name => globalize_proxy.name, :extend => Extensions + has_many( + :globalize_translations, + :class_name => globalize_proxy.name, + :extend => Extensions, + :dependent => :delete_all, + :foreign_key => class_name.foreign_key + ) after_save :update_globalize_record end @@ -109,7 +114,7 @@ module Globalize end module InstanceMethods - def reload_with_globalize + def reload(options = nil) globalize.clear # clear all globalized attributes @@ -118,7 +123,7 @@ module Globalize @attributes.delete attr.to_s end - reload_without_globalize + super options end def globalize @@ -132,6 +137,16 @@ module Globalize def translated_locales globalize_translations.scoped(:select => 'DISTINCT locale').map {|gt| gt.locale.to_sym } end + + def set_translations options + options.keys.each do |key| + + translation = globalize_translations.find_by_locale(key.to_s) || + globalize_translations.build(:locale => key.to_s) + translation.update_attributes!(options[key]) + end + end + end end end -- cgit v1.3