fastlane-plugin-localize 1.0.0 → 1.1.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: 0726cb96dbd630f57c4ecc02807369c216a0f80e2ec17716164f5d471fd13c49
4
- data.tar.gz: 212e153bf17989f430c6e7835d062888efcbff8940f1f0803607ec5e2f5c5127
3
+ metadata.gz: 44a29020ea890b0cd1af66e88acec9b82365c57e3dfffc3c2947bef6d2ff243b
4
+ data.tar.gz: ed5be6c7cd95fa51aaf26c4f84d3b974ab4e51903984be214302f3d70be965fc
5
5
  SHA512:
6
- metadata.gz: 8b8684e8a92b1ad4b7f07840a4f9ec5c9d8b6e569784f28e7caa513bdb334dad02334455248bedaac6a70a841e7add42a187a9bc4f612eee756d9052d1354fec
7
- data.tar.gz: f4ea442034ac0466824e800d9fed72af35443e1d1263bc50d55b4831b253439773901d02c5b3d04064cc2763298eb56d4bf0543b1d01558c6933e513dcab3b6f
6
+ metadata.gz: 112308493533f28118e0622beac78952c48a65897f637b174e119b3462f9a94ad5d0cb8b17d2d5118a4e47cde633604120a628ac441649e18a5a449525263d12
7
+ data.tar.gz: 44e950b5735531cc135183e5d1321eabce0c42badbed3589618126e2ed38b8a3d0a9ecce517a4199b4a03e127af235f151eaa97b1507f48f797fe5588dec7991
@@ -1,5 +1,5 @@
1
- require 'fastlane/action'
2
- require_relative '../helper/localize_helper'
1
+ require "fastlane/action"
2
+ require_relative "../helper/localize_helper"
3
3
 
4
4
  module Fastlane
5
5
  module Actions
@@ -15,7 +15,6 @@ module Fastlane
15
15
  Helper::LocalizeHelper.stringsFromFile(file)
16
16
  end
17
17
 
18
-
19
18
  matchHash = {}
20
19
 
21
20
  matches.each do |match|
@@ -23,27 +22,29 @@ module Fastlane
23
22
  matchHash[match[0]] << match
24
23
  end
25
24
 
26
-
27
25
  whitelist = Helper::LocalizeHelper.getWhitelist
28
26
 
29
27
  matchHash.keys
