pixab 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1aeab2e736e3207b8fce982411852aa8b83e28791658652e32aae8bb6a77af43
4
- data.tar.gz: 4915bf4fc9c70b6a16b835fc2d72a33610af72e63a3fd6f80ba99db05d230fcf
3
+ metadata.gz: 620f8ce01d8a6d133e14e0bf9fd5b38ae12d59690f8755c311dbad00162e3378
4
+ data.tar.gz: 5949bd4e8a44174d1a6702698bd47aabb5b499940ef8bb7785674dcd3e5d4ddc
5
5
  SHA512:
6
- metadata.gz: b7de12d1d9e4feb61704c9c7f8c4473ee5719d8c7e8d2907a66c985e95b99bee14c79649435d14ac36fa8ca714ad8e37935dc711ef18d7c52c6b01c5f52b4d8c
7
- data.tar.gz: b2addac7aa9cbbb46893cd3aeaa1d0edd7319b2420e3473fe2395044263179c95967a00779d2103a789415d8b825f00f1c907d9f03c7f3ffc489270d48166170
6
+ metadata.gz: 3f64497e1c775ea0f8fe164f66d15b463c967e6ddcb568e8447541d366828e7e84c50e99ec22836afa26968cdf6172cb31f699ba53eea8e24a5623ebcc5ea0b6
7
+ data.tar.gz: fc3c3013e9e97e39fa622fcfff40125df59c2aa5735455aa50d6fe6df82ea1bbcd92d5929975f08b967238159322828b5a17e841320f9422e82896a42359a61f
data/exe/pixab CHANGED
@@ -19,7 +19,7 @@ when 'sync'
19
19
  commands = ["-m"]
20
20
  if !synchronizer.updated_repo_names.empty?
21
21
  default_commit_msg = "[Feature]Update"
22
- updated_repo_names.each do |repo_name|
22
+ synchronizer.updated_repo_names.each do |repo_name|
23
23
  default_commit_msg += " #{repo_name}"
24
24
  end
25
25
  commands.push("--commit-m")
@@ -105,6 +105,7 @@ module Pixab
105
105
  repo_name = repo["name"]
106
106
  repo_target_branch = repo["target_branch"]
107
107
  FileUtils.cd("#{repo_manager.root_path}/#{repo_name}")
108
+ `git fetch origin #{repo_target_branch}`
108
109
  commit_id = `git log origin/#{repo_target_branch} -n 1 --pretty=format:"%H"`
109
110
  if !commit_id.nil?
110
111
  repo_commite_id[repo_name] = commit_id
data/lib/Localization.rb CHANGED
@@ -27,21 +27,18 @@ module Pixab
27
27
  add_project(Project_AirBrush)
28
28
  when '--project-abv'
29
29
  add_project(Project_AirBrush_Video)
30
- when '--tags'
31
- @tags = commands[index + 1]
32
- when '--platform'
33
- @platform = commands[index + 1]
34
- when '--mode'
35
- @mode = commands[index + 1]
36
30
  when '--ab-android'
37
31
  @projects = "#{Project_AirBrush},#{Project_AirBrush_Video}"
38
32
  @platform = 'android'
33
+ @tags = 'android'
39
34
  when '--ab-iOS'
40
35
  @projects = "#{Project_AirBrush}"
41
36
  @mode = 'add'
37
+ @tags = 'iOS'
42
38
  when '--abv-iOS'
43
39
  @projects = "#{Project_AirBrush_Video}"
44
40
  @mode = 'add'
41
+ @tags = 'iOS'
45
42
  end
46
43
  end
47
44
 
@@ -50,6 +47,12 @@ module Pixab
50
47
  case command
51
48
  when '--projects'
52
49
  @projects = commands[index + 1]
50
+ when '--tags'
51
+ @tags = commands[index + 1]
52
+ when '--platform'
53
+ @platform = commands[index + 1]
54
+ when '--mode'
55
+ @mode = commands[index + 1]
53
56
  end
54
57
  end
55
58
 
@@ -70,14 +73,23 @@ module Pixab
70
73
  localized_info_category = {}
71
74
  project_array = projects.split(',')
72
75
  project_array.each do |project|
