Class: Fastlane::Actions::AndroidDownloadTranslationsAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



108
109
110
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 108

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 45

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :res_dir,
      env_name: 'FL_DOWNLOAD_TRANSLATIONS_RES_DIR',
      description: "The path to the Android project's `res` dir (typically the `<project name>/src/main/res` directory) containing the `values-*` subdirs",
      type: String,
      default_value: "#{ENV['PROJECT_NAME']}/src/main/res"
    ),
    FastlaneCore::ConfigItem.new(
      key: :glotpress_url,
      env_name: 'FL_DOWNLOAD_TRANSLATIONS_GLOTPRESS_URL',
      description: 'URL to the GlotPress project',
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :status_filter,
      env_name: 'FL_DOWNLOAD_TRANSLATIONS_STATUS_FILTER',
      description: 'The GlotPress status(es) to filter on when downloading the translations',
      type: Array,
      default_value: 'current'
    ),
    FastlaneCore::ConfigItem.new(
      key: :source_locale,
      env_name: 'FL_DOWNLOAD_TRANSLATIONS_SOURCE_LOCALE',
      description: 'The Android locale code for the source locale (the one serving as original/reference). This will be included into the `available_languages.xml` file',
      type: String,
      default_value: 'en_US'
    ),
    FastlaneCore::ConfigItem.new(
      key: :locales,
      description: 'An array of hashes – each with the :glotpress and :android keys – listing the locale codes to download and update',
      type: Array,
      verify_block: proc do |value|
        unless value.is_a?(Array) && value.all? { |e| e.is_a?(Hash) && e.key?(:glotpress) && e.key?(:android) }
          UI.user_error!('The value for the `locales` parameter must be an Array of Hashes, and each Hash must have at least `:glotpress` and `:android` keys.')
        end
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :lint_task,
      env_name: 'FL_DOWNLOAD_TRANSLATIONS_LINT_TASK',
      description: 'The name of the Gradle task to run to lint the translations (after this action have updated them). Set to nil or empty string to skip the lint',
      type: String,
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :skip_commit,
      env_name: 'FL_DOWNLOAD_TRANSLATIONS_SKIP_COMMIT',
      description: 'If set to true, will skip the commit step',
      type: Boolean,
      default_value: false
    ),
    Fastlane::Helper::Deprecated.project_root_folder_config_item,
  ]
end

.descriptionObject



37
38
39
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 37

def self.description
  'Download Android string.xml files from GlotPress and lint the updated translations'
end

.detailsObject



41
42
43
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 41

def self.details
  'Download translations from GlotPress, update local strings.xml files accordingly, lint, commit the changes'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 112

def self.is_supported?(platform)
  platform == :android
end

.outputObject



102
103
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 102

def self.output
end

.return_valueObject



105
106
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 105

def self.return_value
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb', line 6

def self.run(params)
  require_relative '../../helper/android/android_localize_helper'
  require_relative '../../helper/git_helper'

  project_root_folder = params[:project_root_folder]
  res_dir = File.join(project_root_folder || '.', params[:res_dir])

  Fastlane::Helper::Android::LocalizeHelper.create_available_languages_file(
    res_dir: res_dir,
    locale_codes: [params[:source_locale]] + params[:locales].map { |h| h[:android] }
  )
  Fastlane::Helper::Android::LocalizeHelper.download_from_glotpress(
    res_dir: res_dir,
    glotpress_project_url: params[:glotpress_url],
    glotpress_filters: params[:status_filter].map { |s| { status: s } },
    locales_map: params[:locales]
  )

  # Update submodules then lint translations
  unless params[:lint_task].nil? || params[:lint_task].empty?
    Fastlane::Helper::GitHelper.update_submodules
    Action.sh('./gradlew', params[:lint_task])
  end

  Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: res_dir) unless params[:skip_commit]
end