Module | GetText::Rails
In: | lib/gettext/rails.rb

GetText::Rails supports Ruby on Rails. You add only 2 lines in your controller, all of the controller/view/models are targeted the textdomain.

See <Ruby-GetText-Package HOWTO for Ruby on Rails (www.yotabanana.com/hiki/ruby-gettext-howto-rails.html>.

### Methods

available_locales bindtextdomain normalized_locale

### Included Modules

GetText

### Constants

Rails | = | ::Rails #:nodoc:

### External Aliases

bindtextdomain | -> | _bindtextdomain

### Public Instance methods

available_locales()

Returns locales which supported by the application. This function returns an reversed array of the locale strings under RAILS_ROOT/locale/*. It is used for restriction such as caching files.

[Source]

        # File lib/gettext/rails.rb, line 67
    67:     def available_locales
    68:       unless (GetText.cached? and @@available_locales)
    69:         @@available_locales = (Dir.glob(File.join(RAILS_ROOT, "locale/[a-z]*")).map{|path| File.basename(path)} << "en").uniq.sort.reverse
    70:       end
    71:       @@available_locales
    72:     end

bindtextdomain(domainname, options = {})

Bind a textdomain(#{path}/#{locale}/LC_MESSAGES/#{domainname}.mo) to your program. Notes the textdomain scope becomes all of the controllers/views/models in your app. This is different from normal GetText.bindtextomain.

Usually, you don‘t call this directly in your rails application. Call init_gettext in ActionController::Base instead.

On the other hand, you need to call this in helpers/plugins.

- domainname: the textdomain name.
- options: options as a Hash.
  - :locale - the locale value such as "ja-JP". When the value is nil, locale is searched the order by this value > "lang" value of QUERY_STRING > params["lang"] > "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
  - :path - the path to the mo-files. Default is "RAIL_ROOT/locale".
  - :charset - the charset. Generally UTF-8 is recommanded. And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).

[Source]

        # File lib/gettext/rails.rb, line 58
    58:     def bindtextdomain(domainname, options = {})
    59:       options[:path] ||= File.join(RAILS_ROOT, "locale")
    60:       _bindtextdomain(domainname, options)
    61:     end

normalized_locale(locale = nil)

Returns a normalized locale which is in available_locales.

- locale: a Locale::Object or nil.

[Source]

        # File lib/gettext/rails.rb, line 76
    76:     def normalized_locale(locale = nil)
    77:       locale ||= GetText.locale
    78:       (available_locales &
    79:         [locale.to_general, locale.to_s, locale.language, Locale.default.language, "en"].uniq)[0]
    80:     end

[Validate]