fastlane-plugin-google_sheet_localize 0.3.06 → 0.4.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: 8cd7e38197a7a899f0babccc4dd007133de1f45a4f75cd8164161b77a380d0be
4
- data.tar.gz: 6aae195e79318258190b3a8b1d2dd68977589c771f7a746ecb48e4e04522dd3a
3
+ metadata.gz: 15c037771e905ef04ad956696cde554c6fde266c3d43c4018e798b4cd2633749
4
+ data.tar.gz: 1492ff3d8dc8564f847fcd512a5494a28be79d4bb8f255562a3445be77f0e77a
5
5
  SHA512:
6
- metadata.gz: b3d4cee30ff65e35d313138b8deb8644596dc517d1c2f4517b073506a9cd5e546b082cc3f899fda617188197a29f5fbe05c4395786a48c0fcc8dc6d3dbdbe973
7
- data.tar.gz: b1a107ece3531c4ee3ccdb57fec4c108540ea4f14689a1a1d5fa14b083f33621687f4afbc7f284d60301f3c4416c4a4cca55a151602eacefa6947a6cca5cd015
6
+ metadata.gz: f5807b14f1949f33f7137414086a49e0722b02e381baf0718581b4a0147c3514a7c8d6c89d3086565bc71d1810fd182d722d7d0f389f15a5eeeb9270b14e08c5
7
+ data.tar.gz: c47ed3818bdfe98c4add9aa6c6c4ee99e09f003b4ad81651941e06ffc6fd15a9ec84e1f9aaf362e8eaa522ec7690bf795a58b406b086e8c7e7b3803faabea3fa
data/README.md CHANGED
@@ -41,6 +41,11 @@ other|%d artists
41
41
  #### String Array: (Android)
42
42
  ["Monday", "Tuesday", "Wednesday"]
43
43
 
44
+ ## iOS specifics
45
+
46
+ In order to support Objective-C, the plugin provides the `support_objc` argument, which is default `false`.
47
+ Therefore, if you need Objective-C support pass `support_objc: true`.
48
+
44
49
  ## Example
45
50
 
