2011-03-30 20:31:39 -04:00
|
|
|
module Ransack
|
|
|
|
module Nodes
|
|
|
|
class Node
|
|
|
|
attr_reader :context
|
2014-05-01 09:55:39 -04:00
|
|
|
delegate :contextualize, :to => :context
|
2011-03-30 20:31:39 -04:00
|
|
|
class_attribute :i18n_words
|
|
|
|
class_attribute :i18n_aliases
|
|
|
|
self.i18n_words = []
|
|
|
|
self.i18n_aliases = {}
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def i18n_word(*args)
|
|
|
|
self.i18n_words += args.map(&:to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def i18n_alias(opts = {})
|
2013-12-15 13:27:50 -05:00
|
|
|
self.i18n_aliases.merge! Hash[opts.map { |k, v| [k.to_s, v.to_s] }]
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(context)
|
|
|
|
@context = context
|
|
|
|
end
|
|
|
|
|
|
|
|
def translate(key, options = {})
|
|
|
|
key = i18n_aliases[key.to_s] if i18n_aliases.has_key?(key.to_s)
|
|
|
|
if i18n_words.include?(key.to_s)
|
|
|
|
Translate.word(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2013-12-10 09:00:44 -05:00
|
|
|
end
|