Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple db localization
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