Module: I18n
Public Instance Methods
candidates (type = :common)
Get the locale candidates as a Locale::TagList. This is the utility function which calls Locale.candidates with supported_language_tags.
I18n.locale is also overrided by Ruby-Locale and it returns the result of this method with :rfc option.
type :simple, :common(default), :rfc, :cldr.
This is used by Rails application, but it may be better not to use this method in Rails plugins/libraries, because they have their own supported languages.
# File lib/locale_rails/i18n.rb, line 47 47: def candidates(type = :common) 48: default = [I18n.default_locale.to_s] 49: default = ["en-US", "en"] if default[0] == "en-US" 50: Locale.candidates(:type => type, 51: :supported_language_tags => supported_locales, 52: :default_language_tags => default) 53: end
locale= (tag)
Sets the locale.
I18n.locale = "ja-JP"
# File lib/locale_rails/i18n.rb, line 29 29: def locale=(tag) 30: Locale.clear 31: Locale.current = tag 32: Thread.current[:locale] = candidates(:rfc)[0] 33: end
supported_locales ()
Gets the supported locales.
# File lib/locale_rails/i18n.rb, line 17 17: def supported_locales 18: @@supported_locales 19: end
supported_locales= (tags)
Sets the supported locales as an Array.
I18n.supported_locales = ["ja-JP", "ko-KR"]
# File lib/locale_rails/i18n.rb, line 23 23: def supported_locales=(tags) 24: @@supported_locales = tags 25: end