Module: NLize

Defined in:
lib/nlize.rb

Constant Summary collapse

VERSION =
rb_str_new2(NLIZE_VERSION)

Class Method Summary collapse

Class Method Details

.translate(msg) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nlize.rb', line 18

def self.translate(msg)
  r = GetText::_(msg)
  if r == msg
    if /.+Error: (.+)\Z/ =~ msg
      r = GetText::_($1)
    elsif m = /\A(.+unexpected\s)(.+)(,\s+expecting\s)(.+)\Z/.match(msg)
      org = [GetText::_("#{m[1]}%s"), GetText::_("#{m[3]}%s")]
      r = "#{sprintf(org[0], m[2])}#{sprintf(org[1], m[4])}"
    elsif /\A(syntax error, unexpected )(.+)\Z/ =~ msg
      arg = $2
      org = GetText::_("#{$1}%s")
      r = sprintf(org, arg)
    end
  end
  r
end