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



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

def self.authors
  ['Automattic']
end

.available_optionsObject



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

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
    ),
  ]
end

.descriptionObject



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

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

.detailsObject



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

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.outputObject



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

def self.output
end

.return_valueObject



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

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
32
33
# 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'

  res_dir = File.join('.', 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?
    git_submodule_update(
      recursive: true,
      init: true
    )
    Action.sh('./gradlew', params[:lint_task])
  end

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