~ubuntu-branches/ubuntu/vivid/ruby-i18n/vivid

« back to all changes in this revision

Viewing changes to lib/i18n.rb

  • Committer: Package Import Robot
  • Author(s): Praveen Arimbrathodiyil
  • Date: 2013-06-03 19:20:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20130603192031-qk11as87x3cotd1n
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
  RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise, :rescue_format]
13
13
  RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
14
14
 
15
 
  class << self
 
15
  extend Module.new {
16
16
    # Gets I18n configuration object.
17
17
    def config
18
18
      Thread.current[:i18n_config] ||= I18n::Config.new
160
160
    end
161
161
    alias :t :translate
162
162
 
 
163
    # Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With
 
164
    # this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
163
165
    def translate!(key, options={})
164
166
      translate(key, options.merge(:raise => true))
165
167
    end
220
222
      options      = args.pop if args.last.is_a?(Hash)
221
223
      key          = args.shift
222
224
      locale       = options && options.delete(:locale) || config.locale
223
 
      raises       = options && options.delete(:raise)
 
225
      handling     = options && (options.delete(:throw) && :throw || options.delete(:raise) && :raise)
224
226
      replacement  = options && options.delete(:replacement)
225
227
      config.backend.transliterate(locale, key, replacement)
226
228
    rescue I18n::ArgumentError => exception
227
 
      raise exception if raises
228
 
      handle_exception(exception, locale, key, options)
 
229
      handle_exception(handling, exception, locale, key, options || {})
229
230
    end
230
231
 
231
232
    # Localizes certain objects, such as dates and numbers to local formatting.
327
328
           "(an instance of which is set to I18n.exception_handler by default)."
328
329
      exception.is_a?(MissingTranslation) ? exception.message : raise(exception)
329
330
    end
330
 
  end
 
331
  }
331
332
end