1 require 'globalize/backend/pluralizing'
 
   2 require 'globalize/locale/fallbacks'
 
   3 require 'globalize/translation'
 
   7     class Static < Pluralizing
 
   9         add(*args) unless args.empty?
 
  12       def translate(locale, key, options = {})
 
  13         result, default, fallback = nil, options.delete(:default), nil
 
  14         I18n.fallbacks[locale].each do |fallback|
 
  16             result = super(fallback, key, options) and break
 
  17           rescue I18n::MissingTranslationData
 
  20         result ||= default locale, default, options
 
  22         attrs = {:requested_locale => locale, :locale => fallback, :key => key, :options => options}
 
  23         translation(result, attrs) || raise(I18n::MissingTranslationData.new(locale, key, options))
 
  28         alias :orig_interpolate :interpolate unless method_defined? :orig_interpolate
 
  29         def interpolate(locale, string, values = {})
 
  30           result = orig_interpolate(locale, string, values)
 
  31           translation = translation(string)
 
  32           translation.nil? ? result : translation.replace(result)
 
  35         def translation(result, meta = nil)
 
  42             result = Translation::Static.new(result) unless result.is_a? Translation::Static
 
  46             Hash[*result.map do |key, value|
 
  47               [key, translation(value, meta)]
 
  51               translation(value, meta)
 
  55             # raise "unexpected translation type: #{result.inspect}"