File: transifex.rake

package info (click to toggle)
mikutter 3.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,256 kB
  • ctags: 2,165
  • sloc: ruby: 19,079; sh: 205; makefile: 20
file content (53 lines) | stat: -rw-r--r-- 2,357 bytes parent folder | download | duplicates (3)
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
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
namespace 'transifex' do
  task 'upload' do
    require 'tmpdir'
    require 'httpclient'
    require 'json'
    require 'pp'
    require 'set'
    require_relative '../core/boot/option'
    require_relative '../core/miquire'
    require_relative 'transifex'

    miquire :boot, 'delayer'
    miquire :core, "miquire_plugin"

    project_name = ENV['TRANSIFEX_PROJECT_NAME']

    Dir.mktmpdir('mikutter-transifex-upload') do |confroot|
      Mopt.parse(["--confroot=#{confroot}"], exec_command: false)
      project = Transifex.project_detail(project_name)
      existing_resource_slugs = Set.new(project[:resources].map{|res|res[:slug].to_sym})
      Miquire::Plugin.loadpath << Environment::PLUGIN_PATH << File.join(__dir__, "..", "plugin")
      Miquire::Plugin.each_spec do |spec|
        pot_path = File.join(spec[:path], 'po', "#{spec[:slug]}.pot")
        next unless FileTest.exist?(pot_path)
        slug = spec[:slug] == :settings ? 'settings-1' : spec[:slug]
        if existing_resource_slugs.include? slug.to_sym
          puts "Update #{slug}"
          pp Transifex.resource_update(project_name: project_name,
                                       slug: slug,
                                       content: File.open(pot_path).map(&:chomp).reject{|l|
                                         l == '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"'
                                       }.reject{|l|
                                         l == '#, fuzzy'
                                       }.join("\n")
                                      )
        else
          puts "Create #{spec[:slug]}"
          pp Transifex.resource_create(project_name: project_name,
                                       slug: slug,
                                       name: spec[:slug], # 表示名を日本語にすると外人が核ミサイルを撃ってくるかもしれない
                                       content: File.open(pot_path).map(&:chomp).reject{|l|
                                         l == '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"'
                                       }.reject{|l|
                                         l == '#, fuzzy'
                                       }.join("\n")
                                      )
        end
      end
    end
  end
end