class Xcodeproj::Project
Public Class Methods
find(path)
click to toggle source
# File lib/smartling_xcode/xcode.rb, line 7 def self.find(path) # Get .xcodeproj path if path.nil? path = './' end if File.exist?(path) if !path.end_with?(".xcodeproj") project_file = Dir.entries(path).select {|f| f.end_with?(".xcodeproj") }.first path = "#{path}/#{project_file}".gsub("//", "/") end puts "Using project #{path}" # Open project begin return Xcodeproj::Project.open(path) rescue Kernel.abort("⚠️ Failed to open project file") end else Kernel.abort("⚠️ No .xcodeproj file found") end end
fromBase(path)
click to toggle source
Returns true if the file is from Base localization or unlocalized
# File lib/smartling_xcode/xcode.rb, line 33 def self.fromBase(path) if path.include?('.lproj') return path.include?('Base.lproj') else return true end end
Public Instance Methods
extract()
click to toggle source
# File lib/smartling_xcode/xcode.rb, line 41 def extract strings_files = [] # Loop on IB files from Base localization self.files.select{|f| f.path.end_with?(".xib", ".storyboard") && Project.fromBase(f.path) }.each do |f| output_name = f.path.gsub(/[\/\.]/, '_') output_path = "/tmp/#{output_name}.strings" puts "Extracting strings from #{f.path} into #{output_path}" Kernel.system("ibtool --generate-strings-file \"#{output_path}\" \"#{f.real_path}\"") strings_files.push(output_path) end # Loop on .strings and .stringsdict files self.files.select{|f| Project.fromBase(f.path) && f.path.end_with?(".strings", ".stringsdict") }.each do |f| strings_files.push(f.real_path) end return strings_files end
getVersion()
click to toggle source
# File lib/smartling_xcode/xcode.rb, line 65 def getVersion puts "Looking for an app version number to use for the strings files upload..." versions = [] self.files.select{|f| f.path.end_with?(".plist")}.each do |f| contents = Xcodeproj::Plist.read_from_path(f.real_path) if contents['CFBundleShortVersionString'] versions.push({:version => contents['CFBundleShortVersionString'], :file => f.hierarchy_path}) end end case versions.count when 0 puts "No app version found in project.\nPlease enter a version number:" version = STDIN.gets.chomp return version when 1 file = versions.first version = file[:version] puts "Using #{version} found in #{file[:file]}" return version else puts "Multiple Info.plist files found. Please select which version number to use:" versions.each_with_index do |v, i| puts "#{i}. #{v[:version]} from #{v[:file]}" end puts "Selection: " choice = nil while choice.nil? choice = STDIN.gets.chomp.to_i if choice < versions.count return versions[choice][:version] end choice = nil end end end