Skip to content

Instantly share code, notes, and snippets.

@jfsso
Last active June 21, 2016 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsso/c82102dded15a1cefc53994a96dfed6d to your computer and use it in GitHub Desktop.
Save jfsso/c82102dded15a1cefc53994a96dfed6d to your computer and use it in GitHub Desktop.
Script that downloads translated Android strings in languages marked as "ready" from OneSky
require 'onesky'
require 'fileutils'
# Settings
project_id = XXXXX
# Create client
client = Onesky::Client.new('<api_key>', '<api_secret>')
# show project details
project = client.project(project_id)
resp = JSON.parse(project.show)
p resp['data']
# get language list
resp = JSON.parse(project.list_language)
#p resp['data']
# download translations that are ready
resp['data'].each do |x|
if (x['is_ready_to_publish'])
locale = x['custom_locale'] || x['locale']
print "Downloading ", x['english_name'], " (", x['code'], ") with translation progress of ", x['translation_progress'], " to values-", locale, "... "
resp = project.export_translation(source_file_name: 'strings.xml', locale: x['code'])
path = 'app/src/main/res/values-' + locale
FileUtils.mkdir_p(path) unless File.exists?(path)
File.open(path + '/strings.xml', 'w') { |file| file.write(resp)}
puts "Done!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment