Class ActionController::Base
In: lib/gettext_rails/action_controller.rb
Parent: Object

Methods

Included Modules

GetText

Public Class methods

Append a block which is called after initializing gettext on the each WWW request.

The GetText.locale is set the locale which bound to the textdomains when gettext is initialized.

(e.g.1)

  class ApplicationController < ActionController::Base
    after_init_gettext {|controller|
      L10nClass.new(GetText.locale)
    }
    init_gettext "foo"
    # ...
  end

(e.g.2)

  class ApplicationController < ActionController::Base
    def sample_foo
      L10nClass.new(GetText.locale)
    end
    after_init_gettext :sample_foo
    init_gettext "foo"
    # ...
  end

Append a block which is called before initializing gettext on the each WWW request.

(e.g.1)

  class ApplicationController < ActionController::Base
    before_init_gettext{|controller|
      p "before_init_gettext is called."
    }
    init_gettext "myapp"
    # ...
  end

(e.g.2)

  class ApplicationController < ActionController::Base
    def sample_foo
      p "sample_foo is called."
    end
    before_init_gettext :sample_foo
    init_gettext "myapp"
    # ...
  end

Bind a ‘textdomain’ to all of the controllers/views/models. Call this instead of GetText.bindtextdomain.

  • textdomain: the textdomain
  • options: options as a Hash.
    • :charset - the output charset. Default is "UTF-8"
    • :locale_path - the path to locale directory. Default is {RAILS_ROOT}/locale or {plugin root directory}/locale.

locale is searched the order by params["lang"] > "lang" value of QUERY_STRING > "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en). And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8). Refer Ruby-Locale for more details.

If you want to separate the textdomain each controllers, you need to call this function in the each controllers.

app/controller/blog_controller.rb:

 class BlogController < ApplicationController
   init_gettext "blog"
     :
   end

[Validate]