Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial stub work on making translatable versions
- Loading branch information
Walter McGinnis
committed
Oct 13, 2010
1 parent
ca64290
commit 9c55e96
Showing
5 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
lib/kete_translatable_content/extensions/extended_content_translation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# for ZOOM_CLASSES, extended_content is translatable_attribute | ||
# however, in mongodb we store indivdual values for the extended fields | ||
# and then we swap in actual translatable extended field values via individual | ||
# extended field setter methods (method missing methods) | ||
# the advantage is that we only have to tell mongo_translatable that extended_content | ||
# is translatable at the time of system startup | ||
# and we can go on declaring new extended fields dynamically | ||
module ExtendedContentTranslation | ||
unless included_modules.include? ExtendedContentTranslation | ||
|
||
# override so that we may have extended fields be translatable attributes | ||
def translatable_attributes | ||
# klass is ::Version classes parent namespace wise | ||
klass = original_class | ||
|
||
type = klass == Topic ? topic_type : ContentType.find_by_name(klass.name) | ||
|
||
fields = type.mapped_fields.select { |f| ['text', 'textarea', 'choice', 'autocomplete'].include?(f.f_type) } | ||
type_translatable_attributes = fields.collect { |f| f.label_for_params.to_sym } | ||
|
||
klass::Translation.update_keys_if_necessary_with(type_translatable_attributes) | ||
|
||
update_translation_for_methods_if_necessary_with(type_translatable_attributes) | ||
|
||
klass::Translation.translatable_attributes + type_translatable_attributes | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
lib/kete_translatable_content/extensions/translation_from_version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'replace_results_with_translations' | ||
require 'redefine_find_with_result_replacement' | ||
# For classes where their ::Version subclass | ||
# is what has mongo_translatable declaration is on | ||
module TranslationFromVersion | ||
unless included_modules.include? TranslationFromVersion | ||
def self.included(base) | ||
base.extend(ReplaceResultsWithTranslations) | ||
base.extend(RedefineFindWithResultReplacement) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
# an instance of the ::Version subclass is what has a translation | ||
# mapped to it for instances of this class | ||
# these methods, if appropriate, pulls the translation for the requested locale | ||
# for the version of the original class instance | ||
module ClassMethods | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters