class Fastlane::Actions::LocalizeAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 55
def self.authors
  ["Wolfgang Lutz"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 68
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :localize_project,
                               env_name: "FL_LOCALIZE_PROJECT", # The name of the environment variable
                               description: "The project to localize", # a short description of this parameter
                               is_string: true, # true: verifies the input is a string, false: every kind of value
                               default_value: Helper::LocalizeHelper.getProject(nil).path # the default value if the user didn't provide one
                             ),
   FastlaneCore::ConfigItem.new(key: :localize_target,
                              env_name: "FL_LOCALIZE_TARGET", # The name of the environment variable
                              description: "The target to localize", # a short description of this parameter
                              is_string: true, # true: verifies the input is a string, false: every kind of value
                              default_value: Helper::LocalizeHelper.getTargetName(nil) # the default value if the user didn't provide one
                            ),
    FastlaneCore::ConfigItem.new(key: :use_swiftgen,
                                 env_name: "FL_LOCALIZE_USE_SWIFTGEN", # The name of the environment variable
                                 description: "Localize using Swiftgens L10n ", # a short description of this parameter
                                 is_string: false, # true: verifies the input is a string, false: every kind of value
                                 default_value: false # the default value if the user didn't provide one
                                ),
    FastlaneCore::ConfigItem.new(key: :strings_file,
                                 env_name: "FL_LOCALIZE_STRINGS_FILE",
                                 description: "The stringsfile to write to",
                                 is_string: true, # true: verifies the input is a string, false: every kind of value
                                 default_value: "Localizable.strings" # the default value if the user didn't provide one,
                               ),
     FastlaneCore::ConfigItem.new(key: :file_filter,
                                   env_name: "FL_LOCALIZE_FILE_FILTER",
                                   description: "Filter strings for file paths to ignore, separated by commas",
                                   optional: true,
                                   is_string: false
                                 )
  ]
end
description() click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 51
def self.description
  "Searches the code for extractable strings and allows interactive extraction to .strings file."
end
details() click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 62
def self.details
  "Searches the code for extractable strings and allows interactive extraction to .strings file:"
  "- Whitelists non-extracted strings"
  "- Support for NSLocalizedString and Swiftgen"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 103
def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
  true
end
return_value() click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 59
def self.return_value
end
run(params) click to toggle source
# File lib/fastlane/plugin/localize/actions/localize_action.rb, line 7
def self.run(params)
  project = Helper::LocalizeHelper.getProject(params)

  target = Helper::LocalizeHelper.getTarget(params)

  files = Helper::LocalizeHelper.codeFiles(target, params)

  matches = files.flat_map do |file|
    Helper::LocalizeHelper.stringsFromFile(file)
  end


  matchHash = {}

  matches.each do |match|
    matchHash[match[0]] = [] unless matchHash[match[0]] != nil
    matchHash[match[0]] << match
  end


  whitelist = Helper::LocalizeHelper.getWhitelist

  matchHash.keys
  .map { |match|
    match.gsub(/^\\"/, "\"").gsub(/\\"$/, "\"")
  }
  .reject { |match|
    whitelist.include? match
  }
  .each { |match|

    files.flat_map do |file|
      Helper::LocalizeHelper.showStringOccurrencesFromFile(file, match)
    end

    if UI.confirm "Extract #{match}?"
      key = UI.input "Enter key for localization:"
      Helper::LocalizeHelper.localize_string(match, key, files, params)
    else
      Helper::LocalizeHelper.addToWhitelist(match)
    end
  }
end