fastlane-plugin-google_sheet_localize 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87a4897b4267a2b1ec85e0decd035d4bbcaeec53b481a9c9d672476aad6065b6
|
4
|
+
data.tar.gz: ea0718e1d745c797e1ccf9c79d08dd299f8848381521652f4a524ad5f2a2ff47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e252a54b79b9728660ad3307d99caaec6500219fd11dbd4ffbf437340a9ae791be4e2879278c2f77fadfb1ecc5c787eac168883f0db2ced044ffeca68d67e031
|
7
|
+
data.tar.gz: 06e2fbf3ab587f03d94fd915abd7268daabaeef07a3a4bc9738aaf78eb87a48bb940de0ecfc3524ac9a123138cc64f01d8696d592bd2ee915660ec8361a023c8
|
@@ -13,41 +13,42 @@ module Fastlane
|
|
13
13
|
tabs = params[:tabs]
|
14
14
|
platform = params[:platform]
|
15
15
|
path = params[:localization_path]
|
16
|
+
language_titles = params[:language_titles]
|
17
|
+
default_language = params[:default_language]
|
16
18
|
|
17
19
|
spreadsheet = session.spreadsheet_by_url(spreadsheet_id)
|
18
|
-
|
19
|
-
# Get the first worksheet
|
20
20
|
worksheet = spreadsheet.worksheets.first
|
21
21
|
|
22
|
-
languages = self.numberOfLanguages(worksheet)
|
23
|
-
|
24
22
|
result = []
|
25
23
|
|
26
|
-
for i in
|
24
|
+
for i in 0..worksheet.max_cols
|
25
|
+
|
27
26
|
title = worksheet.rows[0][i]
|
28
27
|
|
29
|
-
|
30
|
-
'language' => title,
|
31
|
-
'items' => []
|
32
|
-
}
|
28
|
+
if language_titles.include?(title)
|
33
29
|
|
34
|
-
|
30
|
+
language = {
|
31
|
+
'language' => title,
|
32
|
+
'items' => []
|
33
|
+
}
|
35
34
|
|
36
|
-
|
37
|
-
filterdWorksheets = spreadsheet.worksheets
|
38
|
-
else
|
39
|
-
filterdWorksheets = spreadsheet.worksheets.select { |item| tabs.include?(item.title) }
|
40
|
-
end
|
35
|
+
filterdWorksheets = []
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
if tabs.count == 0
|
38
|
+
filterdWorksheets = spreadsheet.worksheets
|
39
|
+
else
|
40
|
+
filterdWorksheets = spreadsheet.worksheets.select { |item| tabs.include?(item.title) }
|
41
|
+
end
|
46
42
|
|
47
|
-
|
43
|
+
filterdWorksheets.each { |worksheet|
|
44
|
+
contentRows = worksheet.rows.drop(1)
|
45
|
+
language['items'].concat(self.generateJSONObject(contentRows, i))
|
46
|
+
}
|
48
47
|
|
48
|
+
result.push(language)
|
49
|
+
end
|
49
50
|
end
|
50
|
-
self.createFiles(result, platform, path)
|
51
|
+
self.createFiles(result, platform, path, default_language)
|
51
52
|
end
|
52
53
|
|
53
54
|
def self.generateJSONObject(contentRows, index)
|
@@ -64,12 +65,6 @@ module Fastlane
|
|
64
65
|
|
65
66
|
end
|
66
67
|
|
67
|
-
def self.writeToJSONFile(languages)
|
68
|
-
File.open("output.json","w") do |f|
|
69
|
-
f.write(JSON.pretty_generate(languages))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
68
|
def self.generateSingleObject(row, column)
|
74
69
|
identifierIos = row[0]
|
75
70
|
identifierAndroid = row[1]
|
@@ -87,8 +82,15 @@ module Fastlane
|
|
87
82
|
|
88
83
|
end
|
89
84
|
|
90
|
-
def
|
91
|
-
|
85
|
+
def filterUnusedRows(items, identifier)
|
86
|
+
return items.select { |item|
|
87
|
+
iosIdentifier = item[identifier]
|
88
|
+
iosIdentifier != "NR" && iosIdentifier != ""
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.createFiles(languages, platform, destinationPath, defaultLanguage)
|
93
|
+
self.createFilesForLanguages(languages, platform, destinationPath, defaultLanguage)
|
92
94
|
|
93
95
|
if platform == "ios"
|
94
96
|
|
@@ -135,35 +137,43 @@ module Fastlane
|
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
138
|
-
def self.
|
139
|
-
if platform == "ios"
|
140
|
+
def self.createFilesForLanguages(languages, platform, destinationPath, defaultLanguage)
|
140
141
|
|
141
|
-
|
142
|
-
swiftFilepath = "#{destinationPath}/#{swiftFilename}"
|
142
|
+
languages.each { |language|
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
}
|
144
|
+
if platform == "ios"
|
145
|
+
|
146
|
+
filteredItems = self.filterUnusedRows(language["items"],'identifierIos')
|
148
147
|
|
149
148
|
filename = "Localizable.strings"
|
150
149
|
filepath = "#{destinationPath}/#{language['language']}.lproj/#{filename}"
|
151
|
-
FileUtils.mkdir_p language['language']
|
150
|
+
FileUtils.mkdir_p "#{destinationPath}/#{language['language']}.lproj"
|
152
151
|
File.open(filepath, "w") do |f|
|
153
|
-
filteredItems.
|
152
|
+
filteredItems.each_with_index { |item, index|
|
154
153
|
|
155
154
|
text = self.mapInvalidPlaceholder(item['text'])
|
156
155
|
comment = item['comment']
|
157
156
|
identifier = item['identifierIos']
|
158
157
|
|
159
158
|
line = ""
|
160
|
-
|
161
159
|
if identifier.include?('//')
|
162
160
|
line = "\n\n#{identifier}\n"
|
163
161
|
else
|
162
|
+
|
163
|
+
if text == "" || text == "TBD"
|
164
|
+
default_language_object = languages.select { |languageItem| languageItem['language'] == defaultLanguage }.first["items"]
|
165
|
+
default_language_object = self.filterUnusedRows(default_language_object,'identifierIos')
|
166
|
+
|
167
|
+
defaultLanguageText = default_language_object[index]['text']
|
168
|
+
puts "found empty text for identifier: #{identifier} for language:#{language['language']}, replaceing it with #{defaultLanguageText}"
|
169
|
+
text = self.mapInvalidPlaceholder(defaultLanguageText)
|
170
|
+
end
|
171
|
+
|
164
172
|
line = "\"#{identifier}\" = \"#{text}\";"
|
165
173
|
if !comment.to_s.empty?
|
166
174
|
line = line + " //#{comment}\n"
|
175
|
+
else
|
176
|
+
line = line + "\n"
|
167
177
|
end
|
168
178
|
end
|
169
179
|
|
@@ -173,16 +183,40 @@ module Fastlane
|
|
173
183
|
end
|
174
184
|
|
175
185
|
if platform == "android"
|
176
|
-
|
177
|
-
|
186
|
+
languageDir = language['language']
|
187
|
+
|
188
|
+
if languageDir == "en"
|
189
|
+
languageDir = "values"
|
190
|
+
else
|
191
|
+
languageDir = "values-#{languageDir}"
|
192
|
+
end
|
193
|
+
|
194
|
+
FileUtils.mkdir_p "#{destinationPath}/#{languageDir}"
|
195
|
+
File.open("#{destinationPath}/#{languageDir}/strings.xml", "w") do |f|
|
178
196
|
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
|
179
197
|
f.write("<resources>\n")
|
180
198
|
language["items"].each { |item|
|
181
|
-
|
199
|
+
|
200
|
+
comment = item['comment']
|
201
|
+
identifier = item['identifierAndroid']
|
202
|
+
text = item['text']
|
203
|
+
|
204
|
+
if !identifier.to_s.empty? && identifier != "NR"
|
205
|
+
line = ""
|
206
|
+
|
207
|
+
if !comment.to_s.empty?
|
208
|
+
line = line + "\t<!--#{comment}-->\n"
|
209
|
+
end
|
210
|
+
|
211
|
+
line = line + "\t<string name=\"#{identifier}\"><![CDATA[#{text}]]></string>\n"
|
212
|
+
|
213
|
+
f.write(line)
|
214
|
+
end
|
182
215
|
}
|
183
216
|
f.write("</resources>\n")
|
184
217
|
end
|
185
218
|
end
|
219
|
+
}
|
186
220
|
end
|
187
221
|
|
188
222
|
def self.createiOSFileEndString()
|
@@ -243,15 +277,10 @@ module Fastlane
|
|
243
277
|
end
|
244
278
|
|
245
279
|
def self.mapInvalidPlaceholder(text)
|
246
|
-
filtered = text.gsub('%s', '%@')
|
280
|
+
filtered = text.gsub('%s', '%@').gsub('"', '\"')
|
247
281
|
return filtered
|
248
282
|
end
|
249
283
|
|
250
|
-
def self.numberOfLanguages(worksheet)
|
251
|
-
i = worksheet.num_cols
|
252
|
-
return i - 3
|
253
|
-
end
|
254
|
-
|
255
284
|
def self.description
|
256
285
|
"Creates .strings files for iOS and strings.xml files for Android"
|
257
286
|
end
|
@@ -292,6 +321,16 @@ module Fastlane
|
|
292
321
|
description: "Array of all Google Sheet Tabs",
|
293
322
|
optional: false,
|
294
323
|
type: Array),
|
324
|
+
FastlaneCore::ConfigItem.new(key: :language_titles,
|
325
|
+
env_name: "LANGUAGE_TITLES",
|
326
|
+
description: "Alle language titles",
|
327
|
+
optional: false,
|
328
|
+
type: Array),
|
329
|
+
FastlaneCore::ConfigItem.new(key: :default_language,
|
330
|
+
env_name: "DEFAULT_LANGUAGE",
|
331
|
+
description: "Default Language",
|
332
|
+
optional: false,
|
333
|
+
type: String),
|
295
334
|
FastlaneCore::ConfigItem.new(key: :localization_path,
|
296
335
|
env_name: "LOCALIZATION_PATH",
|
297
336
|
description: "Output path",
|