Class: Tanuki::I18n

Inherits:
Object show all
Includes:
ControllerBehavior
Defined in:
lib/tanuki/i18n.rb

Overview

Tanuki::I18n is a drop-in controller for localizable applications.

Instance Method Summary collapse

Methods included from ControllerBehavior

#[], #_ctx, #active?, #child_class, #current?, dispatch, #each, #ensure_configured!, #forward_link, included, #initialize, #initialize_route, #length, #to_s, #visual_parent

Methods included from ControllerBehavior::ClassMethods

#arg_defs, #escape, extended, #extract_args, #grow_link, #has_arg

Instance Method Details

#configureObject

Adds language routes of root controller class when invoked.



9
10
11
12
13
# File 'lib/tanuki/i18n.rb', line 9

def configure
  raise 'languages are not configured' if @_ctx.languages.size == 0
  root_page = @_ctx.root_page
  @_ctx.languages.each {|lng| has_child root_page, lng }
end

#default_routeObject

Returns default route according to default language.



16
17
18
19
# File 'lib/tanuki/i18n.rb', line 16

def default_route
  raise 'default language is not configured' unless @_ctx.language
  {:route => @_ctx.language, :args => {}, :redirect => @_ctx.i18n_redirect}
end

#default_viewObject

Calls default view of visual child.



22
23
24
# File 'lib/tanuki/i18n.rb', line 22

def default_view
  @_visual_child.default_view
end

#process_child_context(ctx, route) ⇒ Object

Adds child controller language to its context.



27
28
29
30
31
# File 'lib/tanuki/i18n.rb', line 27

def process_child_context(ctx, route)
  ctx = ctx.child
  ctx.language = route.to_sym
  ctx
end