I18nScopes

Installation

Add this line to your application's Gemfile:

gem 'i18n_scopes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install i18n_scopes

Usage

Configuration

I18nScopes.configure do |config|
  config.plural_classes = false
  config.strip_controller_suffix = true
  config.attach_to ActionController::Base
end

In your class (for example Controller)

class Local::ExampleController < ActionController::Base
  i18n_default_scope :class_name, :translation, :action_name, :strip_controller_suffix => true, :plural_classes => false
  i18n_scope :flash, :class_name, :action_name, :flashes

  def index
    @post = Post.new
    self.examples
  end

  protected
  def examples
    # the t_scoped method will inherit the path from the i18n_scope method
    t_scoped :name # => [:example, :translation, :index, :name]

    # the path can be overwritten with an option
    t_scoped :name, :path => :elsewhere # => [:elsewhere, :name]

    # the path can be extended through the :path_extension options, it'll be attached to the end of path
    t_scoped :name, :path_extension => :flash, # => [:example, :translation, :index, :flash, :name]

    # it's also possible to use local methods as path, in this example :modules_with_extension will be called, note that 
    t_scoped :name, :path_extension => :modules_with_extension # => [:example, :translation, :index, :local_modules, :name]

    # in this example, the post object will be given as argument, @post will respond to :post_scope and returns :normal
    t_scoped :name, :path_extension => :post_scope, :respondable => @post # => [:example, :translation, :index, :normal, :name]

    # this will call the named scope +t_flash+ and extend it with a path_extension
    t_flash :name, :path_extension => :success # => [:example, :index, :flashes, :sucess, :name]
  end

  def modules_with_extension(modules)
    "#{modules}_modules"
  end

end