fastlane-plugin-google_sheet_localize 0.2.10 → 0.3.0

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: f01c89ddd217a7a4ba1c0691f22fe7c2b663cbce770e0290e7876c1432b29dc4
4
- data.tar.gz: c2cbabd869492a13b0f992efa6e331afad18a028d25de0138f865b6fcdb29ba4
3
+ metadata.gz: 7226e41700dadff517f0fbb7d0963ee8ee5bf72f27f5c44b983b4bf9d537e058
4
+ data.tar.gz: 9585d8c9e5ddc5c6ee25687f979a9505b93bd9f0eeb5a44e99823e628ad6f96a
5
5
  SHA512:
6
- metadata.gz: 2c1cc4ad3ae80886de16f725bed0e29b4e759eedb156e4c4bbd585dc725add3fd3970707487833c2d603b63bf1c08b4193788f3ecaf2371b87b4f13ef1c603f3
7
- data.tar.gz: 76ef7846e7691259f59712a4969392c301fcf7ae05df8f264aba415d21f91862cb62c0338906fd45b0a0b5c8b9cd6989a7e0280221ce4d6db403a87c56604657
6
+ metadata.gz: 32085198f4d2c22cd773f62c65fa11eb9e1cbe3fedbabdfb1925f798b47610eec039e9b6b7268e632e7a21ae0bba82ea7bc1f425927c084ab3c5cbfac24058d2
7
+ data.tar.gz: 38cf66f5caf4123ad4dfccc74049929cf2baed2f1f805c394094348ba3a7a5401b808cbe0a55ee2a6539ab2dc306e2dffdec1880e745831e7463cc04983a28cb
@@ -19,6 +19,7 @@ module Fastlane
19
19
  base_language = params[:base_language]
20
20
  code_generation_path = params[:code_generation_path]
21
21
  identifier_name = params[:identifier_name]
22
+ comment_example_language = params[:comment_example_language]
22
23
 
23
24
  if identifier_name.to_s.empty?
24
25
  if platform == "ios"
@@ -32,6 +33,10 @@ module Fastlane
32
33
  end
33
34
  end
34
35
 
36
+ if comment_example_language.to_s.empty?
37
+ comment_example_language = default_language
38
+ end
39
+
35
40
  spreadsheet = session.spreadsheet_by_url(spreadsheet_id)
36
41
 
37
42
  filterdWorksheets = []
@@ -80,7 +85,7 @@ module Fastlane
80
85
  end
81
86
  end
82
87
  }
83
- self.createFiles(result, platform, path, default_language, base_language, code_generation_path)
88
+ self.createFiles(result, platform, path, default_language, base_language, code_generation_path, comment_example_language)
84
89
  end
85
90
 
86
91
  def self.generateJSONObject(contentRows, index, identifierIndex)
@@ -126,7 +131,7 @@ module Fastlane
126
131
  }
127
132
  end
128
133
 
129
- def self.createFiles(languages, platform, destinationPath, defaultLanguage, base_language, codeGenerationPath)
134
+ def self.createFiles(languages, platform, destinationPath, defaultLanguage, base_language, codeGenerationPath, comment_example_language)
130
135
  self.createFilesForLanguages(languages, platform, destinationPath, defaultLanguage, base_language)
131
136
 
132
137
  if platform == "web"
@@ -175,7 +180,9 @@ module Fastlane
175
180
  swiftPath = destinationPath
176
181
  end
177
182
 
178
- filteredItems = self.filterUnusedRows(languages[0]["items"],'identifier', "true")
183
+ languageItems = languages.select { |item| item["language"] == comment_example_language }.first
184
+
185
+ filteredItems = self.filterUnusedRows(languageItems["items"],'identifier', "true")
179
186
 
180
187
  swiftFilepath = "#{swiftPath}/#{swiftFilename}"
181
188
 
@@ -212,18 +219,47 @@ module Fastlane
212
219
  arguments = self.findArgumentsInText(text)
213
220
 
214
221
  if arguments.count == 0
215
- f.write("\n\t///Sheet comment: #{item['comment']}\n\tpublic static let #{constantName} = localized(identifier: \"#{identifier}\")\n")
222
+ f.write(self.createComment(item['comment'], item['text']))
223
+ f.write("public static let #{constantName} = localized(identifier: \"#{identifier}\")\n")
216
224
  else
217
- f.write(self.createiOSFunction(constantName, identifier, arguments, item['comment']))
225
+ f.write(self.createComment(item['comment'], item['text']))
226
+ f.write(self.createiOSFunction(constantName, identifier, arguments))
218
227
  end
219
228
  }
220
229
  f.write("\n}")
221
- f.write(self.createiOSFileEndString())
230
+ f.write(self.createiOSFileEndString(destinationPath))
222
231
  end
223
232
 
224
233
  end
225
234
  end
226
235
 
