genki (owner)

Revisions

gist: 140157 Download_button fork
public
Public Clone URL: git://gist.github.com/140157.git
Embed All Files: show embed
ds-translator.rb #
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
pt = PropertyTranslator.new(Item)
scope = pt.translate("name") # => "Item.name"
 
emt = ErrorMessageTranslator.new(:be_present)
scope = emt.translate(scope) #=> "Item.name should be present"
 
gtt = GetTextTranslator.new(:ja, :JP)
scope = gtt.translate(scope) #=> "名前は必須です"
 
 
 
 
# 1段目
class PropertyTranslator
  @model = "Item"
  def translate(scope = "name")
    lookup(scope) #=> "Item.name"
  end
 
# 2段目
class ErrorMessageTranslator
  @type = :be_present
 
  def translate(scope = "Item.name")
    "%{property} should be present" % scope #=> "Item.name should_be_present"
  end
 
# 3段目
class GetTextTranslator
  @lang = :ja
 
  def translate(scope = "Item.name should_be_present")
    lookup(scope) #=> "%{property}は必須です"
  end