module Egalite::M17N::Filters
Public Instance Methods
_(str, values = [])
click to toggle source
# File lib/egalite/m17n.rb, line 32 def _(str, values = []) if @lang str = @lang.translate_string(req.controller_class, req.action_method, str, values) else str = str.dup values.each_with_index { |s2,i| str.gsub!(/\{#{i}\}/, s2) } end str end
after_filter_return_value(response)
click to toggle source
Calls superclass method
# File lib/egalite/m17n.rb, line 26 def after_filter_return_value(response) if @lang response = @lang.translate_msg(req.controller_class, req.action_method, response) end super(response) end
before_filter()
click to toggle source
Calls superclass method
# File lib/egalite/m17n.rb, line 7 def before_filter # check hostname first to determine which language to serve. first = req.host.split(/\./).first @lang = Translation.lang(first) if not @lang and req.accept_language and Translation.allow_content_negotiation # fallback to Accept-Language HTTP header for language to serve. langs = req.accept_language.split(/,/) @lang = langs.map { |s| Translation.lang(s.split(/;/).first) }.compact.first end @lang ||= Translation.lang(Translation.user_default_lang) @lang ||= Translation.lang('ja') req.language = @lang.langcode super end
filter_on_html_load(html,path)
click to toggle source
Calls superclass method
# File lib/egalite/m17n.rb, line 22 def filter_on_html_load(html,path) html = @lang.translate_html(path, html) if @lang super(html,path) end