Skip to content

Instantly share code, notes, and snippets.

@achempion
Created October 22, 2012 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achempion/3933728 to your computer and use it in GitHub Desktop.
Save achempion/3933728 to your computer and use it in GitHub Desktop.
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