5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/idiom/microsoft_translator.rb', line 5
def t(value, code)
value = URI.encode(value)
appId = CONFIG["appId"]
url = "http://api.microsofttranslator.com/V2/Http.svc/Translate?to=#{code}&text=#{value}&appId=#{appId}"
result = Net::HTTP.get(URI.parse(url))
if result =~ /<string xmlns=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/\">(.*)<\/string>/
output = $1
end
if result =~ /Message: (.*)/
$stdout.puts(result)
end
if result =~ /AppId is over the quota/
raise "AppId is over the quota"
end
output.to_s
end
|