Class: Applyrics::Project_iOS
- Inherits:
-
Object
- Object
- Applyrics::Project_iOS
- Defined in:
- lib/applyrics/project_ios.rb
Instance Method Summary collapse
-
#detected_languages ⇒ Object
Return a list of detected languages in the project.
-
#initialize(path) ⇒ Project_iOS
constructor
A new instance of Project_iOS.
- #platform_project_settings(name) ⇒ Object
- #rebuild_files ⇒ Object
Constructor Details
#initialize(path) ⇒ Project_iOS
Returns a new instance of Project_iOS.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/applyrics/project_ios.rb', line 9 def initialize(path) if path.to_s.length == 0 path = Dir["./*.xcworkspace"].first end if path.to_s.length == 0 path = Dir["./*.xcodeproj"].first end @path = path @platform_settings = nil @langs = {} end |
Instance Method Details
#detected_languages ⇒ Object
Return a list of detected languages in the project
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/applyrics/project_ios.rb', line 22 def detected_languages folder = self.platform_project_settings("SOURCE_ROOT") base_language = I18nData.language_code(self.platform_project_settings("DEVELOPMENT_LANGUAGE")).downcase lang_folders = Dir.glob(File.join(folder, "**", "*.lproj")) lang_folders.each do |lang_folder| lang = /([A-Za-z\-]*?)\.lproj/.match(lang_folder)[1] lang = (lang == "Base" ? base_language : lang) @langs[lang] = lang_folder end return @langs end |
#platform_project_settings(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/applyrics/project_ios.rb', line 34 def platform_project_settings(name) if @platform_settings.nil? cmd = ["set -o pipefail && xcrun xcodebuild -showBuildSettings"] cmd << "-project '#{@path}'" @platform_settings = Command.execute(cmd, false) end result = @platform_settings.split("\n").find { |c| c.split(" = ").first.strip == name } return result.split(" = ").last end |
#rebuild_files ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/applyrics/project_ios.rb', line 45 def rebuild_files folder = self.platform_project_settings("SOURCE_ROOT") tmp_folder = "./.tmp/" if !Dir.exist?(tmp_folder) Dir.mkdir(tmp_folder, 0700) end GenStrings.run("#{folder}", tmp_folder) IBTool.run("#{folder}", tmp_folder) out = {} Dir[File.join(tmp_folder, "*.strings")].each do |file| puts file strings = StringsFile.new(file) out[File.basename(file)] = strings.hash end File.open(File.join("./", "strings.json"), 'w') { |file| file.write(MultiJson.dump(out, :pretty => true)) } end |