Created
October 12, 2011 02:55
-
-
Save jmccartie/1280130 to your computer and use it in GitHub Desktop.
Use the Google Translate API to translate Babelwith.me strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Not currently dynamic for a i18n file -- it spits out "en/txt and en/errors" | |
# | |
require 'cgi' | |
require 'yaml' | |
require 'httparty' | |
@strings = YAML.load(File.read("")).to_hash | |
@api_key = '' | |
@language = 'hi' | |
def translate(string) | |
response = HTTParty.get("https://www.googleapis.com/language/translate/v2?key=#{@api_key}&q=#{CGI::escape(string)}&source=en&target=#{@language}") | |
response['data']['translations'].first['translatedText'] | |
end | |
puts "#{@language}:" | |
puts "\s\stxt:" | |
@strings['en']['txt'].each do |key, value| | |
puts "\s\s\s\s#{key}: \"#{translate(value)}\"" | |
end | |
puts "\s\serrors:" | |
@strings['en']['error'].each do |key, value| | |
puts "\s\s\s\s#{key}: \"#{translate(value)}\"" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment