Created
October 22, 2012 20:00
-
-
Save achempion/3933728 to your computer and use it in GitHub Desktop.
simple db localization
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
module InternalizationHelper | |
# let's imagine that some methods defined in your model like 'title_en' and 'title_ru' for different locales | |
# helper will create 'title' method depending on current I18n.locale | |
# Model.rb | |
# extend InternalizationHelper | |
# define_translations_for 'title', 'description', ... | |
def define_translations_for *methods | |
methods.each do |method_name| | |
define_method(method_name) { | |
self.send "#{method_name}_#{I18n.locale}" | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment