fastlane-plugin-google_sheet_localize 0.2.07 → 0.2.08
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d7de3c4d7121b4e4951eedee63a9e52be35327ee78ad9b21596ef94a1ba7e98
|
4
|
+
data.tar.gz: fbf9f07fc2ccb22cb88132473e353bdbd07d51b81bbd79f968b259fa0e33488e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ba498f21335ec969a77a330e3f99301fd07cfeb4255b13751253a900f02f03d357429288f28bb6167e96c75d9aedc2998df2ca284f51a1781aeb4a62f7d4ff
|
7
|
+
data.tar.gz: 96f8197af3ffb73bc768932f79251ae5a28e8eee4ee833f04a6f58e06ab66f913f4df7acdcd28596f29f732713bf85f96a6d093894f9eba00e5873878ea94be7
|
@@ -18,6 +18,19 @@ module Fastlane
|
|
18
18
|
default_language = params[:default_language]
|
19
19
|
base_language = params[:base_language]
|
20
20
|
code_generation_path = params[:code_generation_path]
|
21
|
+
identifier_name = params[:identifier_name]
|
22
|
+
|
23
|
+
if identifier_name.to_s.empty?
|
24
|
+
if platform == "ios"
|
25
|
+
identifier_name = "Identifier iOS"
|
26
|
+
end
|
27
|
+
if platform == "android"
|
28
|
+
identifier_name = "Identifier Android"
|
29
|
+
end
|
30
|
+
if platform == "web"
|
31
|
+
identifier_name = "Identifier Web"
|
32
|
+
end
|
33
|
+
end
|
21
34
|
|
22
35
|
spreadsheet = session.spreadsheet_by_url(spreadsheet_id)
|
23
36
|
worksheet = spreadsheet.worksheets.first
|
@@ -44,8 +57,16 @@ module Fastlane
|
|
44
57
|
end
|
45
58
|
|
46
59
|
filterdWorksheets.each { |worksheet|
|
60
|
+
identifierIndex = 0
|
61
|
+
|
62
|
+
for index in 0..worksheet.max_cols
|
63
|
+
if worksheet.rows[0][index] == identifier_name
|
64
|
+
identifierIndex = index
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
47
68
|
contentRows = worksheet.rows.drop(1)
|
48
|
-
language['items'].concat(self.generateJSONObject(contentRows, i))
|
69
|
+
language['items'].concat(self.generateJSONObject(contentRows, i, identifierIndex))
|
49
70
|
}
|
50
71
|
|
51
72
|
result.push(language)
|
@@ -54,12 +75,12 @@ module Fastlane
|
|
54
75
|
self.createFiles(result, platform, path, default_language, base_language, code_generation_path)
|
55
76
|
end
|
56
77
|
|
57
|
-
def self.generateJSONObject(contentRows, index)
|
78
|
+
def self.generateJSONObject(contentRows, index, identifierIndex)
|
58
79
|
result = Array.new
|
59
80
|
for i in 0..contentRows.count - 1
|
60
|
-
item = self.generateSingleObject(contentRows[i], index)
|
81
|
+
item = self.generateSingleObject(contentRows[i], index, identifierIndex)
|
61
82
|
|
62
|
-
if item[:
|
83
|
+
if item[:identifier] != ""
|
63
84
|
result.push(item)
|
64
85
|
end
|
65
86
|
end
|
@@ -68,33 +89,74 @@ module Fastlane
|
|
68
89
|
|
69
90
|
end
|
70
91
|
|
71
|
-
def self.generateSingleObject(row, column)
|
72
|
-
|
73
|
-
identifierAndroid = row[1]
|
92
|
+
def self.generateSingleObject(row, column, identifierIndex)
|
93
|
+
identifier = row[identifierIndex]
|
74
94
|
|
75
95
|
text = row[column]
|
76
96
|
comment = row.last
|
77
97
|
|
78
|
-
object = { '
|
79
|
-
'identifierAndroid' => identifierAndroid,
|
98
|
+
object = { 'identifier' => identifier,
|
80
99
|
'text' => text,
|
81
100
|
'comment' => comment
|
82
101
|
}
|
83
|
-
|
84
102
|
return object
|
85
103
|
|
86
104
|
end
|
87
105
|
|
88
|
-
def self.filterUnusedRows(items, identifier)
|
89
|
-
|
106
|
+
def self.filterUnusedRows(items, identifier, filterComment)
|
107
|
+
filtered = items.select { |item|
|
90
108
|
currentIdentifier = item[identifier]
|
91
109
|
currentIdentifier != "NR" && currentIdentifier != "" && currentIdentifier != "TBD"
|
92
110
|
}
|
111
|
+
|
112
|
+
if filterComment == "false"
|
113
|
+
return filtered
|
114
|
+
end
|
115
|
+
|
116
|
+
return filtered.select { |item|
|
117
|
+
!item[identifier].include?('//')
|
118
|
+
}
|
93
119
|
end
|
94
120
|
|
95
121
|
def self.createFiles(languages, platform, destinationPath, defaultLanguage, base_language, codeGenerationPath)
|
96
122
|
self.createFilesForLanguages(languages, platform, destinationPath, defaultLanguage, base_language)
|
97
123
|
|
124
|
+
if platform == "web"
|
125
|
+
jsonFileName = "Localization.json"
|
126
|
+
|
127
|
+
jsonFilepath = "#{destinationPath}/#{jsonFileName}"
|
128
|
+
|
129
|
+
File.open(jsonFilepath, "w") do |f|
|
130
|
+
|
131
|
+
jsonItem = {}
|
132
|
+
|
133
|
+
languages.each { |language|
|
134
|
+
filteredItems = self.filterUnusedRows(language["items"],'identifier', "true")
|
135
|
+
|
136
|
+
allKeys = {}
|
137
|
+
|
138
|
+
filteredItems.each { |item|
|
139
|
+
identifier = item['identifier']
|
140
|
+
|
141
|
+
text = item['text']
|
142
|
+
|
143
|
+
matches = text.scan(/%[0-9][sdf]/)
|
144
|
+
matches.each { |match|
|
145
|
+
text = text.gsub(match, "{#{match[1]}}")
|
146
|
+
}
|
147
|
+
|
148
|
+
if !identifier.include?('//')
|
149
|
+
allKeys[identifier] = text
|
150
|
+
end
|
151
|
+
}
|
152
|
+
jsonItem[language["language"]] = allKeys
|
153
|
+
}
|
154
|
+
|
155
|
+
jsonString = JSON.pretty_generate(jsonItem)
|
156
|
+
f.write(jsonString)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
98
160
|
if platform == "ios"
|
99
161
|
|
100
162
|
swiftFilename = "Localization.swift"
|
@@ -105,18 +167,15 @@ module Fastlane
|
|
105
167
|
swiftPath = destinationPath
|
106
168
|
end
|
107
169
|
|
108
|
-
|
170
|
+
filteredItems = self.filterUnusedRows(languages[0]["items"],'identifier', "true")
|
109
171
|
|
110
|
-
|
111
|
-
iosIdentifier = item['identifierIos']
|
112
|
-
iosIdentifier != "NR" && iosIdentifier != "" && !iosIdentifier.include?('//') && iosIdentifier != "TBD"
|
113
|
-
}
|
172
|
+
swiftFilepath = "#{swiftPath}/#{swiftFilename}"
|
114
173
|
|
115
174
|
File.open(swiftFilepath, "w") do |f|
|
116
175
|
f.write("import Foundation\n\n// swiftlint:disable all\npublic struct Localization {\n")
|
117
176
|
filteredItems.each { |item|
|
118
177
|
|
119
|
-
identifier = item['
|
178
|
+
identifier = item['identifier']
|
120
179
|
|
121
180
|
values = identifier.dup.split(".")
|
122
181
|
|
@@ -163,7 +222,7 @@ module Fastlane
|
|
163
222
|
|
164
223
|
if platform == "ios"
|
165
224
|
|
166
|
-
filteredItems = self.filterUnusedRows(language["items"],'
|
225
|
+
filteredItems = self.filterUnusedRows(language["items"],'identifier', "false")
|
167
226
|
|
168
227
|
stringFileName = "Localizable.strings"
|
169
228
|
pluralsFileName = "Localizable.stringsdict"
|
@@ -183,7 +242,7 @@ module Fastlane
|
|
183
242
|
|
184
243
|
text = self.mapInvalidPlaceholder(item['text'])
|
185
244
|
comment = item['comment']
|
186
|
-
identifier = item['
|
245
|
+
identifier = item['identifier']
|
187
246
|
|
188
247
|
line = ""
|
189
248
|
if identifier.include?('//')
|
@@ -194,13 +253,19 @@ module Fastlane
|
|
194
253
|
|
195
254
|
if (text == "" || text == "TBD") && !defaultLanguage.to_s.empty?
|
196
255
|
default_language_object = languages.select { |languageItem| languageItem['language'] == defaultLanguage }.first["items"]
|
197
|
-
default_language_object = self.filterUnusedRows(default_language_object,'
|
256
|
+
default_language_object = self.filterUnusedRows(default_language_object,'identifier', "false")
|
198
257
|
|
199
258
|
defaultLanguageText = default_language_object[index]['text']
|
200
259
|
puts "found empty text for:\n\tidentifier: #{identifier}\n\tlanguage:#{language['language']}\n\treplacing it with: #{defaultLanguageText}"
|
201
260
|
text = self.mapInvalidPlaceholder(defaultLanguageText)
|
202
261
|
end
|
203
262
|
|
263
|
+
matches = text.scan(/%[0-9][sdf]/)
|
264
|
+
|
265
|
+
matches.each { |match|
|
266
|
+
text = text.gsub(match, "%#{match[1]}$#{match[2].gsub("s","@")}")
|
267
|
+
}
|
268
|
+
|
204
269
|
line = "\"#{identifier}\" = \"#{text}\";"
|
205
270
|
if !comment.to_s.empty?
|
206
271
|
line = line + " //#{comment}\n"
|
@@ -223,12 +288,12 @@ module Fastlane
|
|
223
288
|
filteredItems.each_with_index { |item, index|
|
224
289
|
|
225
290
|
text = self.mapInvalidPlaceholder(item['text'])
|
226
|
-
identifier = item['
|
291
|
+
identifier = item['identifier']
|
227
292
|
|
228
293
|
if !identifier.include?('//') && text.include?("one|")
|
229
294
|
if (text == "" || text == "TBD") && !defaultLanguage.to_s.empty?
|
230
295
|
default_language_object = languages.select { |languageItem| languageItem['language'] == defaultLanguage }.first["items"]
|
231
|
-
default_language_object = self.filterUnusedRows(default_language_object,'
|
296
|
+
default_language_object = self.filterUnusedRows(default_language_object,'identifier', "false")
|
232
297
|
|
233
298
|
defaultLanguageText = default_language_object[index]['text']
|
234
299
|
puts "found empty text for:\n\tidentifier: #{identifier}\n\tlanguage:#{language['language']}\n\treplacing it with: #{defaultLanguageText}"
|
@@ -280,12 +345,12 @@ module Fastlane
|
|
280
345
|
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
|
281
346
|
f.write("<resources>\n")
|
282
347
|
|
283
|
-
filteredItems = self.filterUnusedRows(language["items"],'
|
348
|
+
filteredItems = self.filterUnusedRows(language["items"],'identifier', "false")
|
284
349
|
|
285
350
|
filteredItems.each_with_index { |item, index|
|
286
351
|
|
287
352
|
comment = item['comment']
|
288
|
-
identifier = item['
|
353
|
+
identifier = item['identifier']
|
289
354
|
text = item['text']
|
290
355
|
|
291
356
|
line = ""
|
@@ -296,7 +361,7 @@ module Fastlane
|
|
296
361
|
|
297
362
|
if (text == "" || text == "TBD") && !defaultLanguage.to_s.empty?
|
298
363
|
default_language_object = languages.select { |languageItem| languageItem['language'] == defaultLanguage }.first["items"]
|
299
|
-
default_language_object = self.filterUnusedRows(default_language_object,'
|
364
|
+
default_language_object = self.filterUnusedRows(default_language_object,'identifier', "false")
|
300
365
|
|
301
366
|
defaultLanguageText = default_language_object[index]['text']
|
302
367
|
puts "found empty text for:\n\tidentifier: #{identifier}\n\tlanguage:#{language['language']}\n\treplacing it with: #{defaultLanguageText}"
|
@@ -380,10 +445,10 @@ module Fastlane
|
|
380
445
|
result = Array.new
|
381
446
|
filtered = self.mapInvalidPlaceholder(text)
|
382
447
|
|
383
|
-
stringIndexes =
|
384
|
-
intIndexes =
|
385
|
-
floatIndexes =
|
386
|
-
doubleIndexes =
|
448
|
+
stringIndexes = filtered.scan(/%[0-9]?[s@]/)
|
449
|
+
intIndexes = filtered.scan(/%[0-9]?[d]/)
|
450
|
+
floatIndexes = filtered.scan(/%[0-9]?[f]/)
|
451
|
+
doubleIndexes = filtered.scan(/%[0-9]?[ld]/)
|
387
452
|
|
388
453
|
if stringIndexes.count > 0
|
389
454
|
result = result.concat(stringIndexes.map { |e| { "index": e, "type": "String" }})
|
@@ -440,7 +505,7 @@ module Fastlane
|
|
440
505
|
type: String),
|
441
506
|
FastlaneCore::ConfigItem.new(key: :platform,
|
442
507
|
env_name: "PLATFORM",
|
443
|
-
description: "
|
508
|
+
description: "Platform, ios or android",
|
444
509
|
optional: true,
|
445
510
|
default_value: Actions.lane_context[Actions::SharedValues::PLATFORM_NAME].to_s,
|
446
511
|
default_value_dynamic: true,
|
@@ -471,6 +536,11 @@ module Fastlane
|
|
471
536
|
description: "Output path",
|
472
537
|
optional: false,
|
473
538
|
type: String),
|
539
|
+
FastlaneCore::ConfigItem.new(key: :identifier_name,
|
540
|
+
env_name: "IDENTIFIER_NAME",
|
541
|
+
description: "Identifier for Platform",
|
542
|
+
optional: true,
|
543
|
+
type: String),
|
474
544
|
FastlaneCore::ConfigItem.new(key: :code_generation_path,
|
475
545
|
env_name: "CODEGENERATIONPATH",
|
476
546
|
description: "Code generation path for the Swift file",
|