fetch_locales.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env ruby
  2. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  3. require 'rubygems'
  4. require 'uri'
  5. require 'net/http'
  6. require 'json'
  7. require 'yaml'
  8. version = File.read('VERSION')
  9. version.strip!
  10. url_locales = 'https://i18n.zammad.com/api/v1/locales'
  11. url_translations = 'https://i18n.zammad.com/api/v1/translations/'
  12. file_locales = "config/locales-#{version}.yml"
  13. directory_translations = 'config/translations'
  14. # download locales
  15. uri = URI.parse("#{url_locales}?version=#{version}")
  16. http = Net::HTTP.new(uri.host, uri.port)
  17. http.use_ssl = true
  18. request = Net::HTTP::Get.new(uri)
  19. response = http.request(request)
  20. data = JSON.parse(response.body)
  21. puts "Writing #{file_locales}..."
  22. File.open(file_locales, 'w') do |out|
  23. YAML.dump(data, out)
  24. end
  25. # download translations
  26. if !File.directory?(directory_translations)
  27. Dir.mkdir(directory_translations, 0o755)
  28. end
  29. data.each do |locale|
  30. url = "#{url_translations}#{locale['locale']}?version=#{version}"
  31. uri = URI.parse(url)
  32. http = Net::HTTP.new(uri.host, uri.port)
  33. http.use_ssl = true
  34. request = Net::HTTP::Get.new(uri)
  35. response = http.request(request)
  36. data = JSON.parse(response.body)
  37. file = "#{directory_translations}/#{locale['locale']}-#{version}.yml"
  38. puts "Writing #{file}..."
  39. File.open(file, 'w') do |out|
  40. YAML.dump(data, out)
  41. end
  42. end
  43. puts 'done'