46
51
  ```ruby
@@ -20,6 +20,8 @@ module Fastlane
20
20
  code_generation_path = params[:code_generation_path]
21
21
  identifier_name = params[:identifier_name]
22
22
  comment_example_language = params[:comment_example_language]
23
+ support_objc = params[:support_objc]
24
+ support_spm = params[:support_spm]
23
25
 
24
26
  if identifier_name.to_s.empty?
25
27
  if platform == "ios"
@@ -85,7 +87,7 @@ module Fastlane
85
87
  end
86
88
  end
87
89
  }
88
- self.createFiles(result, platform, path, default_language, base_language, code_generation_path, comment_example_language)
90
+ self.createFiles(result, platform, path, default_language, base_language, code_generation_path, comment_example_language, support_objc, support_spm)
89
91
  end
90
92
 
91
93
  def self.generateJSONObject(contentRows, index, identifierIndex)
@@ -131,7 +133,7 @@ module Fastlane
131
133
  }
132
134
  end
133
135
 
134
- def self.createFiles(languages, platform, destinationPath, defaultLanguage, base_language, codeGenerationPath, comment_example_language)
136
+ def self.createFiles(languages, platform, destinationPath, defaultLanguage, base_language, codeGenerationPath, comment_example_language, support_objc, support_spm)
135
137
  self.createFilesForLanguages(languages, platform, destinationPath, defaultLanguage, base_language)
136
138
 
137
139
  if platform == "web"
@@ -187,7 +189,7 @@ module Fastlane
187
189
  swiftFilepath = "#{swiftPath}/#{swiftFilename}"
188
190
 
189
191
  File.open(swiftFilepath, "w") do |f|
190
- f.write("import Foundation\n\n// swiftlint:disable all\npublic class Localization: NSObject {\n")
192
+ f.write("import Foundation\n\n// swiftlint:disable all\n#{getiOSTypeDefinition(support_objc)} {\n")
191
193
  filteredItems.each { |item|
192
194
 
193
195
  identifier = item['identifier']
@@ -220,14 +222,14 @@ module Fastlane
220
222
 
221
223
  if arguments.count == 0
222
224
  f.write(self.createComment(item['comment'], item['text']))
223
- f.write("@objc public static let #{constantName} = localized(identifier: \"#{identifier}\")\n")
225
+ f.write("#{getiOSAttributes(support_objc)}public static let #{constantName} = localized(identifier: \"#{identifier}\")\n")
224
226
  else
225
227
  f.write(self.createComment(item['comment'], item['text']))
226
- f.write(self.createiOSFunction(constantName, identifier, arguments))
228
+ f.write(self.createiOSFunction(constantName, identifier, arguments, support_objc))
227
229
  end
228
230
  }
229
231
  f.write("\n}")
230
- f.write(self.createiOSFileEndString(destinationPath))
232
+ f.write(self.createiOSFileEndString(destinationPath, support_spm))
231
233
  end
232
234
 
233
235
  end
@@ -300,11 +302,7 @@ module Fastlane
300
302
 
301
303
  if !text.include?("one|")
302
304
 
303
- matches = text.scan(/%[0-9][sdf]/)
304
-
305
- matches.each { |match|
306
- text = text.gsub(match, "%#{match[1]}$#{match[2].gsub("s","@")}")
307
- }
305
+ text = text.gsub("$s","$@").gsub("%s","%@")
308
306
 
309
307
  line = "\"#{identifier}\" = \"#{text}\";"
310
308
  if !comment.to_s.empty?
@@ -452,9 +450,9 @@ module Fastlane
452
450
  }
453
451
  end
454
452
 
455
- def self.createiOSFileEndString(destinationPath)
453
+ def self.createiOSFileEndString(destinationPath, support_spm)
456
454
 
457
- bundle = "let bundle = Bundle(for: LocalizationHelper.self)"
455
+ bundle = support_spm ? "let bundle = Bundle.module" : "let bundle = Bundle(for: LocalizationHelper.self)"
458
456
 
459
457
  puts destinationPath
460
458
 
@@ -476,8 +474,8 @@ module Fastlane
476
474
  \n})
477
475
  end
478
476
 
479
- def self.createiOSFunction(constantName, identifier, arguments)
480
- functionTitle = "@objc public static func #{constantName}("
477
+ def self.createiOSFunction(constantName, identifier, arguments, support_objc)
478
+ functionTitle = "#{getiOSAttributes(support_objc)}public static func #{constantName}("
481
479
 
482
480
  arguments.each_with_index do |item, index|
483
481
  functionTitle = functionTitle + "_ arg#{index}: #{item[:type]}"
@@ -500,6 +498,14 @@ module Fastlane
500
498
  return functionTitle
501
499
  end
502
500
 
501
+ def self.getiOSTypeDefinition(support_objc)
502
+ return support_objc ? "public class Localization: NSObject" : "public struct Localization"
503
+ end
504
+
505
+ def self.getiOSAttributes(support_objc)
506
+ return support_objc ? "@objc " : ""
507
+ end
508
+
503
509
  def self.findArgumentsInText(text)
504
510
 
505
511
  if text.include?("one|")
@@ -509,30 +515,40 @@ module Fastlane
509
515
  result = Array.new
510
516
  filtered = self.mapInvalidPlaceholder(text)
511
517
 
512
- stringIndexes = filtered.scan(/%[0-9]?[s@]/)
513
- intIndexes = filtered.scan(/%[0-9]?[d]/)
514
- floatIndexes = filtered.scan(/%[0-9]?[f]/)
515
- doubleIndexes = filtered.scan(/%[0-9]?ld/)
518
+ stringIndexes = self.scan_str(filtered, /%([0-9]+)?\$?[s@]/)
519
+ intIndexes = self.scan_str(filtered, /%([0-9]+)?\$?d/)
520
+ floatIndexes = self.scan_str(filtered, /%([0-9]+)?\$?([0-9]+)?.?([0-9]+)?f/)
521
+ doubleIndexes = self.scan_str(filtered, /%([0-9]+)?\$?([0-9]+)?.?([0-9]+)?ld/)
516
522
 
517
523
  if stringIndexes.count > 0
518
- result = result.concat(stringIndexes.map { |e| { "index": e, "type": "String" }})
524
+ result = result + stringIndexes.map { |e| { "index": e[0], "offset": e[1], "type": "String" }}
519
525
  end
520
526
 
521
527
  if intIndexes.count > 0
522
- result = result.concat(intIndexes.map { |e| { "index": e, "type": "Int" }})
528
+ result = result + intIndexes.map { |e| { "index": e[0], "offset": e[1], "type": "Int" }}
523
529
  end
524
530
 
525
531
  if floatIndexes.count > 0
526
- result = result.concat(floatIndexes.map { |e| { "index": e, "type": "Float" }})
532
+ result = result + floatIndexes.map { |e| { "index": e[0], "offset": e[1], "type": "Float" }}
527
533
  end
528
534
 
529
535
  if doubleIndexes.count > 0
530
- result = result.concat(doubleIndexes.map { |e| { "index": e, "type": "Double" }})
536
+ result = result + doubleIndexes.map { |e| { "index": e[0], "offset": e[1], "type": "Double" }}
531
537
  end
532
538
 
539
+ result = result.sort_by { |hsh| hsh[:offset] }
540
+
533
541
  return result
534
542
  end
535
543
 
544
+ def self.scan_str(str, pattern)
545
+ res = []
546
+ (0..str.length).each do |i|
547
+ res << [Regexp.last_match.to_s, i] if str[i..-1] =~ /^#{pattern}/
548
+ end
549
+ res
550
+ end
551
+
536
552
  def self.mapInvalidPlaceholder(text)
537
553
  filtered = text.gsub('%s', '%@').gsub('"', '\"')
538
554
  return filtered
@@ -580,6 +596,11 @@ module Fastlane
580
596
  default_value: [],
581
597
  optional: true,
582
598
  type: Array),
599
+ FastlaneCore::ConfigItem.new(key: :support_spm,
600
+ env_name: "SUPPORT_SPM",
601
+ description: "Is Swift Package",
602
+ default_value: false,
603
+ type: Boolean),
583
604
  FastlaneCore::ConfigItem.new(key: :language_titles,
584
605
  env_name: "LANGUAGE_TITLES",
585
606
  description: "Alle language titles",
@@ -614,7 +635,12 @@ module Fastlane
614
635
  env_name: "CODEGENERATIONPATH",
615
636
  description: "Code generation path for the Swift file",
616
637
  optional: true,
617
- type: String)
638
+ type: String),
639
+ FastlaneCore::ConfigItem.new(key: :support_objc,
640
+ env_name: "OBJC_SUPPORT",
641
+ description: "Whether the generated code should support Obj-C. Only relevant for the ios platform",
642
+ type: Boolean,
643
+ default_value: false)
618
644
  ]
619
645
  end
620
646
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module GoogleSheetLocalize
3
- VERSION = "0.3.06"
3
+ VERSION = "0.4.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.3.06
4
+ version: 0.4.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-10-07 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive
@@ -181,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
- rubyforge_project:
185
- rubygems_version: 2.7.7
184
+ rubygems_version: 3.0.3
186
185
  signing_key:
187
186
  specification_version: 4
188
187
  summary: Creates .strings files for iOS and strings.xml files for Android