File: i18n.rb

package info (click to toggle)
libgettext-activerecord-ruby 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 608 kB
  • ctags: 285
  • sloc: ruby: 2,895; makefile: 13
file content (27 lines) | stat: -rw-r--r-- 982 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
=begin
  lib/gettext_activerecord/i18n.rb - GetText for ActiveRecord's I18n.

  Copyright (C) 2009 Masao Mutoh
 
  You may redistribute it and/or modify it under the same
  license terms as Ruby or LGPL.
=end
 
module I18n  #:nodoc:
  class << self 
    include GetText
    # gettext_activerecord doesn't define backend. So it can be used with another backend.
    def translate_with_gettext_activerecord(key, options = {}) #:nodoc:
      if options[:scope] == [:activerecord, :errors]
        options[:attribute] = key.to_s.split(".")[3]
        options   # This value will be used in ActiveRecord::Base::Errors.localize_error_messages
      else
        translate_without_gettext_activerecord(key, options)
      end
    end
    alias_method_chain :translate, :gettext_activerecord #:nodoc:
    alias_method :t_with_gettext_activerecord, :translate_with_gettext_activerecord #:nodoc:
    alias_method_chain :t, :gettext_activerecord #:nodoc:

  end
end