73
- command = "\"https://api.phrase.com/v2/projects/#{project}/translations"
74
- if !tags.nil?
75
- command += "?q=tags:#{tags}"
76
- end
77
- command += "\" -u #{ACCESS_TOKEN}:"
78
- localized_string = `curl #{command}`
79
- localized_info_category.merge!(assemble_data(localized_string)) do |key, oldval, newval|
80
- oldval + newval
76
+ page_number = 1
77
+ while true
78
+ link = "\"https://api.phrase.com/v2/projects/#{project}/translations?page=#{page_number}&per_page=100&sort=created_at"
79
+ if !tags.nil?
80
+ link += "&q=tags:#{tags}"
81
+ end
82
+ link += "\""
83
+ access_token = "-u #{ACCESS_TOKEN}:"
84
+ localized_string = `curl #{link} #{access_token}`
85
+ per_localized_info_category = assemble_data(localized_string)
86
+ if per_localized_info_category.empty?
87
+ break
88
+ end
89
+ localized_info_category.merge!(per_localized_info_category) do |key, oldval, newval|
90
+ oldval + newval
91
+ end
92
+ page_number += 1
81
93
  end
82
94
  end
83
95
  return localized_info_category
@@ -85,8 +97,12 @@ module Pixab
85
97
 
86
98
  # 重新组装本地化数据
87
99
  def assemble_data(string)
88
- objects = JSON.parse(string)
100
+ if string.nil? || string.empty?
101
+ return {}
102
+ end
103
+
89
104
  localized_info_category = {}
105
+ objects = JSON.parse(string)
90
106
  objects.each do |object|
91
107
  locale_name = object["locale"]["name"]
92
108
  localized_infos = localized_info_category[locale_name]
@@ -16,15 +16,16 @@ module Pixab
16
16
  end
17
17
 
18
18
  def resolve_commands(commands)
19
- if !commands.nil?
20
- commands.each_index do |index|
21
- command = commands[index]
22
- case command
23
- when "--mode"
24
- mode = commands[index + 1]
25
- if mode == 'add'
26
- @file_mode = 'a+'
27
- end
19
+ if commands.nil?
20
+ return
21
+ end
22
+ commands.each_index do |index|
23
+ command = commands[index]
24
+ case command
25
+ when "--mode"
26
+ mode = commands[index + 1]
27
+ if mode == 'add'
28
+ @file_mode = 'a+'
28
29
  end
29
30
  end
30
31
  end
@@ -48,18 +49,29 @@ module Pixab
48
49
  def run(localized_info_category, commands)
49
50
  super(localized_info_category, commands)
50
51
 
52
+ begin_prompt = "\n// Created from phrase api <<<<<<<<<< begin\n"
53
+ end_prompt = "\n// Created from phrase api <<<<<<<<<< end\n"
54
+
51
55
  localized_info_category.each do |locale, localized_infos|
52
56
  content_dir_path = dir_name(locale)
53
57
  if !Dir.exists?(content_dir_path)
54
58
  FileUtils.mkdir_p content_dir_path
55
59
  end
56
60
  content_file_path = "#{content_dir_path}/#{File_name}"
57
- File.open(content_file_path, @file_mode) do |aFile|
58
- aFile.syswrite("\n// Created from phrase api <<<<<<<<<< begin\n")
61
+ if @file_mode == 'a+' and File::exists?(content_file_path)
62
+ # 移除以前脚本添加的本地化文案
63
+ content = File.read(content_file_path)
64
+ content = content.sub(/#{begin_prompt}.*#{end_prompt}/m, '')
65
+ File.open(content_file_path, 'w+') do |file|
66
+ file.syswrite(content)
67
+ end
68
+ end
69
+ File.open(content_file_path, @file_mode) do |file|
70
+ file.syswrite(begin_prompt)
59
71
  localized_infos.each do |localized_info|
60
- aFile.syswrite("\n\"#{localized_info['key']}\" = \"#{localized_info['value']}\";\n")
72
+ file.syswrite("\n\"#{localized_info['key']}\" = \"#{localized_info['value']}\";\n")
61
73
  end
62
- aFile.syswrite("\n// Created from phrase api <<<<<<<<<< end\n")
74
+ file.syswrite(end_prompt)
63
75
  end
64
76
  end
65
77
  end
@@ -92,13 +104,13 @@ module Pixab
92
104
  FileUtils.mkdir_p content_dir_path
93
105
  end
94
106
  content_file_path = "#{content_dir_path}/#{File_name}"
95
- File.open(content_file_path, @file_mode) do |aFile|
96
- aFile.syswrite("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
97
- aFile.syswrite("<resources>\n")
107
+ File.open(content_file_path, @file_mode) do |file|
108
+ file.syswrite("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
109
+ file.syswrite("<resources>\n")
98
110
  localized_infos.each do |localized_info|
99
- aFile.syswrite(" <string name=\"#{localized_info['key']}\">#{localized_info['value']}</string>\n")
111
+ file.syswrite(" <string name=\"#{localized_info['key']}\">#{localized_info['value']}</string>\n")
100
112
  end
101
- aFile.syswrite("</resources>\n")
113
+ file.syswrite("</resources>\n")
102
114
  end
103
115
  end
104
116
  end
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-05 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2