fastlane-plugin-google_sheet_localize 0.1.0 → 0.1.1

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: aa84006d7058d1cc9649efb0b0c8f7c540976c22621c9e07c5d1d9d3aa87d5df
4
- data.tar.gz: 9ebb44a052366f2274aaf1434063b0136f2b56e6c36f9a3527258a2bdcf4d893
3
+ metadata.gz: fd292bac4d8626916e67ced0f1b6f20aaa774144c1008b234bbcde6eb21b07a1
4
+ data.tar.gz: 538f1fc89c8cbcbd3ff661a473f37a89aa4809d453a4d1f3c79dda1ba19a0051
5
5
  SHA512:
6
- metadata.gz: f8079ccd415ce7c7277251915966b7a5da501b9e2619f1dad4c8c777a234de0ca9543b88b6aa8597bc51fa6d816e7086c8a5119a8804f1a4015b5aa253bb11f5
7
- data.tar.gz: 3bd3dd582afe25d12b26a6c34ea72c3f3362323debd7c5eca0045f4d01e57b9284f5def274260a5e5f519bfdab23dbdfcc5a199b55f761e7c6386ca3155ef141
6
+ metadata.gz: ffbeb72764b0d070f059f35d48c2eb4e1e021dd950a2f156629b8e2d2abbfca38be58cdf9f4e9a5e3c02b306a44e014e5dcbb56346a42fda168e07e9805d38fd
7
+ data.tar.gz: e59221b83e07ef8f0ef5e5514271eb071505b9f6f81d7dab2a8a0662a355a312968c115c6bf2f755d64d3f0f430fd87f9da0d4b4df04a951f94d4b0978a8e09a
@@ -10,13 +10,14 @@ module Fastlane
10
10
  spreadsheet_id = "https://docs.google.com/spreadsheets/d/#{params[:sheet_id]}"
11
11
  tabs = params[:tabs]
12
12
  plaform = params[:platform]
13
+ path = params[:localization_path]
13
14
 
14
15
  spreadsheet = session.spreadsheet_by_url(spreadsheet_id)
15
16
 
16
17
  # Get the first worksheet
17
18
  worksheet = spreadsheet.worksheets.first
18
19
 
19
- languages = numberOfLanguages(worksheet)
20
+ languages = self.numberOfLanguages(worksheet)
20
21
 
21
22
  result = []
22
23
 
@@ -38,19 +39,19 @@ module Fastlane
38
39
 
39
40
  filterdWorksheets.each { |worksheet|
40
41
  contentRows = worksheet.rows.drop(1)
41
- language['items'].concat(generateJSONObject(contentRows, i))
42
+ language['items'].concat(self.generateJSONObject(contentRows, i))
42
43
  }
43
44
 
44
45
  result.push(language)
45
46
 
46
47
  end
47
- createFiles(result, platform, path)
48
+ self.createFiles(result, platform, path)
48
49
  end
49
50
 
50
- def generateJSONObject(contentRows, index)
51
+ def self.generateJSONObject(contentRows, index)
51
52
  result = Array.new
52
53
  for i in 0..contentRows.count - 1
53
- item = generateSingleObject(contentRows[i], index)
54
+ item = self.generateSingleObject(contentRows[i], index)
54
55
 
55
56
  if item[:identifierIos] != "" && item[:identifierAndroid] != ""
56
57
  result.push(item)
@@ -61,13 +62,13 @@ module Fastlane
61
62
 
62
63
  end
63
64
 
64
- def writeToJSONFile(languages)
65
+ def self.writeToJSONFile(languages)
65
66
  File.open("output.json","w") do |f|
66
67
  f.write(JSON.pretty_generate(languages))
67
68
  end
68
69
  end
69
70
 
70
- def generateSingleObject(row, column)
71
+ def self.generateSingleObject(row, column)
71
72
  identifierIos = row[0]
72
73
  identifierAndroid = row[1]
73
74
 
@@ -84,8 +85,8 @@ module Fastlane
84
85
 
85
86
  end
86
87
 
87
- def createFiles(languages, platform, destinationPath)
88
- languages.each { |language| createFileForLanguage(language, platform, destinationPath) }
88
+ def self.createFiles(languages, platform, destinationPath)
89
+ languages.each { |language| self.createFileForLanguage(language, platform, destinationPath) }
89
90
 
90
91
  if platform == "ios"
91
92
 
@@ -113,27 +114,24 @@ module Fastlane
113
114
  end
114
115
  end
115
116
 
116
- text = mapInvalidPlaceholder(item['text'])
117
+ text = self.mapInvalidPlaceholder(item['text'])
117
118
 
118
- arguments = findArgumentsInText(text)
119
-
120
- puts "Arguments"
121
- puts arguments.count
119
+ arguments = self.findArgumentsInText(text)
122
120
 
123
121
  if arguments.count == 0
