Class: Fastlane::Actions::XliffEnGenAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::XliffEnGenAction
- Defined in:
- lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
-
.output ⇒ Object
If your method provides a return value, you can describe here what it does.
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
90 91 92 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 90 def self. ["alexander sun"] end |
.available_options ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 108 def self. [ FastlaneCore::ConfigItem.new(key: :xcodeproj, env_name: "XLIFF_EN_GEN_PROJECT", description: "Specify the path to your main Xcode project", optional: false, type: String, verify_block: proc do |value| UI.user_error!("Please specify your project file path") if !value.end_with? ".xcodeproj" UI.user_error!("Could not find Xcode project at path '#{File.(value)}'") if !File.exist?(value) and !Helper.is_test? end), FastlaneCore::ConfigItem.new(key: :localizable, env_name: "XLIFF_EN_GEN_LOCALIZABLE_PATH", description: "localizable.strings path to be replaced", optional: false, type: String, verify_block: proc do |value| UI.user_error!("Could not find Localizable.strings project at path '#{File.(value)}'") if !File.exist?(value) and !Helper.is_test? end), FastlaneCore::ConfigItem.new(key: :keepArtifacts, env_name: "XLIFF_EN_GEN_KEEP_ARTIFACTS", description: "whether keep the en.xliff file for your use", optional: true, default_value: false, type: TrueClass) ] end |
.description ⇒ Object
86 87 88 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 86 def self.description "Overwrite project Localizable.strings file from English version xliff" end |
.details ⇒ Object
103 104 105 106 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 103 def self.details "Generate new Localizable.strings file based on the exported en.xliff by using xcode build, and over write the file based on the en.xliff.\n This will include nokogiri to parse xml. lane context XE_XLIFF_LOCATION will be used for store location of the en.xliff" end |
.is_supported?(platform) ⇒ Boolean
136 137 138 139 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 136 def self.is_supported?(platform) [:ios, :mac].include?(platform) true end |
.output ⇒ Object
If your method provides a return value, you can describe here what it does
97 98 99 100 101 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 97 def self.output [ ['XE_XLIFF_LOCATION', 'Path to en.xliff'] ] end |
.return_value ⇒ Object
94 95 96 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 94 def self.return_value # If your method provides a return value, you can describe here what it does end |
.run(params) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 7 def self.run(params) require 'nokogiri' projectPath = File.absolute_path(params[:xcodeproj]) UI.("Located project at: "+projectPath) workingPath = File.dirname(projectPath) dir = File.dirname(projectPath) file = File.basename(projectPath) sh ("cd #{dir} && xcodebuild -exportLocalizations -localizationPath #{workingPath} -project #{file} -exportLanguage en") xliffPath = File.join(workingPath, "en.xliff") Actions.lane_context[SharedValues::XE_XLIFF_LOCATION] = xliffPath doc = Nokogiri::XML(File.open(xliffPath)) doc.remove_namespaces! UI.("Found total: "+doc.xpath("count(//file[@original='uan/en.lproj/Localizable.strings']/body/trans-unit)").to_s()+" translation unit") transUnits = doc.xpath("//file[contains(@original,'Localizable.strings')]/body/trans-unit") translations = Array.new transUnits.each do |unit| transId = unit['id'] target = unit.at_xpath("target/text()") note = unit.at_xpath("note/text()") if note == nil note = "(No Commment)" end info = { "id" => transId, "English" => target, "note" => note } translations << info end translations.sort! {|x,y| x['id'] <=> y ['id']} File.open("Localizable.strings", "w"){ |f| translations.each do |transInfo| f.write ('/* ' + transInfo['note'] + ' */' + "\n") f.write ('"' + transInfo['id'] + '"' + "=" '"' + transInfo['English'] + '";' + "\n") f.write ("\n") end } localizablePath = params[:localizable] FileUtils.mv 'Localizable.strings', localizablePath, :force => true UI.("Localizable moved to: "+localizablePath) keepFile = params[:keepArtifacts] if not keepFile FileUtils.rm xliffPath, :force => true end end |