Class: Fastlane::Actions::CheckTranslationProgressAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



138
139
140
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 138

def self.authors
  ['Automattic']
end

.available_optionsObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 104

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :glotpress_url,
                                 env_name: 'FL_CHECK_TRANSLATION_PROGRESS_GLOTPRESS_URL',
                                 description: 'URL to the GlotPress project',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :language_codes,
                                 env_name: 'FL_CHECK_TRANSLATION_PROGRESS_LANGUAGE_CODES',
                                 description: 'The list of the codes of the languages to check',
                                 type: Array,
                                 optional: true,
                                 # Default to Mag16.
                                 default_value: 'ar de es fr he id it ja ko nl pt-br ru sv tr zh-cn zh-tw'.split),
    FastlaneCore::ConfigItem.new(key: :min_acceptable_translation_percentage,
                                 env_name: 'FL_CHECK_TRANSLATION_PROGRESS_MIN_ACCEPTABLE_TRANSLATION_PERCENTAGE',
                                 description: 'The threshold under which an error is raised',
                                 type: Integer,
                                 optional: true,
                                 default_value: 100),
    FastlaneCore::ConfigItem.new(key: :abort_on_violations,
                                 env_name: 'FL_CHECK_TRANSLATION_ABORT_ON_VIOLATIONS',
                                 description: 'Should we abort with a global error if any violations are found?',
                                 optional: true,
                                 default_value: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :skip_confirm,
                                 env_name: 'FL_CHECK_TRANSLATION_SKIP_CONFIRM',
                                 description: 'Move ahead without requesting confirmation if violations are found. Only works if "abort_on_violations" is disabled',
                                 optional: true,
                                 default_value: false,
                                 type: Boolean),
  ]
end

.check_results(under_threshold_langs:, threshold:, skip_confirm:) ⇒ Object

Report the status of the translations and verify whether to abort or not

Parameters:

  • The (Array)

    list of violations (array of hashes of “language code” and “current percentage”)

  • The (Integer)

    minimum acceptable percentage of translated strings.

  • If (Bool)

    true, continue after the report without asking the user.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 75

def self.check_results(under_threshold_langs:, threshold:, skip_confirm:)
  message = "The translations for the following languages are below the #{threshold}% threshold:\n"

  under_threshold_langs.each do |lang|
    message << " - #{lang[:lang]} is at #{lang[:progress]}%.\n"
  end

  if skip_confirm
    UI.important(message)
  elsif UI.interactive?
    UI.abort_with_message!('Aborted by user!') unless UI.confirm("#{message}Do you want to continue?")
  else
    UI.abort_with_message!(message)
  end
end

.check_translations(glotpress_url:, language_codes:, abort_on_violations:, threshold:) ⇒ Array

Check the status of the translations and returns the list of violations

Parameters:

  • URL (String)

    to the GlotPress project.

  • The (String)

    list of codes (in GlotPress format) of the languages to check.

  • Whether (Bool)

    to abort on the first found violation or not.

  • The (Integer)

    minimum acceptable percentage of translated strings.

Returns:

  • (Array)

    The list of violations (array of hashes of “language code” and “current percentage”)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 36

def self.check_translations(glotpress_url:, language_codes:, abort_on_violations:, threshold:)
  under_threshold_langs = []

  data = begin
    Fastlane::Helper::GlotPressHelper.get_translation_status_data(glotpress_url: glotpress_url)
  rescue StandardError
    nil
  end
  UI.abort_with_message!("Can't retrieve data from #{glotpress_url}") if data.nil? || data.empty?

  language_codes.each do |language_code|
    UI.message("> Getting translation status for #{language_code}")
    progress = begin
      Fastlane::Helper::GlotPressHelper.get_translation_status(
        data: data,
        language_code: language_code
      )
    rescue StandardError
      -1
    end

    if abort_on_violations
      UI.abort_with_message!("Can't get data for language #{language_code}") if progress == -1
      UI.abort_with_message!("#{language_code} is translated #{progress}% which is under the required #{threshold}%.") if progress < threshold
    end

    UI.message("Language #{language_code} is #{progress}% translated.")
    under_threshold_langs.push({ lang: language_code, progress: progress }) if progress < threshold
  end

  under_threshold_langs
end

.descriptionObject



95
96
97
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 95

def self.description
  'Raises an error if the translation percentage is lower than the provided threshold'
end

.detailsObject



99
100
101
102
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 99

def self.details
  'This actions checks the current status of the translations on GlotPress ' \
    'and raises an error if it\'s below the provided threshold'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 142

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb', line 4

def self.run(params)
  require_relative '../../helper/glotpress_helper'

  UI.message('Checking translations status...')

  under_threshold_langs = check_translations(
    glotpress_url: params[:glotpress_url],
    language_codes: params[:language_codes],
    abort_on_violations: params[:abort_on_violations],
    threshold: params[:min_acceptable_translation_percentage]
  )

  unless under_threshold_langs.empty?
    check_results(
      under_threshold_langs: under_threshold_langs,
      threshold: params[:min_acceptable_translation_percentage],
      skip_confirm: params[:skip_confirm]
    )
  end

  UI.success('Done')
end