Skip to content

Instantly share code, notes, and snippets.

@edouard
Created April 12, 2012 13:31
Show Gist options
  • Save edouard/2367226 to your computer and use it in GitHub Desktop.
Save edouard/2367226 to your computer and use it in GitHub Desktop.
Example code to create and get strings on WebTranslateIt to translate a Product database
require 'web_translate_it'
# create a KeepAlive HTTPS connection to WebTranslateIt.com
WebTranslateIt::Connection.new('secret_api_key') do
# create translations
translation_en = WebTranslateIt::Translation.new({ :locale => "en", :text => "Hello" })
translation_fr = WebTranslateIt::Translation.new({ :locale => "fr", :text => "Bonjour" })
# create a new segment
string = WebTranslateIt::String.new({ :key => "Greetings", :translations => [translation_en, translation_fr]})
# and save
string.save
puts string.id #=> 1234
# find a segment by ID and update it
string = WebTranslateIt::String.find(1234) #=> WebTranslateIt::String object
string.key = "GoodBye"
string.save
# find segments by key. You can search by many parameters. See http://docs.webtranslateit.com/api/string/#list-string
WebTranslateIt::String.find_all({ :key => "test.*" }).each do |string|
string.key = string.key.gsub("test", "hello")
string.file["id"] = 4567
string.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment