class Fastlane::Helper::LocalizeHelper
Public Class Methods
addToWhitelist(string)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 133 def self.addToWhitelist(string) open(whitelistFilename, 'a') { |f| f.puts string } UI.message "Added \"#{string}\" to #{whitelistFilename}" end
codeFiles(target, options)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 78 def self.codeFiles(target, options) if options[:file_filter].nil? filter = [] else filter = ( options[:file_filter]).split(",") end codeFiles = target.source_build_phase.files.to_a.map do |pbx_build_file| pbx_build_file.file_ref.real_path.to_s end.select do |path| path.end_with?(".swift") end.select do |path| bool = true filter.each { |filter| if path.include? filter bool = false end } next bool end.select do |path| File.exists?(path) end codeFiles end
getProject(options)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 34 def self.getProject(options) project = Xcodeproj::Project.open(self.getProjectPath(options)) project end
getProjectPath(options)
click to toggle source
class methods that you define here become available in your action as `Helper::LocalizeHelper.your_method`
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 12 def self.getProjectPath(options) projectPath = nil unless options.nil? projectPath = options[:localize_project] end if projectPath.nil? projectPath = ENV["PROJECT_FILE_PATH"] end if projectPath.nil? projectPath = Dir.entries('.').select { |f| f.end_with?(".xcodeproj") }.first end if projectPath.nil? fail "no xcodeproject found" end projectPath end
getTarget(options)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 65 def self.getTarget(options) project = self.getProject(options) targetName = self.getTargetName(options) target = project.targets.select { |target| target.name.eql? targetName }.first if target.nil? fail 'no target' end target end
getTargetName(options)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 41 def self.getTargetName(options) project = self.getProject(options) targetName = nil unless options.nil? targetName = options[:localize_target] end if targetName.nil? targetName = ENV["TARGET_NAME"] end if targetName.nil? targetName = project.targets.map { |target| target.name.to_s }.first end if targetName.nil? fail "no target found" end targetName end
getWhitelist()
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 140 def self.getWhitelist if File.exist?(whitelistFilename) return File.readlines(whitelistFilename).map(&:strip).map { |s| s.gsub(/^\\"/, "\"").gsub(/\\"$/, "\"") } else return [] end end
localize_string(string, key, files, params)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 148 def self.localize_string(string, key, files, params) open(params[:strings_file], 'a') { |f| f.puts "\"#{key}\" = #{string};" } files.each do |file_name| text = File.read(file_name) new_contents = text.gsub(string, replacementString(key, params)) File.open(file_name, "w") {|file| file.puts new_contents } end UI.message "Replaced \"#{string}\" with \"#{replacementString(key, params)}\"" end
replacementString(key, params)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 163 def self.replacementString(key, params) if params[:use_swiftgen] return "L10n.#{key.gsub("." , "_").split("_").inject { |m, p| m + p.capitalize }}" else return "NSLocalizedString(\"#{key}\")" end end
showStringOccurrencesFromFile(file, string)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 116 def self.showStringOccurrencesFromFile(file, string) line_array = File.readlines(file) File.open(file).each_with_index { |line, index| if line =~ /(?<!\#imageLiteral\(resourceName:|\#imageLiteral\(resourceName: |NSLocalizedString\()#{string}/ then hits = line_array[index-2 .. index-1] + [line_array[index].green] + line_array[index+1 .. index+2] UI.message "In file #{file} (line #{index}): \n\n#{hits.join()}" end } end
stringsFromFile(file)
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 108 def self.stringsFromFile(file) strings = File.readlines(file).to_s.enum_for(:scan, /(?<!\#imageLiteral\(resourceName:|\#imageLiteral\(resourceName: |NSLocalizedString\()\\"[^\\"\r\n]*\\"/ ).flat_map {Regexp.last_match} return strings end
whitelistFilename()
click to toggle source
# File lib/fastlane/plugin/localize/helper/localize_helper.rb, line 129 def self.whitelistFilename "fastlane/.fastlane_localization_whitelist" end