Module: Egalite::M17N::Filters
- Included in:
- Controller
- Defined in:
- lib/egalite/m17n.rb
Instance Method Summary collapse
- #_(str, values = []) ⇒ Object
- #after_filter_return_value(response) ⇒ Object
- #before_filter ⇒ Object
- #filter_on_html_load(html, path) ⇒ Object
Instance Method Details
#_(str, values = []) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
26 27 28 29 30 31 |
# 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 ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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) ⇒ Object
22 23 24 25 |
# 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 |