Module: I18n

Defined in:
lib/locale_rails/i18n.rb

Overview

locale_rails/lib/i18n.rb - Ruby/Locale for “Ruby on Rails”

Copyright (C) 2008,2009  Masao Mutoh

You may redistribute it and/or modify it under the same
license terms as Ruby or LGPL.

Class Method Summary collapse

Class Method Details

.default_locale=(tag) ⇒ Object

Sets the default locale.

I18n.default_locale = "ja"


42
43
44
45
46
# File 'lib/locale_rails/i18n.rb', line 42

def default_locale=(tag)
  tag = Locale::Tag::Rfc.parse(tag.to_s) if tag.kind_of? Symbol
  Locale.default = tag
  @@default_locale = tag
end

.locale=(tag) ⇒ Object

Sets the locale.

I18n.locale = "ja-JP"


33
34
35
36
37
38
# File 'lib/locale_rails/i18n.rb', line 33

def locale=(tag)
  Locale.clear
  tag = Locale::Tag::Rfc.parse(tag.to_s) if tag.kind_of? Symbol
  Locale.current = tag
  Thread.current[:locale] = Locale.candidates(:type => :rfc)[0]
end

.locale_rails_exception_handler(exception, locale, key, options) ⇒ Object

MissingTranslationData is overrided to fallback messages in candidate locales.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/locale_rails/i18n.rb', line 51

def locale_rails_exception_handler(exception, locale, key, options) #:nodoc:
  ret = nil
  Locale.candidates(:type => :rfc).each do |loc|
    begin
      ret = backend.translate(loc, key, options)
      break
    rescue I18n::MissingTranslationData 
      ret = I18n.default_exception_handler(exception, locale, key, options)
    end
  end
  ret
end

.set_supported_locales(*tags) ⇒ Object

Sets the supported locales.

I18n.set_supported_locales("ja-JP", "ko-KR", ...)


21
22
23
# File 'lib/locale_rails/i18n.rb', line 21

def set_supported_locales(*tags)
  Locale.set_app_language_tags(*tags)
end

.supported_localesObject

Gets the supported locales.



15
16
17
# File 'lib/locale_rails/i18n.rb', line 15

def supported_locales 
  Locale.app_language_tags
end

.supported_locales=(tags) ⇒ Object

Sets the supported locales as an Array.

I18n.supported_locales = ["ja-JP", "ko-KR", ...]


27
28
29
# File 'lib/locale_rails/i18n.rb', line 27

def supported_locales=(tags)
  Locale.set_app_language_tags(*tags)
end