-
Notifications
You must be signed in to change notification settings - Fork 34
Extras
As a bonus, the WebTranslateIt rubygem contains ruby libraries to connect to the WebTranslateIt API.
The String and Translation APIs are a set of endpoints to view, create, update and destroy segments and translations.
For more information, I invite your to read the String API Documentation and the Translation API Documentation.
The web_translate_it rubygem contains libraries to handle these endpoints easily. For more information, you can browse the code:
- webtranslateit/lib/web_translate_it/string.rb contains everything you need to connect to the String API
- webtranslateit/lib/web_translate_it/translation.rb contains everything you need to connect to the Translation API
The ruby code is self-documented, but here are a few pointers to get you started:
(Install the web_translate_it rubygem file first)
require 'web_translate_it'
# create a KeepAlive HTTPS connection to WebTranslateIt.com
WebTranslateIt::Connection.new('secret_api_key') do
translation_en = WebTranslateIt::Translation.new({ :locale => "en", :text => "Hello" })
translation_fr = WebTranslateIt::Translation.new({ :locale => "fr", :text => "Bonjour" })
string = WebTranslateIt::String.new({ :key => "Greetings", :translations => [translation_en, translation_fr]})
string.save
puts string.id #=> 1234
string = WebTranslateIt::String.find(1234) #=> WebTranslateIt::String object
string.key = "GoodBye"
string.save
WebTranslateIt::String.find_all({ :key => "GoodBye" }).first.delete
end
The TermBase and TermBase Translation APIs are a set of endpoints to view, create, update and destroy terms for a WebTranslateIt TermBase.
For more information, I invite your to read the TermBase API Documentation and the TermBase Translation API Documentation.
The web_translate_it rubygem contains libraries to handle these endpoints easily. For more information, you can browse the code:
- webtranslateit/lib/web_translate_it/term.rb contains everything you need to connect to the String API
- webtranslateit/lib/web_translate_it/term_translation.rb contains everything you need to connect to the Translation API
The ruby code is self-documented, but here are a few pointers to get you started:
(Install the web_translate_it rubygem file first)
require 'web_translate_it'
# create a KeepAlive HTTPS connection to WebTranslateIt.com
WebTranslateIt::Connection.new('secret_api_key') do
translation1 = WebTranslateIt::TermTranslation.new({ :locale => "fr", :text => "Bonjour" })
translation2 = WebTranslateIt::TermTranslation.new({ :locale => "fr", :text => "Salut" })
term = WebTranslateIt::Term.new({ :text => "Hello", :translations => [translation1, translation2] })
term.save
term.text = "Good Bye!"
term.save
term.translation_for("fr") #=> Returns an array of TermTranslation for this term in French
WebTranslateIt::Term.find_all.each do |term|
term.delete
end
end