module LostInTranslations

Constants

Config
VERSION

Public Class Methods

assign_translation(*args) click to toggle source
# File lib/lost_in_translations.rb, line 31
def self.assign_translation(*args)
  config.translator.assign_translation(*args)
end
config() click to toggle source
# File lib/lost_in_translations.rb, line 18
def self.config
  @config ||= Config.new(
    'translation_data',
    Translator::Base,
    nil,
    'force_locale'
  )
end
configure() { |config| ... } click to toggle source
# File lib/lost_in_translations.rb, line 74
def self.configure
  yield(config)
end
define_dynamic_translation_method(object, method_name) click to toggle source
# File lib/lost_in_translations.rb, line 46
  def self.define_dynamic_translation_method(object, method_name)
    object.class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{method_name}
        translate(:#{method_name}, I18n.locale)
      end
    RUBY
  end
define_particular_translation_methods(object, attribute) click to toggle source
# File lib/lost_in_translations.rb, line 54
def self.define_particular_translation_methods(object, attribute)
  I18n.available_locales.each do |locale|
    method_name = "#{locale.to_s.downcase.tr('-', '_')}_#{attribute}"

    define_translation_method(object, method_name, attribute, locale)
  end
end
define_translation_method(object, method_name, attribute, locale) click to toggle source
# File lib/lost_in_translations.rb, line 62
  def self.define_translation_method(object, method_name, attribute, locale)
    object.class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{method_name}
        translate(:#{attribute}, :'#{locale}')
      end

      def #{method_name}=(value)
        assign_translation(:#{attribute}, value, :'#{locale}')
      end
    RUBY
  end
define_translation_methods(object, *fields) click to toggle source
# File lib/lost_in_translations.rb, line 39
def self.define_translation_methods(object, *fields)
  fields.each do |field|
    define_dynamic_translation_method(object, field)
    define_particular_translation_methods(object, field)
  end
end
included(base_class) click to toggle source
# File lib/lost_in_translations.rb, line 9
def self.included(base_class)
  if defined?(::ActiveRecord::Base) &&
     base_class.ancestors.include?(::ActiveRecord::Base)
    base_class.send(:include, LostInTranslations::ActiveRecord)
  else
    base_class.send(:include, Ruby)
  end
end
infected_classes() click to toggle source
# File lib/lost_in_translations.rb, line 78
def self.infected_classes
  @infected_classes ||= []
end
reload() click to toggle source
# File lib/lost_in_translations.rb, line 82
def self.reload
  infected_classes.each(&:define_translation_methods)
end
translate(*args) click to toggle source
# File lib/lost_in_translations.rb, line 27
def self.translate(*args)
  config.translator.translate(*args)
end
translation_data(object) click to toggle source
# File lib/lost_in_translations.rb, line 35
def self.translation_data(object)
  config.translator.translation_data(object)
end