-
Notifications
You must be signed in to change notification settings - Fork 86
/
pull_locales.rb
46 lines (42 loc) · 1.39 KB
/
pull_locales.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Install transifex-ruby - https://rubygems.org/gems/transifex-ruby
#
# Create a file in the same directory called pull_locales_login.rb.
# Contents should be:
#
# Transifex.configure do |config|
# config.username = 'transifex.username'
# config.password = 'transifex.password'
# end
require 'transifex'
require 'fileutils'
require_relative 'pull_locales_login'
project_slug = 'stylish'
transifex = Transifex::Client.new
project = transifex.project(project_slug)
project.languages.each do |language|
code = language.language_code
code_with_hyphens = code.sub('_', '-')
puts "Getting locale #{code_with_hyphens}"
dir_name = "locale/#{code_with_hyphens}"
Dir.mkdir(dir_name) if !Dir.exist?(dir_name)
has_content = false
project.resources.each do |resource|
c = resource.translation(code).content.gsub('\\\\', '\\').gsub('&', '&')
# transifex likes underscores in locale names, we like hyphens
c.sub!(code, code_with_hyphens) if code != code_with_hyphens
file_name = "#{dir_name}/#{resource.name}"
begin
completed = resource.stats(code).completed
rescue Transifex::NotFound
puts "Not found, skipping."
next
end
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_with_hyphens} has no content, deleting."
FileUtils.rm_rf(dir_name)
end
end