30
- .map { |match|
28
+ .map { |match|
31
29
  match.gsub(/^\\"/, "\"").gsub(/\\"$/, "\"")
32
30
  }
33
- .reject { |match|
31
+ .reject { |match|
34
32
  whitelist.include? match
35
33
  }
36
- .each { |match|
37
-
38
- files.flat_map do |file|
39
- Helper::LocalizeHelper.showStringOccurrencesFromFile(file, match)
40
- end
41
-
42
- if UI.confirm "Extract #{match}?"
43
- key = UI.input "Enter key for localization:"
44
- Helper::LocalizeHelper.localize_string(match, key, files, params)
34
+ .each { |match|
35
+ if params[:lint_only]
36
+ puts "warning: #{match} is not localized"
45
37
  else
46
- Helper::LocalizeHelper.addToWhitelist(match)
38
+ files.flat_map do |file|
39
+ Helper::LocalizeHelper.showStringOccurrencesFromFile(file, match)
40
+ end
41
+
42
+ if UI.confirm "Extract #{match}?"
43
+ key = UI.input "Enter key for localization:"
44
+ Helper::LocalizeHelper.localize_string(match, key, files, params)
45
+ else
46
+ Helper::LocalizeHelper.addToWhitelist(match)
47
+ end
47
48
  end
48
49
  }
49
50
  end
@@ -68,35 +69,40 @@ module Fastlane
68
69
  def self.available_options
69
70
  [
70
71
  FastlaneCore::ConfigItem.new(key: :localize_project,
71
- env_name: "FL_LOCALIZE_PROJECT", # The name of the environment variable
72
- description: "The project to localize", # a short description of this parameter
73
- is_string: true, # true: verifies the input is a string, false: every kind of value
74
- default_value: Helper::LocalizeHelper.getProject(nil).path # the default value if the user didn't provide one
75
- ),
76
- FastlaneCore::ConfigItem.new(key: :localize_target,
77
- env_name: "FL_LOCALIZE_TARGET", # The name of the environment variable
78
- description: "The target to localize", # a short description of this parameter
79
- is_string: true, # true: verifies the input is a string, false: every kind of value
80
- default_value: Helper::LocalizeHelper.getTargetName(nil) # the default value if the user didn't provide one
81
- ),
72
+ env_name: "FL_LOCALIZE_PROJECT", # The name of the environment variable
73
+ description: "The project to localize", # a short description of this parameter
74
+ is_string: true, # true: verifies the input is a string, false: every kind of value
75
+ default_value: Helper::LocalizeHelper.getProject(nil).path # the default value if the user didn't provide one
76
+ ),
77
+ FastlaneCore::ConfigItem.new(key: :localize_target,
78
+ env_name: "FL_LOCALIZE_TARGET", # The name of the environment variable
79
+ description: "The target to localize", # a short description of this parameter
80
+ is_string: true, # true: verifies the input is a string, false: every kind of value
81
+ default_value: Helper::LocalizeHelper.getTargetName(nil) # the default value if the user didn't provide one
82
+ ),
82
83
  FastlaneCore::ConfigItem.new(key: :use_swiftgen,
83
84
  env_name: "FL_LOCALIZE_USE_SWIFTGEN", # The name of the environment variable
84
85
  description: "Localize using Swiftgens L10n ", # a short description of this parameter
85
86
  is_string: false, # true: verifies the input is a string, false: every kind of value
86
87
  default_value: false # the default value if the user didn't provide one
87
- ),
88
+ ),
88
89
  FastlaneCore::ConfigItem.new(key: :strings_file,
89
90
  env_name: "FL_LOCALIZE_STRINGS_FILE",
90
91
  description: "The stringsfile to write to",
91
92
  is_string: true, # true: verifies the input is a string, false: every kind of value
92
93
  default_value: "Localizable.strings" # the default value if the user didn't provide one,
93
- ),
94
- FastlaneCore::ConfigItem.new(key: :file_filter,
95
- env_name: "FL_LOCALIZE_FILE_FILTER",
96
- description: "Filter strings for file paths to ignore, separated by commas",
97
- optional: true,
98
- is_string: false
99
- )
94
+ ),
95
+ FastlaneCore::ConfigItem.new(key: :file_filter,
96
+ env_name: "FL_LOCALIZE_FILE_FILTER",
97
+ description: "Filter strings for file paths to ignore, separated by commas",
98
+ optional: true,
99
+ is_string: false),
100
+ FastlaneCore::ConfigItem.new(key: :lint_only,
101
+ env_name: "FL_LOCALIZE_LINT_ONLY", # The name of the environment variable
102
+ description: "Only lint and print warnings for unlocalized strings. ", # a short description of this parameter
103
+ is_string: false, # true: verifies the input is a string, false: every kind of value
104
+ default_value: false # the default value if the user didn't provide one
105
+ ),
100
106
  ]
101
107
  end
102
108
 
@@ -1,4 +1,4 @@
1
- require 'fastlane_core/ui/ui'
1
+ require "fastlane_core/ui/ui"
2
2
 
3
3
  module Fastlane
4
4
  UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
@@ -21,7 +21,7 @@ module Fastlane
21
21
  end
22
22
 
23
23
  if projectPath.nil?
24
- projectPath = Dir.entries('.').select { |f| f.end_with?(".xcodeproj") }.first
24
+ projectPath = Dir.entries(".").select { |f| f.end_with?(".xcodeproj") }.first
25
25
  end
26
26
 
27
27
  if projectPath.nil?
@@ -32,7 +32,6 @@ module Fastlane
32
32
  end
33
33
 
34
34
  def self.getProject(options)
35
-
36
35
  project = Xcodeproj::Project.open(self.getProjectPath(options))
37
36
 
38
37
  project
@@ -69,27 +68,25 @@ module Fastlane
69
68
  target = project.targets.select { |target| target.name.eql? targetName }.first
70
69
 
71
70
  if target.nil?
72
- fail 'no target'
71
+ fail "no target"
73
72
  end
74
73
 
75
74
  target
76
75
  end
77
76
 
78
77
  def self.codeFiles(target, options)
78
+ if options[:file_filter].nil?
79
+ filter = []
80
+ else
81
+ filter = (options[:file_filter]).split(",")
82
+ end
79
83
 
80
- if options[:file_filter].nil?
81
- filter = []
82
- else
83
- filter = ( options[:file_filter]).split(",")
84
- end
85
-
86
-
87
- codeFiles = target.source_build_phase.files.to_a.map do |pbx_build_file|
88
- pbx_build_file.file_ref.real_path.to_s
84
+ codeFiles = target.source_build_phase.files.to_a.map do |pbx_build_file|
85
+ pbx_build_file.file_ref.real_path.to_s
89
86
  end.select do |path|
