Class: Fastlane::Actions::IosMergeStringsFilesAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



72
73
74
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 72

def self.authors
  ['Automattic']
end

.available_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 45

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :paths_to_merge,
      env_name: 'FL_IOS_MERGE_STRINGS_FILES_PATHS_TO_MERGE',
      description: 'A hash of the paths of all the `.strings` files to merge into the `destination`, with the prefix to be used for their keys as associated value',
      type: Hash,
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :destination,
      env_name: 'FL_IOS_MERGE_STRINGS_FILES_DESTINATION',
      description: 'The path of the `.strings` file to merge the other ones into',
      type: String,
      optional: false
    ),
  ]
end

.descriptionObject



26
27
28
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 26

def self.description
  'Merge multiple `.strings` files into one'
end

.detailsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 30

def self.details
  "    Merge multiple `.strings` files into another one.\n\n    Especially useful to prepare a single `.strings` file merging string files like `InfoPlist.strings` \u2014 whose\n    content are typically manually maintained by developers \u2014 within the main `Localizable.strings` file \u2014 which\n    would have typically been previously generated from the codebase via `ios_generate_strings_file_from_code`.\n\n    The action only supports merging files which are in the OpenStep (`\"key\" = \"value\";`) text format (which is\n    the most common format for `.strings` files, and the one generated by `genstrings`), but can handle the case\n    of different files using different encodings (UTF8 vs UTF16) and is able to detect and report duplicates.\n    It does not handle `.strings` files in XML or binary-plist formats (which are valid but more rare)\n  DETAILS\nend\n"

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 76

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

.return_typeObject



64
65
66
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 64

def self.return_type
  :array_of_strings
end

.return_valueObject



68
69
70
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 68

def self.return_value
  'The list of duplicate keys (after prefix has been added to each) found while merging the various `.strings` files'
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 6

def self.run(params)
  destination = params[:destination]
  # Include the destination as the first of the files (without key prefixes) to be included in the merged result
  all_paths_list = { destination => nil }.merge(params[:paths_to_merge])

  UI.message "Merging strings files #{all_paths_list.inspect}"

  File.write(destination, '') unless File.exist?(destination) # Create empty destination file if it does not exist yet
  duplicates = Fastlane::Helper::Ios::L10nHelper.merge_strings(paths: all_paths_list, output_path: params[:destination])
  duplicates.each do |dup_key|
    UI.important "Duplicate key found while merging the `.strings` files: `#{dup_key}`"
  end
  UI.important 'Tip: To avoid those key conflicts, you might want to consider providing different prefixes in the `Hash` you used for the `paths:` parameter.' unless duplicates.empty?
  duplicates
end