pixab 0.1.0 → 1.0.0
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 +4 -4
- data/exe/pixab +3 -0
- data/lib/Localization.rb +99 -0
- data/lib/LocalizationPlatform.rb +124 -0
- data/lib/pixab/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee48a05e69b1e9e59214e38380ba36ee81aa64311fb1d181e7bde2252c439d4b
|
4
|
+
data.tar.gz: d3590c352c4a5395cf2dd9b6e52cd13f074ee8882bebf15e62912b12eac070f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae1d44e653a004cebf75973fc4b357ab240b301230b43aaed35490db8758d3a983903dae046d54c7d098437d50a9bc589960075912907971d7ad62ceea3d1bfb
|
7
|
+
data.tar.gz: 8af96cc79c17e29b5e5761d8a6c4a371cc08706718e4d21acdd98cfa6596705f3c12ee7942a7380b856b9257e4227320b58cc9ebc1d8c3cc3c35b189467513f8
|
data/exe/pixab
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
require_relative '../lib/MergeRequest.rb'
|
6
6
|
require_relative '../lib/ComponentSynchronizer.rb'
|
7
|
+
require_relative '../lib/Localization.rb'
|
7
8
|
|
8
9
|
case ARGV[0]
|
9
10
|
when 'merge'
|
@@ -25,6 +26,8 @@ when 'sync'
|
|
25
26
|
end
|
26
27
|
Pixab::MergeRequest.new(repo_manager, commands).run
|
27
28
|
end
|
29
|
+
when 'localize'
|
30
|
+
Pixab::Localization.new.run(ARGV[1..-1])
|
28
31
|
else
|
29
32
|
puts "Invalid command".red
|
30
33
|
end
|
data/lib/Localization.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require 'colored2'
|
5
|
+
require 'json'
|
6
|
+
require_relative 'LocalizationPlatform.rb'
|
7
|
+
|
8
|
+
module Pixab
|
9
|
+
|
10
|
+
class Localization
|
11
|
+
|
12
|
+
ACCESS_TOKEN = '4f5379d0d26b9a2ef167b3fc84fb47f1fe2b4e87b1f95d8f5fc15269132051ef'
|
13
|
+
|
14
|
+
attr_accessor :projects, :tags, :platform, :mode
|
15
|
+
|
16
|
+
def initialize()
|
17
|
+
@platform = 'iOS'
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(commands = nil)
|
21
|
+
commands.each_index do |index|
|
22
|
+
command = commands[index]
|
23
|
+
case command
|
24
|
+
when "--projects"
|
25
|
+
@projects = commands[index + 1]
|
26
|
+
when "--tags"
|
27
|
+
@tags = commands[index + 1]
|
28
|
+
when "--platform"
|
29
|
+
@platform = commands[index + 1]
|
30
|
+
when "--mode"
|
31
|
+
@mode = commands[index + 1]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "\n》》》》》正在下载本地化文案 》》》》》》》》》》\n".green
|
36
|
+
localized_info_category = retrieveLocalizationString
|
37
|
+
|
38
|
+
puts "\n》》》》》正在替换本地化文案 》》》》》》》》》》\n".green
|
39
|
+
replace_local_files(localized_info_category)
|
40
|
+
end
|
41
|
+
|
42
|
+
# 从Phrase平台检索获取本地化文案
|
43
|
+
def retrieveLocalizationString
|
44
|
+
if projects.nil?
|
45
|
+
puts "Error: project id cannot be nil".red
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
localized_info_category = {}
|
50
|
+
project_array = projects.split(',')
|
51
|
+
project_array.each do |project|
|
52
|
+
command = "\"https://api.phrase.com/v2/projects/#{project}/translations"
|
53
|
+
if !tags.nil?
|
54
|
+
command += "?q=tags:#{tags}"
|
55
|
+
end
|
56
|
+
command += "\" -u #{ACCESS_TOKEN}:"
|
57
|
+
localized_string = `curl #{command}`
|
58
|
+
localized_info_category.merge!(assemble_data(localized_string)) do |key, oldval, newval|
|
59
|
+
oldval + newval
|
60
|
+
end
|
61
|
+
end
|
62
|
+
return localized_info_category
|
63
|
+
end
|
64
|
+
|
65
|
+
# 重新组装本地化数据
|
66
|
+
def assemble_data(string)
|
67
|
+
objects = JSON.parse(string)
|
68
|
+
localized_info_category = {}
|
69
|
+
objects.each do |object|
|
70
|
+
locale_name = object["locale"]["name"]
|
71
|
+
localized_infos = localized_info_category[locale_name]
|
72
|
+
if localized_infos.nil?
|
73
|
+
localized_infos = []
|
74
|
+
localized_info_category[locale_name] = localized_infos
|
75
|
+
end
|
76
|
+
localized_infos.push({'key' => "#{object['key']['name']}", 'value' => "#{object['content']}"})
|
77
|
+
end
|
78
|
+
return localized_info_category
|
79
|
+
end
|
80
|
+
|
81
|
+
# 替换本地文件
|
82
|
+
def replace_local_files(localized_info_category)
|
83
|
+
platform_commands = nil
|
84
|
+
if !mode.nil?
|
85
|
+
platform_commands = ['--mode', mode]
|
86
|
+
end
|
87
|
+
if platform == 'android'
|
88
|
+
LocalizationAndroid.new.run(localized_info_category, platform_commands)
|
89
|
+
else
|
90
|
+
LocalizationiOS.new.run(localized_info_category, platform_commands)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
Pixab::Localization.new.run(ARGV)
|
99
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
module Pixab
|
7
|
+
|
8
|
+
class LocalizationPlatform
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@file_mode = 'w+'
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(localized_info_category, commands)
|
15
|
+
resolve_commands(commands)
|
16
|
+
end
|
17
|
+
|
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
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def dir_name(locale)
|
34
|
+
return ''
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
module Pixab
|
44
|
+
|
45
|
+
class LocalizationiOS < LocalizationPlatform
|
46
|
+
|
47
|
+
File_name = "Localizable.strings"
|
48
|
+
|
49
|
+
def run(localized_info_category, commands)
|
50
|
+
super(localized_info_category, commands)
|
51
|
+
|
52
|
+
localized_info_category.each do |locale, localized_infos|
|
53
|
+
content_dir_path = dir_name(locale)
|
54
|
+
if !Dir.exists?(content_dir_path)
|
55
|
+
FileUtils.mkdir_p content_dir_path
|
56
|
+
end
|
57
|
+
content_file_path = "#{content_dir_path}/#{File_name}"
|
58
|
+
File.open(content_file_path, @file_mode) do |aFile|
|
59
|
+
aFile.syswrite("\n// Created from phrase api <<<<<<<<<< begin\n")
|
60
|
+
localized_infos.each do |localized_info|
|
61
|
+
aFile.syswrite("\n\"#{localized_info['key']}\" = \"#{localized_info['value']}\";\n")
|
62
|
+
end
|
63
|
+
aFile.syswrite("\n// Created from phrase api <<<<<<<<<< end\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def dir_name(locale)
|
70
|
+
"#{locale}.lproj"
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
module Pixab
|
79
|
+
|
80
|
+
class LocalizationAndroid < LocalizationPlatform
|
81
|
+
|
82
|
+
File_name = "strings_ph.xml"
|
83
|
+
|
84
|
+
def run(localized_info_category, commands)
|
85
|
+
localized_info_category.each do |locale, localized_infos|
|
86
|
+
content_dir_path = dir_name(locale)
|
87
|
+
if !Dir.exists?(content_dir_path)
|
88
|
+
FileUtils.mkdir_p content_dir_path
|
89
|
+
end
|
90
|
+
content_file_path = "#{content_dir_path}/#{File_name}"
|
91
|
+
File.open(content_file_path, @file_mode) do |aFile|
|
92
|
+
aFile.syswrite("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
93
|
+
aFile.syswrite("<resources xmlns:tools=\"http://schemas.android.com/tools\">\n")
|
94
|
+
localized_infos.each do |localized_info|
|
95
|
+
aFile.syswrite(" <string name=\"#{localized_info['key']}\">#{localized_info['value']}</string>\n")
|
96
|
+
end
|
97
|
+
aFile.syswrite("</resources>\n")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def dir_name(locale)
|
104
|
+
suffix = ''
|
105
|
+
case locale
|
106
|
+
when 'en'
|
107
|
+
suffix = ''
|
108
|
+
when 'fr'
|
109
|
+
suffix = '-fr-rFR'
|
110
|
+
when 'ru'
|
111
|
+
suffix = '-ru-rRU'
|
112
|
+
when 'zh-hans'
|
113
|
+
suffix = '-zh-rCN'
|
114
|
+
when 'zh-hant'
|
115
|
+
suffix = '-tr-rTR'
|
116
|
+
else
|
117
|
+
suffix = "-#{locale}"
|
118
|
+
end
|
119
|
+
return "values#{suffix}"
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
data/lib/pixab/version.rb
CHANGED
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:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 廖再润
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Write a longer description or delete this line.
|
14
14
|
email:
|
@@ -26,6 +26,8 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- exe/pixab
|
28
28
|
- lib/ComponentSynchronizer.rb
|
29
|
+
- lib/Localization.rb
|
30
|
+
- lib/LocalizationPlatform.rb
|
29
31
|
- lib/MergeRequest.rb
|
30
32
|
- lib/RepoManager.rb
|
31
33
|
- lib/Utilities.rb
|