(Not documented)
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 594
594: def self.included(klass)
595: klass.alias_method_chain :update, :translatable
596: klass.alias_method_chain :create, :translatable
597: klass.alias_method_chain :create, :i18n_fields
598:
599: end
(Not documented)
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 676
676: def attributes_except_unique_for_translation
677: attributes.reject{|attr, value| [:id, :locale].include?(attr.to_sym)}
678: end
proxy to add a new content_id if empty on creation
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 602
602: def create_with_i18n_fields
603: if self.class.is_translatable?
604: # we do this even if there is not currently any tr. attribute,
605: # as long as is a translatable model
606: unless self.content_id
607: self.content_id = self.class.connection.next_val_sequence("#{self.class.table_name}_$_content_id")
608: end
609: unless self.locale
610: self.locale = Locale.current
611: end
612: end
613: create_without_i18n_fields
614: end
Whenever we update existing content or create a translation, the expected behaviour is the following
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 619
619: def create_with_translatable
620: create_without_translatable
621: update_translations
622: end
(Not documented)
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 667
667: def untranslatable_attributes
668: attrs = {}
669: (untranslatable_attributes_names + [:content_id.to_s] - [:id.to_s]).each do |name|
670: attrs[name] = clone_attribute_value(:read_attribute, name)
671: end
672: attrs
673: end
(Not documented)
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 656
656: def untranslatable_attributes_names
657: translatable_attributes = (self.class.translatable_attributes || []) +
658: (self.class.instance_variable_get('@global_translatable_attributes') || []) +
659: (self.class.reflections.select do |name, ref|
660: ref.macro != :belongs_to ||
661: !ref.options[:translation_shared] ||
662: ((model = [send(name)].first) && model.class.is_translatable?)
663: end.map{|name, ref| ref.primary_key_name})
664: attribute_names - translatable_attributes.map{|attr| attr.to_s}
665: end
(Not documented)
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 641
641: def update_translations
642: if self.class.is_translatable? && !@stop_translatable_propagation
643: # Update the translations
644: self.translations.each do |translation|
645: translation.instance_variable_set('@stop_translatable_propagation', true)
646: begin
647: translation.update_attributes untranslatable_attributes
648: translation.copy_translatable_shared_relations_from self
649: ensure
650: translation.instance_variable_set('@stop_translatable_propagation', false)
651: end
652: end
653: end
654: end
(Not documented)
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 624
624: def update_with_translatable
625: if self.class.is_translatable? && !@stop_translatable_propagation
626: if Locale.current && !in_locale?(Locale.current)
627: translation = in_locale(Locale.current) || translate(Locale.current)
628: self.send(:attributes_except_unique_for_translation).each_pair do |attr, value|
629: translation.send("#{attr}=", value)
630: end
631: translation.save
632: else
633: update_without_translatable
634: update_translations
635: end
636: else
637: update_without_translatable
638: end
639: end
Used to execute a block disabling automatic translation update for this instance
# File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/extensions/active_record.rb, line 681
681: def without_updating_translations
682: @stop_translatable_propagation = true
683: begin
684: yield
685: ensure
686: @stop_translatable_propagation = false
687: end
688: end
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.