236
+ def self.createComment(comment, example)
237
+
238
+ if comment.to_s.empty?
239
+ return %Q(
240
+ /**
241
+ - Example:
242
+ ````
243
+ #{example}
244
+ ````
245
+ */
246
+ )
247
+ end
248
+
249
+ return %Q(
250
+ /**
251
+ - Sheet comment:
252
+ ````
253
+ #{comment}
254
+ ````
255
+ - Example:
256
+ ````
257
+ #{example}
258
+ ````
259
+ */
260
+ )
261
+ end
262
+
227
263
  def self.createFilesForLanguages(languages, platform, destinationPath, defaultLanguage, base_language)
228
264
 
229
265
  languages.each { |language|
@@ -382,30 +418,30 @@ module Fastlane
382
418
 
383
419
  text = text.gsub("\n", "|")
384
420
 
385
- line = line + "\t<plurals name=\"#{identifier}\">\n"
421
+ line = line + " <plurals name=\"#{identifier}\">\n"
386
422
 
387
423
  plural = ""
388
424
 
389
425
  text.split("|").each_with_index { |word, wordIndex|
390
426
  if wordIndex % 2 == 0
391
- plural = "\t\t<item quantity=\"#{word}\">"
427
+ plural = " <item quantity=\"#{word}\">"
392
428
  else
393
429
  plural = plural + "<![CDATA[#{word}]]></item>\n"
394
430
  line = line + plural
395
431
  end
396
432
  }
397
- line = line + "\t</plurals>\n"
433
+ line = line + " </plurals>\n"
398
434
  elsif text.start_with?("[\"") && text.end_with?("\"]")
399
435
 
400
- line = line + "\t<string-array name=\"#{identifier}\">\n"
436
+ line = line + " <string-array name=\"#{identifier}\">\n"
401
437
 
402
438
  JSON.parse(text).each { |arrayItem|
403
- line = line + "\t\t<item><![CDATA[#{arrayItem}]]></item>\n"
439
+ line = line + " <item><![CDATA[#{arrayItem}]]></item>\n"
404
440
  }
405
441
 
406
- line = line + "\t</string-array>\n"
442
+ line = line + " </string-array>\n"
407
443
  else
408
- line = line + "\t<string name=\"#{identifier}\"><![CDATA[#{text}]]></string>\n"
444
+ line = line + " <string name=\"#{identifier}\"><![CDATA[#{text}]]></string>\n"
409
445
  end
410
446
 
411
447
  f.write(line)
@@ -416,12 +452,32 @@ module Fastlane
416
452
  }
417
453
  end
418
454
 
419
- def self.createiOSFileEndString()
420
- return "\n\nprivate class LocalizationHelper { }\n\nextension Localization {\n\tprivate static func localized(identifier key: String, _ args: CVarArg...) -> String {\n\t\tlet format = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: LocalizationHelper.self), comment: \"\")\n\n\t\tguard !args.isEmpty else { return format }\n\n\t\treturn String(format: format, locale: .current, arguments: args)\n\t}\n}"
455
+ def self.createiOSFileEndString(destinationPath)
456
+
457
+ bundle = "let bundle = Bundle(for: LocalizationHelper.self)"
458
+
459
+ puts destinationPath
460
+
461
+ if destinationPath.include?(".bundle")
462
+
463
+ bundle = %Q(let bundleUrl = Bundle(for: LocalizationHelper.self).url(forResource: "#{destinationPath.split('/').last.gsub(".bundle", "")}", withExtension: "bundle")
464
+ \n\t\tlet bundle = Bundle(url: bundleUrl!))
465
+ end
466
+
467
+ return %Q(
468
+ \n\nprivate class LocalizationHelper { }
469
+ \n\nextension Localization {
470
+ \n\tprivate static func localized(identifier key: String, _ args: CVarArg...) -> String {
471
+ \n\t\t#{bundle}
472
+ \n\t\tlet format = NSLocalizedString(key, tableName: nil, bundle: bundle, comment: \"\")
473
+ \n\t\tguard !args.isEmpty else { return format }
474
+ \n\t\treturn String(format: format, locale: .current, arguments: args)
475
+ \n\t}
476
+ \n})
421
477
  end
422
478
 
423
- def self.createiOSFunction(constantName, identifier, arguments, comment)
424
- functionTitle = "\n\t///Sheet comment: #{comment}\n\tpublic static func #{constantName}("
479
+ def self.createiOSFunction(constantName, identifier, arguments)
480
+ functionTitle = "public static func #{constantName}("
425
481
 
426
482
  arguments.each_with_index do |item, index|
427
483
  functionTitle = functionTitle + "_ arg#{index}: #{item[:type]}"
@@ -534,6 +590,11 @@ module Fastlane
534
590
  description: "Default Language",
535
591
  optional: true,
536
592
  type: String),
593
+ FastlaneCore::ConfigItem.new(key: :comment_example_language,
594
+ env_name: "COMMENT_EXAMPLE_LANGUAGE",
595
+ description: "Comment Example Language",
596
+ optional: true,
597
+ type: String),
537
598
  FastlaneCore::ConfigItem.new(key: :base_language,
538
599
  env_name: "BASE_LANGUAGE",
539
600
  description: "Base language for Xcode projects",
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module GoogleSheetLocalize
3
- VERSION = "0.2.10"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-google_sheet_localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Hahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-27 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive