translation_helper.rb 571 字节
Newer Older
S
Sven Fuchs 已提交
1 2 3 4 5
require 'action_view/helpers/tag_helper'

module ActionView
  module Helpers
    module TranslationHelper
6 7 8
      def translate(key, options = {})
        options[:raise] = true
        I18n.translate(key, options)
S
Sven Fuchs 已提交
9
      rescue I18n::MissingTranslationData => e
10
        keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
S
Sven Fuchs 已提交
11 12
        content_tag('span', keys.join(', '), :class => 'translation_missing')
      end
13
      alias :t :translate
L
Luca Guidi 已提交
14 15

      def localize(*args)
16
        I18n.localize *args
L
Luca Guidi 已提交
17
      end
18
      alias :l :localize
S
Sven Fuchs 已提交
19 20 21
    end
  end
end