124
122
  f.write("\n\t///Sheet comment: #{item['comment']}\n\tpublic static let #{constantName} = localized(identifier: \"#{identifier}\")\n")
125
123
  else
126
- f.write(createiOSFunction(constantName, identifier, arguments, item['comment']))
124
+ f.write(self.createiOSFunction(constantName, identifier, arguments, item['comment']))
127
125
  end
128
126
  }
129
127
  f.write("\n}")
130
- f.write(createiOSFileEndString())
128
+ f.write(self.createiOSFileEndString())
131
129
  end
132
130
 
133
131
  end
134
132
  end
135
133
 
136
- def createFileForLanguage(language, platform, destinationPath)
134
+ def self.createFileForLanguage(language, platform, destinationPath)
137
135
  if platform == "ios"
138
136
 
139
137
  swiftFilename = "Localization.swift"
@@ -148,7 +146,7 @@ module Fastlane
148
146
  File.open(filepath, "w") do |f|
149
147
  filteredItems.each { |item|
150
148
 
151
- text = mapInvalidPlaceholder(item['text'])
149
+ text = self.mapInvalidPlaceholder(item['text'])
152
150
 
153
151
  f.write("//#{item['comment']}\n\"#{item['identifierIos']}\" = \"#{text}\";\n")
154
152
  }
@@ -168,11 +166,11 @@ module Fastlane
168
166
  end
169
167
  end
170
168
 
171
- def createiOSFileEndString()
169
+ def self.createiOSFileEndString()
172
170
  return "\n\nextension Localization {\n\tprivate static func localized(identifier key: String, _ args: CVarArg...) -> String {\n\t\tlet format = NSLocalizedString(key, tableName: nil, bundle: Bundle.main, comment: \"\")\n\n\t\tguard !args.isEmpty else { return format }\n\n\t\treturn String(format: format, locale: Locale.current, arguments: args)\n\t}\n}"
173
171
  end
174
172
 
175
- def createiOSFunction(constantName, identifier, arguments, comment)
173
+ def self.createiOSFunction(constantName, identifier, arguments, comment)
176
174
  functionTitle = "\n\t///Sheet comment: #{comment}\n\tpublic static func #{constantName}("
177
175
 
178
176
  arguments.each_with_index do |item, index|
@@ -197,11 +195,9 @@ module Fastlane
197
195
  return functionTitle
198
196
  end
199
197
 
200
- def findArgumentsInText(text)
198
+ def self.findArgumentsInText(text)
201
199
  result = Array.new
202
- filtered = mapInvalidPlaceholder(text)
203
-
204
- puts filtered
200
+ filtered = self.mapInvalidPlaceholder(text)
205
201
 
206
202
  stringIndexes = (0 ... filtered.length).find_all { |i| filtered[i,2] == '%@' }
207
203
  intIndexes = (0 ... filtered.length).find_all { |i| filtered[i,2] == '%d' }
@@ -224,23 +220,15 @@ module Fastlane
224
220
  result = result.concat(doubleIndexes.map { |e| { "index": e, "type": "Double" }})
225
221
  end
226
222
 
227
- puts result
228
- result = result.sort { |a, b| a[:index] <=> b[:index] }
229
- puts result
230
-
231
- puts "count"
232
- puts result.count
233
-
234
-
235
223
  return result
236
224
  end
237
225
 
238
- def mapInvalidPlaceholder(text)
226
+ def self.mapInvalidPlaceholder(text)
239
227
  filtered = text.gsub('%s', '%@')
240
228
  return filtered
241
229
  end
242
230
 
243
- def numberOfLanguages(worksheet)
231
+ def self.numberOfLanguages(worksheet)
244
232
  i = worksheet.num_cols
245
233
  return i - 3
246
234
  end
@@ -250,7 +238,7 @@ module Fastlane
250
238
  end
251
239
 
252
240
  def self.authors
253
- ["Mario Hahn"]
241
+ ["Mario Hahn", "Thomas Koller"]
254
242
  end
255
243
 
256
244
  def self.return_value
@@ -277,13 +265,19 @@ module Fastlane
277
265
  FastlaneCore::ConfigItem.new(key: :platform,
278
266
  env_name: "PLATFORM",
279
267
  description: "Plaform, ios or android",
280
- optional: "ios",
268
+ optional: true,
269
+ default_value: "ios",
281
270
  type: String),
282
271
  FastlaneCore::ConfigItem.new(key: :tabs,
283
272
  env_name: "TABS",
284
273
  description: "Array of all Google Sheet Tabs",
285
274
  optional: false,
286
- type: Array)
275
+ type: Array),
276
+ FastlaneCore::ConfigItem.new(key: :localization_path,
277
+ env_name: "LOCALIZATION_PATH",
278
+ description: "Output path",
279
+ optional: false,
280
+ type: String)
287
281
  ]
288
282
  end
289
283
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module GoogleSheetLocalize
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-google_sheet_localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Hahn