90
- path.end_with?(".swift")
87
+ path.end_with?(".swift")
91
88
  end.select do |path|
92
- bool = true
89
+ bool = true
93
90
 
94
91
  filter.each { |filter|
95
92
  if path.include? filter
@@ -99,28 +96,24 @@ module Fastlane
99
96
 
100
97
  next bool
101
98
  end.select do |path|
102
- File.exists?(path)
103
- end
99
+ File.exists?(path)
100
+ end
104
101
 
105
102
  codeFiles
106
103
  end
107
104
 
108
105
  def self.stringsFromFile(file)
109
-
110
106
  strings = File.readlines(file).to_s.enum_for(:scan,
111
- /(?<!\#imageLiteral\(resourceName:|\#imageLiteral\(resourceName: |NSLocalizedString\()\\"[^\\"\r\n]*\\"/
112
- ).flat_map {Regexp.last_match}
107
+ /(?<!\#imageLiteral\(resourceName:|\#imageLiteral\(resourceName: |NSLocalizedString\()\\"[^\\"\r\n]*\\"/).flat_map { Regexp.last_match }
113
108
  return strings
114
109
  end
115
110
 
116
111
  def self.showStringOccurrencesFromFile(file, string)
117
-
118
112
  line_array = File.readlines(file)
119
113
 
120
114
  File.open(file).each_with_index { |line, index|
121
115
  if line =~ /(?<!\#imageLiteral\(resourceName:|\#imageLiteral\(resourceName: |NSLocalizedString\()#{Regexp.escape(string)}/
122
- then
123
- hits = line_array[index-2 .. index-1] + [line_array[index].green] + line_array[index+1 .. index+2]
116
+ hits = line_array[index - 2..index - 1] + [line_array[index].green] + line_array[index + 1..index + 2]
124
117
  UI.message "In file #{file} (line #{index}): \n\n#{hits.join()}"
125
118
  end
126
119
  }
@@ -131,8 +124,8 @@ module Fastlane
131
124
  end
132
125
 
133
126
  def self.addToWhitelist(string)
134
- open(whitelistFilename, 'a') { |f|
135
- f.puts string
127
+ open(whitelistFilename, "a") { |f|
128
+ f.puts string
136
129
  }
137
130
  UI.message "Added \"#{string}\" to #{whitelistFilename}"
138
131
  end
@@ -146,15 +139,15 @@ module Fastlane
146
139
  end
147
140
 
148
141
  def self.localize_string(string, key, files, params)
149
- open(params[:strings_file], 'a') { |f|
150
- f.puts "\"#{key}\" = #{string};"
142
+ open(params[:strings_file], "a") { |f|
143
+ f.puts "\"#{key}\" = #{string};"
151
144
  }
152
145
  files.each do |file_name|
153
146
  text = File.read(file_name)
154
147
 
155
148
  new_contents = text.gsub(string, replacementString(key, params))
156
149
 
157
- File.open(file_name, "w") {|file| file.puts new_contents }
150
+ File.open(file_name, "w") { |file| file.puts new_contents }
158
151
  end
159
152
 
160
153
  UI.message "Replaced \"#{string}\" with \"#{replacementString(key, params)}\""
@@ -162,7 +155,14 @@ module Fastlane
162
155
 
163
156
  def self.replacementString(key, params)
164
157
  if params[:use_swiftgen]
165
- return "L10n.#{key.gsub("." , "_").split("_").inject { |m, p| m + p.capitalize }}"
158
+ swiftgenKey = key.gsub(".", "_").split("_").inject { |m, p|
159
+ letters = p.split("")
160
+ letters.first.upcase!
161
+ p2 = letters.join
162
+ m + p2
163
+ }
164
+
165
+ return "L10n.#{swiftgenKey}"
166
166
  else
167
167
  return "NSLocalizedString(\"#{key}\")"
168
168
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Localize
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -1,10 +1,10 @@
1
- require 'fastlane/plugin/localize/version'
1
+ require "fastlane/plugin/localize/version"
2
2
 
3
3
  module Fastlane
4
4
  module Localize
5
5
  # Return all .rb files inside the "actions" and "helper" directory
6
6
  def self.all_classes
7
- Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
7
+ Dir[File.expand_path("**/{actions,helper}/*.rb", File.dirname(__FILE__))]
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wolfgang Lutz