|
| 1 | +module Fastlane |
| 2 | + module Actions |
| 3 | + class IosMergeStringsFilesAction < Action |
| 4 | + def self.run(params) |
| 5 | + UI.message "Merging strings files: #{params[:paths].inspect}" |
| 6 | + |
| 7 | + duplicates = Fastlane::Helper::Ios::L10nHelper.merge_strings(paths: params[:paths], output_path: params[:destination]) |
| 8 | + duplicates.each do |dup_key| |
| 9 | + UI.important "Duplicate key found while merging the `.strings` files: `#{dup_key}`" |
| 10 | + end |
| 11 | + duplicates |
| 12 | + end |
| 13 | + |
| 14 | + ##################################################### |
| 15 | + # @!group Documentation |
| 16 | + ##################################################### |
| 17 | + |
| 18 | + def self.description |
| 19 | + 'Merge multiple `.strings` files into one' |
| 20 | + end |
| 21 | + |
| 22 | + def self.details |
| 23 | + <<~DETAILS |
| 24 | + Merge multiple `.strings` files into one. |
| 25 | +
|
| 26 | + Especially useful to prepare a single `.strings` file merging strings from both `Localizable.strings` from |
| 27 | + the app code — typically previously extracted from `ios_generate_strings_file_from_code` — |
| 28 | + and string files like `InfoPlist.strings` — which values may not be generated from the codebase but |
| 29 | + manually maintained by developers. |
| 30 | +
|
| 31 | + The action only supports merging files which are in the OpenStep (`"key" = "value";`) text format (which is |
| 32 | + the most common format for `.strings` files, and the one generated by `genstrings`), but can handle the case |
| 33 | + of different files using different encodings (UTF8 vs UTF16) and is able to detect and report duplicates. |
| 34 | + It does not handle strings files in XML or binary-plist formats `.strings` files (which are valid but more rare) |
| 35 | + DETAILS |
| 36 | + end |
| 37 | + |
| 38 | + def self.available_options |
| 39 | + [ |
| 40 | + FastlaneCore::ConfigItem.new( |
| 41 | + key: :paths, |
| 42 | + env_name: 'FL_IOS_MERGE_STRINGS_FILES_PATHS', |
| 43 | + description: 'The paths of all the `.strings` files to merge together', |
| 44 | + type: Array, |
| 45 | + optional: false |
| 46 | + ), |
| 47 | + FastlaneCore::ConfigItem.new( |
| 48 | + key: :destination, |
| 49 | + env_name: 'FL_IOS_MERGE_STRINGS_FILES_DESTINATION', |
| 50 | + description: 'The path of the merged `.strings` file to generate. If nil, the merge will happen in-place in the first file in the `paths:` list', |
| 51 | + type: String, |
| 52 | + optional: true, |
| 53 | + default_value: nil |
| 54 | + ), |
| 55 | + ] |
| 56 | + end |
| 57 | + |
| 58 | + def self.return_type |
| 59 | + :array_of_strings |
| 60 | + end |
| 61 | + |
| 62 | + def self.return_value |
| 63 | + 'The list of duplicate keys found while merging the various `.strings` files' |
| 64 | + end |
| 65 | + |
| 66 | + def self.authors |
| 67 | + ['automattic'] |
| 68 | + end |
| 69 | + |
| 70 | + def self.is_supported?(platform) |
| 71 | + platform == :ios |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | +end |
0 commit comments