stylus/tools/pull_locales.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2015-03-26 18:28:50 +00:00
# Install transifex-ruby - https://rubygems.org/gems/transifex-ruby
#
# Create a file called pull_locales_login.rb.
2015-03-26 18:28:50 +00:00
# Contents should be:
#
# Transifex.configure do |config|
# config.username = 'transifex.username'
# config.password = 'transifex.password'
# end
#
# Update require_relative to point to this file.
2015-03-26 18:28:50 +00:00
require 'transifex'
require 'fileutils'
require_relative '../stylish-chrome-bin/pull_locales_login'
2015-03-26 18:28:50 +00:00
project_slug = 'stylish-for-chrome'
transifex = Transifex::Client.new
project = transifex.project(project_slug)
project.languages.each do |language|
code = language.language_code
puts "Getting locale #{code}"
2017-07-14 00:50:24 +00:00
dir_name = "../_locales/#{code}"
2015-03-26 18:28:50 +00:00
Dir.mkdir(dir_name) if !Dir.exist?(dir_name)
has_content = false
project.resources.each do |resource|
c = resource.translation(code).content
file_name = "#{dir_name}/#{resource.name}"
begin
completed = resource.stats(code).completed
rescue Transifex::NotFound
puts "#{code} not found."
next
end
2015-03-26 18:28:50 +00:00
has_content ||= completed != "0%"
puts "Writing resource #{file_name}, #{completed} complete."
File.open(file_name, 'w') { |file| file.write(c) }
end
if !has_content
puts "Locale #{code} has no content, deleting."
FileUtils.rm_rf(dir_name)
end
end