Class: Fastlane::Actions::XliffEnGenAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



77
78
79
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 77

def self.authors
  ["alexander sun"]
end

.available_optionsObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 95

def self.available_options
  [
    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.expand_path(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.expand_path(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

.descriptionObject



73
74
75
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 73

def self.description
  "Overwrite project Localizable.strings file from English version xliff"
end

.detailsObject



90
91
92
93
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 90

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

Returns:

  • (Boolean)


123
124
125
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 123

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.outputObject

If your method provides a return value, you can describe here what it does



84
85
86
87
88
# File 'lib/fastlane/plugin/xliff_en_gen/actions/xliff_en_gen_action.rb', line 84

def self.output
  [
    
  ]
end

.return_valueObject



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])
  
  UI.message("Located project at: "+projectPath)

  xliffPath = other_action.export_xliff(xcodeproj:projectPath)

  doc = Nokogiri::XML(File.open(xliffPath))

  doc.remove_namespaces!

  UI.message("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.message("Localizable moved to: "+localizablePath)

  keepFile = params[:keepArtifacts]
  
  if not keepFile
    FileUtils.rm xliffPath, :force => true
  end 

end