File: start.rb

package info (click to toggle)
ruby-ramaze 2012.12.08-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,060 kB
  • ctags: 1,200
  • sloc: ruby: 10,446; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
require 'rubygems'
require 'ramaze'

# require YAML based localization
require 'ramaze/helper/localize'

#
# Old Dispatcher::Action::FILTER style localization.
#
class MainController < Ramaze::Controller
  helper :localize

  def index
    # Enclose the strings that have to be localized with {}
    "<h1>{hello world}</h1>
     <p>{just for fun}</p>
     <a href='/locale/en'>{english}</a><br />
     <a href='/locale/ja'>{japanese}</a><br />
     <a href='/locale/de'>{german}</a><br />
    "
  end

  def locale(name)
    session[:lang] = name
    redirect r(:/)
  end

  # for Localization
  alias :raw_wrap_action_call :wrap_action_call

  def wrap_action_call(action, &block)
    localize(raw_wrap_action_call(action, &block))
  end

  private

  Dictionary = Ramaze::Helper::Localize::Dictionary.new
  Dir.glob('./locale/*.yaml').each do |path|
    Dictionary.load(File.basename(path, '.yaml').intern, :yaml => path)
  end

  def localize_dictionary
    Dictionary
  end
end

Ramaze.start