Skip to content
Edouard edited this page Jan 20, 2022 · 8 revisions

As a bonus, the WebTranslateIt rubygem contains ruby libraries to connect to the WebTranslateIt API.

String and Translation APIs

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:

Usage

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

TermBase and TermBase Translation APIs

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:

Usage

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