Created
June 5, 2009 12:00
-
-
Save romul/124258 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MultilingualModule | |
| def self.define_ml_methods_for(attrs) | |
| languages = APP_CONFIG[:languages].split(/\|/) | |
| attrs.each do |method| | |
| define_method('ml_' + method) do |*args| | |
| yml = YAML.load(send("#{method}_ml").to_s) | |
| hash = yml ? yml : {} | |
| languages.each do |lang| | |
| hash[lang.to_sym] = "" unless hash[lang.to_sym] | |
| end | |
| hash | |
| end | |
| define_method(method) do |*args| | |
| ml_values = send "ml_#{method}" | |
| ml_values[I18n.locale.to_sym] | |
| end | |
| end | |
| attrs.each do |method| | |
| languages.each do |lang| | |
| define_method("#{method}_#{lang}") do |*args| | |
| ml_values = send "ml_#{method}" | |
| ml_values[lang.to_sym] | |
| end | |
| define_method("#{method}_#{lang}=") do |value, *args| | |
| ml_values = send "ml_#{method}" | |
| ml_values[lang.to_sym] = value | |
| send "#{method}_ml=", ml_values.to_yaml | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment