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
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
77 78 79 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 77 def self. ["alexander sun"] end |
.available_options ⇒ Object
90 91 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/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 90 def self. [ # FastlaneCore::ConfigItem.new(key: :your_option, # env_name: "XLIFF_EN_GEN_YOUR_OPTION", # description: "A description of your option", # optional: false, # type: String) 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 use the path to the project") 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 path to replace", 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) ] end |
.description ⇒ Object
73 74 75 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 73 def self.description "gen Localizable.strings file from xliff" end |
.details ⇒ Object
85 86 87 88 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 85 def self.details # Optional: "generate new Localizable.strings file based on export en.xliff" end |
.is_supported?(platform) ⇒ Boolean
117 118 119 120 121 122 123 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 117 def self.is_supported?(platform) # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md # [:ios, :mac].include?(platform) true end |
.return_value ⇒ Object
81 82 83 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 81 def self.return_value # If your method provides a return value, you can describe here what it does end |
.run(params) ⇒ Object
4 5 6 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 |
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 4 def self.run(params) require 'nokogiri' projectPath = File.absolute_path(params[:xcodeproj]) 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") doc = Nokogiri::XML(File.open(xliffPath)) doc.remove_namespaces! UI.("Found: "+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 FileUtils.rm xliffPath, :force => true end |