A ruby wrapper for youdao fanyi api.
Add this line to your application's Gemfile:
gem 'youdao_fanyi_api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install youdao_fanyi_api
First you need to configure the API
YoudaoFanyiAPI.configure do |config|
config.key = YOUR_KEY
config.keyfrom = YOUR_KEYFROM
end
Then, you can use translate
method.
puts YoudaoFanyiAPI.translate('hello world')['translation'] # 你好,世界
You could use a client
client = YoudaoFanyiAPI::Client.new(key: YOUR_KEY, keyfrom: YOUR_KEYFROM)
puts client.t('ruby')['basic']['explains']
# n. 红宝石;红宝石色
# adj. 红宝石色的
# ...
You can also use t
method, which is an alias of translate
. The translate
method returns a hash, you can find more details from here.
translate
also has a second optional argument,
using as client.t('hello', only: true)
, which will only show dictionay result.
Feel free to file an issue or send a pr.