pixab 1.3.5 → 1.5.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/lib/LocalizationPlatform.rb +72 -36
- data/lib/pixab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acaaef2eca38499cd2cae9cdf0ed46b1f81096b460cd7ee4c18858edf4cedf6a
|
4
|
+
data.tar.gz: da441801f798f077906f7cf22eccbfbcb42fd460ce869a298dc8e495fb73ccd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab66caadef1cc1a3fa2c536e80543fa2b0efb6f5e814cc932a90aabe32c316b1afbec8a1885d68f78a42981f0b3f2e66a00ea1c8e51e42f7da782fafe24ea1fc
|
7
|
+
data.tar.gz: 320fbdac9d0c560dda72810526065b488fd52fa32d1bd638cc9c627f9b9d7f847645f79f7e6e6112fdde8a9bdeb0a8ca12a29688e981edc5b8b4616ee76e58e7
|
data/lib/LocalizationPlatform.rb
CHANGED
@@ -8,10 +8,6 @@ module Pixab
|
|
8
8
|
|
9
9
|
class LocalizationPlatform
|
10
10
|
|
11
|
-
def initialize()
|
12
|
-
@file_mode = 'w+'
|
13
|
-
end
|
14
|
-
|
15
11
|
def run(localized_info_category, commands)
|
16
12
|
resolve_commands(commands)
|
17
13
|
end
|
@@ -24,10 +20,7 @@ module Pixab
|
|
24
20
|
command = commands[index]
|
25
21
|
case command
|
26
22
|
when "--mode"
|
27
|
-
mode = commands[index + 1]
|
28
|
-
if mode == 'add'
|
29
|
-
@file_mode = 'a+'
|
30
|
-
end
|
23
|
+
@mode = commands[index + 1]
|
31
24
|
end
|
32
25
|
end
|
33
26
|
end
|
@@ -36,6 +29,15 @@ module Pixab
|
|
36
29
|
return ''
|
37
30
|
end
|
38
31
|
|
32
|
+
def file_mode
|
33
|
+
case @mode
|
34
|
+
when 'add'
|
35
|
+
return 'a+'
|
36
|
+
else
|
37
|
+
return 'w+'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
39
41
|
end
|
40
42
|
|
41
43
|
end
|
@@ -50,40 +52,83 @@ module Pixab
|
|
50
52
|
def run(localized_info_category, commands)
|
51
53
|
super(localized_info_category, commands)
|
52
54
|
|
53
|
-
begin_prompt = "\n// Created from phrase api <<<<<<<<<< begin\n"
|
54
|
-
end_prompt = "\n// Created from phrase api <<<<<<<<<< end\n"
|
55
|
-
|
56
55
|
localized_info_category.each do |locale, localized_infos|
|
57
56
|
content_dir_path = dir_name(locale)
|
58
57
|
if !Utilities.dir_exist(content_dir_path)
|
59
58
|
FileUtils.mkdir_p content_dir_path
|
60
59
|
end
|
61
60
|
content_file_path = "#{content_dir_path}/#{File_name}"
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
|
62
|
+
case @mode
|
63
|
+
when 'add'
|
64
|
+
write_file_add(content_file_path, localized_infos)
|
65
|
+
when 'replace'
|
66
|
+
write_file_replace(content_file_path, localized_infos)
|
67
|
+
when 'append'
|
68
|
+
write_file_append(content_file_path, localized_infos)
|
69
|
+
else
|
70
|
+
write_file_by_mode(content_file_path, localized_infos, 'w')
|
69
71
|
end
|
70
|
-
|
71
|
-
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def dir_name(locale)
|
76
|
+
"#{locale}.lproj"
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_file_add(content_file_path, localized_infos)
|
80
|
+
if File::exists?(content_file_path)
|
81
|
+
# 移除以前脚本添加的本地化文案
|
82
|
+
content = File.read(content_file_path)
|
83
|
+
content = content.sub(/#{begin_prompt}.*#{end_prompt}/m, '')
|
84
|
+
File.open(content_file_path, 'w+') do |file|
|
85
|
+
file.syswrite(content)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
write_file_by_mode(content_file_path, localized_infos, file_mode)
|
89
|
+
end
|
90
|
+
|
91
|
+
def write_file_replace(content_file_path, localized_infos)
|
92
|
+
# write_file_by_mode(content_file_path, localized_infos, file_mode)
|
93
|
+
end
|
94
|
+
|
95
|
+
def write_file_append(content_file_path, localized_infos)
|
96
|
+
if File::exists?(content_file_path)
|
97
|
+
file_content = File.read(content_file_path)
|
98
|
+
if index = file_content.index(end_prompt)
|
72
99
|
localized_infos.each do |localized_info|
|
73
|
-
|
74
|
-
value = value.gsub(/%s/, '%@')
|
75
|
-
file.syswrite("\n\"#{localized_info['key']}\" = \"#{value}\";\n")
|
100
|
+
file_content.insert(index, genetate_localized_string(localized_info))
|
76
101
|
end
|
77
|
-
file.
|
102
|
+
File.open(content_file_path, 'w') { |file| file.write(file_content) }
|
103
|
+
return
|
78
104
|
end
|
79
105
|
end
|
106
|
+
write_file_by_mode(content_file_path, localized_infos, 'a+')
|
80
107
|
end
|
81
108
|
|
109
|
+
def write_file_by_mode(content_file_path, localized_infos, mode)
|
110
|
+
File.open(content_file_path, mode) do |file|
|
111
|
+
file.syswrite(begin_prompt)
|
112
|
+
localized_infos.each do |localized_info|
|
113
|
+
file.syswrite(genetate_localized_string(localized_info))
|
114
|
+
end
|
115
|
+
file.syswrite(end_prompt)
|
116
|
+
end
|
117
|
+
end
|
82
118
|
|
83
|
-
def
|
84
|
-
"
|
119
|
+
def begin_prompt
|
120
|
+
return "\n// Created from phrase api <<<<<<<<<< begin\n"
|
85
121
|
end
|
86
122
|
|
123
|
+
def end_prompt
|
124
|
+
return "\n// Created from phrase api <<<<<<<<<< end\n"
|
125
|
+
end
|
126
|
+
|
127
|
+
def genetate_localized_string(localized_info)
|
128
|
+
value = localized_info['value'].gsub(/["]/, '\\\\\0')
|
129
|
+
value = value.gsub(/%s/, '%@')
|
130
|
+
return "\n\"#{localized_info['key']}\" = \"#{value}\";\n"
|
131
|
+
end
|
87
132
|
|
88
133
|
end
|
89
134
|
|
@@ -93,15 +138,6 @@ module Pixab
|
|
93
138
|
|
94
139
|
class LocalizationMac < LocalizationiOS
|
95
140
|
|
96
|
-
def dir_name(locale)
|
97
|
-
suffix = locale
|
98
|
-
case locale
|
99
|
-
when 'pt'
|
100
|
-
suffix = 'pt-PT'
|
101
|
-
end
|
102
|
-
return "#{suffix}.lproj"
|
103
|
-
end
|
104
|
-
|
105
141
|
end
|
106
142
|
|
107
143
|
end
|
@@ -124,7 +160,7 @@ module Pixab
|
|
124
160
|
FileUtils.mkdir_p content_dir_path
|
125
161
|
end
|
126
162
|
content_file_path = "#{content_dir_path}/#{File_name}"
|
127
|
-
File.open(content_file_path,
|
163
|
+
File.open(content_file_path, file_mode) do |file|
|
128
164
|
file.syswrite("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
129
165
|
file.syswrite("<resources>\n")
|
130
166
|
localized_infos.each do |localized_info|
|
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: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 廖再润
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored2
|