Module: Traduction::I18n::I18nMethods
- Included in:
- Traduction::I18n
- Defined in:
- lib/traduction/i18n.rb
Instance Method Summary collapse
- #diff_locales(options = {}) ⇒ Object
- #diff_yaml(from, to, options = {}, &block) ⇒ Object
- #display_messages(messages, options = {}) ⇒ Object
- #load_default_locale ⇒ Object
- #locale_file(locale) ⇒ Object
Instance Method Details
#diff_locales(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/traduction/i18n.rb', line 6 def diff_locales( = {}) from_prefix, from_content = [:from].to_a to_prefix, to_content = [:to].to_a prefix = [:prefix] from = YAML::load(from_content)[from_prefix] to = YAML::load(to_content)[to_prefix] = diff_yaml(from, to, prefix: prefix) do |k,v| yield k,v end (, empty_message: 'No added keys') end |
#diff_yaml(from, to, options = {}, &block) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/traduction/i18n.rb', line 42 def diff_yaml(from, to, = {}, &block) = [] prefix = [:prefix] || nil from.diff_more(to, :ignore_values => true).flatten_keys(prefix).each do |k,v| << yield(k,v) end end |
#display_messages(messages, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/traduction/i18n.rb', line 21 def (, = {}) = [:empty_message] || 'Nothing found' if .present? .each { |m| puts m } else puts end end |
#load_default_locale ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/traduction/i18n.rb', line 30 def load_default_locale i18n_default_locale = ::I18n.default_locale { :key => i18n_default_locale.to_s, :file => locale_file(i18n_default_locale) } end |
#locale_file(locale) ⇒ Object
38 39 40 |
# File 'lib/traduction/i18n.rb', line 38 def locale_file(locale) File.join('config', 'locales', "#{locale}.yml") end |