File: transifex.rake

package info (click to toggle)
mikutter 4.1.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,260 kB
  • sloc: ruby: 20,126; sh: 183; makefile: 19
file content (55 lines) | stat: -rw-r--r-- 2,400 bytes parent folder | download | duplicates (2)
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
54
55
# -*- coding: utf-8 -*-
namespace 'transifex' do
  task 'upload' do
    require 'tmpdir'
    require 'httpclient'
    require 'json'
    require 'set'
    require_relative '../core/boot/option'
    require_relative '../core/miquire'
    require_relative 'transifex'

    require 'boot/delayer'
    require '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})
      Environment::PLUGIN_PATH.each do |path|
        Miquire::Plugin.loadpath << path
      end
      Miquire::Plugin.loadpath << 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