Class: Applyrics::Project_iOS
- Inherits:
-
Object
- Object
- Applyrics::Project_iOS
- Defined in:
- lib/applyrics/project_ios.rb
Instance Method Summary collapse
- #apply_languages(data) ⇒ Object
- #default_language ⇒ Object
-
#detected_languages ⇒ Object
Return a list of detected languages in the project.
-
#initialize(path) ⇒ Project_iOS
constructor
A new instance of Project_iOS.
- #language_files ⇒ Object
- #platform_project_settings(name) ⇒ Object
-
#rebuild_files ⇒ Object
NOTE: This will only rebuild the base language.
- #string_files(folder = nil) ⇒ Object
Constructor Details
#initialize(path) ⇒ Project_iOS
Returns a new instance of Project_iOS.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/applyrics/project_ios.rb', line 10 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 = [] @default_language = nil end |
Instance Method Details
#apply_languages(data) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/applyrics/project_ios.rb', line 117 def apply_languages(data) folder = self.platform_project_settings("SOURCE_ROOT") data.each do |lang, files| files.each do |file, data| lang_folder = Dir[File.join(folder, "**", (lang == default_language ? "Base" : lang) + ".lproj")].first if !Dir.exist?(lang_folder) Dir.mkdir(lang_folder, 0700) puts "Created #{lang_folder}".yellow end strings = StringsFile.new(File.join(lang_folder, file), data) strings.write end end end |
#default_language ⇒ Object
53 54 55 56 57 58 |
# File 'lib/applyrics/project_ios.rb', line 53 def default_language if @default_language.nil? @default_language = I18nData.language_code(self.platform_project_settings("DEVELOPMENT_LANGUAGE")).downcase end @default_language end |
#detected_languages ⇒ Object
Return a list of detected languages in the project
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/applyrics/project_ios.rb', line 24 def detected_languages @langs = [] folder = self.platform_project_settings("SOURCE_ROOT") 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" ? default_language : lang) @langs << lang end return @langs end |
#language_files ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/applyrics/project_ios.rb', line 36 def language_files folder = self.platform_project_settings("SOURCE_ROOT") unless !folder.nil? out = {} Dir[File.join(folder, "**", "*.lproj", "*.strings")].each do |file| lang = /(\w*).lproj/.match(file)[1] lang = (lang == "Base" ? default_language : lang) if !out.key?(lang) out[lang] = [] end out[lang] << file end out end |
#platform_project_settings(name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/applyrics/project_ios.rb', line 60 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
NOTE: This will only rebuild the base language
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/applyrics/project_ios.rb', line 92 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) lang = default_language out = {"#{lang}" => {}} langHash = out["#{lang}"] Dir[File.join(tmp_folder, "*.strings")].each do |file| strings = StringsFile.new(file) langHash[File.basename(file)] = strings.to_hash end FileUtils.remove_dir(tmp_folder) out end |
#string_files(folder = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/applyrics/project_ios.rb', line 71 def string_files(folder=nil) folder = self.platform_project_settings("SOURCE_ROOT") unless !folder.nil? out = {} Dir[File.join(folder, "**", "*.lproj", "*.strings")].each do |file| strings = StringsFile.new(file) lang = /(\w*).lproj/.match(file)[1] lang = (lang == "Base" ? default_language : lang) if !out.key?(lang) out[lang] = {} end out[lang][File.basename(file)] = strings.to_hash end out end |