Debian Codegraph @

tasks/transifex.rake

raw
1 # -*- coding: utf-8 -*-
2 namespace 'transifex' do
3 task 'upload' do
4 require 'tmpdir'
5 require 'httpclient'
6 require 'json'
7 require 'set'
8 require_relative '../core/boot/option'
9 require_relative '../core/miquire'
10 require_relative 'transifex'
11
12 require 'boot/delayer'
13 require 'miquire_plugin'
14
15 project_name = ENV.fetch('TRANSIFEX_PROJECT_NAME')
16
17 Dir.mktmpdir('mikutter-transifex-upload') do |confroot|
18 Mopt.parse(["--confroot=#{confroot}"], exec_command: false)
19 project = Transifex.project_detail(project_name)
20 existing_resource_slugs = Set.new(project[:resources].map{|res|res[:slug].to_sym})
21 Environment::PLUGIN_PATH.each do |path|
22 Miquire::Plugin.loadpath << path
23 end
24 Miquire::Plugin.loadpath << File.join(__dir__, "..", "plugin")
25 Miquire::Plugin.each_spec do |spec|
26 pot_path = File.join(spec[:path], 'po', "#{spec[:slug]}.pot")
27 next unless FileTest.exist?(pot_path)
28 slug = spec[:slug] == :settings ? 'settings-1' : spec[:slug]
29 if existing_resource_slugs.include? slug.to_sym
30 puts "Update #{slug}"
31 pp Transifex.resource_update(project_name: project_name,
32 slug: slug,
33 content: File.open(pot_path).map(&:chomp).reject{|l|
34 l == '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"'
35 }.reject{|l|
36 l == '#, fuzzy'
37 }.join("\n")
38 )
39 else
40 puts "Create #{spec[:slug]}"
41 pp Transifex.resource_create(project_name: project_name,
42 slug: slug,
43 name: spec[:slug], # 表示名を日本語にすると外人が核ミサイルを撃ってくるかもしれない
44 content: File.open(pot_path).map(&:chomp).reject{|l|
45 l == '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"'
46 }.reject{|l|
47 l == '#, fuzzy'
48 }.join("\n")
49 )
50 end
51 end
52 end
53 end
54 end
55