fastlane-plugin-wpmreleasetoolkit 14.9.0 → 14.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1db5468c63b1d9cec762c5af38e8cb1e3b858214fb15d1a1d2fd3502da09b9cc
|
|
4
|
+
data.tar.gz: 9fc9c2104373e1161421e38a014af1b7a686a72747febc8284d7acca2b06ba25
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a984608e0fd91a036759a8700d663aca874af9105732f175c42fa97e4e75a2dca1daa0bbcfa0c79caf77ed4463ddc76a4eaf78a6c902220b0df060337a692a7d
|
|
7
|
+
data.tar.gz: f97d44bb69c2f8283c061f65d3dac7bffb15ea7fd849ee5f3b3db8795e2129d19b8ad4091871e144f7706f3796678b476c856c2fe01f8aaa8f25040f1cb329eb
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fastlane/action'
|
|
4
|
+
require 'nokogiri'
|
|
5
|
+
|
|
6
|
+
module Fastlane
|
|
7
|
+
module Actions
|
|
8
|
+
class AndroidPruneOrphanedTranslationsAction < Action
|
|
9
|
+
# Matches an Android `values-<qualifier>` directory whose qualifier is a locale: a 2- or 3-letter language
|
|
10
|
+
# code (`fr`, `kmr`), an optional region (`pt-rBR`, `es-r419`), or a BCP-47 `b+` form (`b+sr+Latn`), so
|
|
11
|
+
# non-locale qualifier dirs (e.g. `values-night`, `values-v21`, `values-land`) are left untouched.
|
|
12
|
+
LOCALE_VALUES_DIR_REGEX = /\Avalues-(?:b\+[a-zA-Z]+(?:\+[a-zA-Z0-9]+)*|[a-z]{2,3}(?:-r(?:[A-Z]{2}|\d{3}))?)\z/
|
|
13
|
+
|
|
14
|
+
# Android UI-mode qualifiers, which are never locales:
|
|
15
|
+
# https://developer.android.com/guide/topics/resources/providing-resources#UiModeQualifier
|
|
16
|
+
# `car` is indistinguishable by shape from a 3-letter ISO 639 language code, so `LOCALE_VALUES_DIR_REGEX`
|
|
17
|
+
# would otherwise treat `values-car` as a locale and prune its (valid) car-mode resources. There's no purely
|
|
18
|
+
# syntactic way to tell the two apart, so we exclude the documented UI-mode qualifiers explicitly. (`car` is
|
|
19
|
+
# the only one short enough to currently match the regex; the rest are listed to capture the full set.)
|
|
20
|
+
UI_MODE_QUALIFIERS = %w[car desk television appliance watch vrheadset].freeze
|
|
21
|
+
|
|
22
|
+
DEFAULT_SOURCE_STRINGS_FILE_NAME = 'strings.xml'
|
|
23
|
+
DEFAULT_SOURCE_STRINGS_RELATIVE_PATH = File.join('values', DEFAULT_SOURCE_STRINGS_FILE_NAME).freeze
|
|
24
|
+
|
|
25
|
+
def self.run(params)
|
|
26
|
+
res_dir = params[:res_dir]
|
|
27
|
+
source_paths = [File.join(res_dir, DEFAULT_SOURCE_STRINGS_RELATIVE_PATH)] + params[:additional_source_strings_paths]
|
|
28
|
+
valid_keys = collect_keys(source_paths)
|
|
29
|
+
|
|
30
|
+
locale_files = Dir.glob(File.join(res_dir, 'values-*', DEFAULT_SOURCE_STRINGS_FILE_NAME)).select do |file|
|
|
31
|
+
dir_name = File.basename(File.dirname(file))
|
|
32
|
+
dir_name.match?(LOCALE_VALUES_DIR_REGEX) && !UI_MODE_QUALIFIERS.include?(dir_name.delete_prefix('values-'))
|
|
33
|
+
end
|
|
34
|
+
total_pruned = 0
|
|
35
|
+
|
|
36
|
+
locale_files.each do |file|
|
|
37
|
+
pruned = prune_file(file: file, valid_keys: valid_keys)
|
|
38
|
+
next if pruned.empty?
|
|
39
|
+
|
|
40
|
+
total_pruned += pruned.count
|
|
41
|
+
UI.message("Pruned #{pruned.count} orphaned entries from `#{file}`: #{pruned.join(', ')}")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
UI.success("Pruned #{total_pruned} orphaned translation entries across #{locale_files.count} locale file(s).")
|
|
45
|
+
total_pruned
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Collects the set of resource names (string, string-array, plurals, …) declared in the given strings files.
|
|
49
|
+
#
|
|
50
|
+
# @param [Array<String>] paths The strings.xml files to read the valid keys from.
|
|
51
|
+
# @return [Set<String>] The set of declared resource names.
|
|
52
|
+
def self.collect_keys(paths)
|
|
53
|
+
paths.each_with_object(Set.new) do |path, keys|
|
|
54
|
+
doc = File.open(path) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }
|
|
55
|
+
doc.xpath('/resources/*[@name]').each { |node| keys << node['name'] }
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Removes from `file` any resource entry whose `name` is not in `valid_keys`, preserving the rest of the
|
|
60
|
+
# file's formatting (so the change shows up as a minimal diff).
|
|
61
|
+
#
|
|
62
|
+
# @param [String] file The locale strings.xml file to prune.
|
|
63
|
+
# @param [Set<String>] valid_keys The set of names that are allowed to remain.
|
|
64
|
+
# @return [Array<String>] The names of the entries that were pruned.
|
|
65
|
+
def self.prune_file(file:, valid_keys:)
|
|
66
|
+
doc = File.open(file) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }
|
|
67
|
+
orphans = doc.xpath('/resources/*[@name]').reject { |node| valid_keys.include?(node['name']) }
|
|
68
|
+
return [] if orphans.empty?
|
|
69
|
+
|
|
70
|
+
names = orphans.map { |node| node['name'] }
|
|
71
|
+
orphans.each do |node|
|
|
72
|
+
# Drop the indentation/newline text node right before the element too, to avoid leaving a blank line.
|
|
73
|
+
previous = node.previous_sibling
|
|
74
|
+
previous.remove if previous&.text? && previous.text.strip.empty?
|
|
75
|
+
node.remove
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
File.open(file, 'w') { |f| doc.write_to(f, encoding: Encoding::UTF_8.to_s, indent: 4) }
|
|
79
|
+
names
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#####################################################
|
|
83
|
+
# @!group Documentation
|
|
84
|
+
#####################################################
|
|
85
|
+
|
|
86
|
+
def self.description
|
|
87
|
+
'Removes translations whose keys are not present in the source strings, to avoid Lint `ExtraTranslation` errors'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def self.details
|
|
91
|
+
<<~DETAILS
|
|
92
|
+
When downloading translations from GlotPress, the export may include keys that are no longer present in
|
|
93
|
+
the app's source strings (e.g. removed or renamed since the GlotPress source was last synced). Android
|
|
94
|
+
Lint flags these orphaned translations as `ExtraTranslation` errors.
|
|
95
|
+
|
|
96
|
+
This action removes — from every `values-*/strings.xml` under `res_dir` — any `<string>`, `<string-array>`
|
|
97
|
+
or `<plurals>` entry whose `name` is not declared in the default `values/strings.xml` of `res_dir`,
|
|
98
|
+
optionally unioned with `additional_source_strings_paths` (useful when a product flavor overlays a base
|
|
99
|
+
module's resources at build time, so the base module's keys are valid too).
|
|
100
|
+
DETAILS
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.available_options
|
|
104
|
+
[
|
|
105
|
+
FastlaneCore::ConfigItem.new(
|
|
106
|
+
key: :res_dir,
|
|
107
|
+
description: "Path to the Android project's `res` directory containing the `values-*` locale subdirectories to prune",
|
|
108
|
+
type: String,
|
|
109
|
+
optional: false,
|
|
110
|
+
verify_block: proc do |value|
|
|
111
|
+
source_path = File.join(value, DEFAULT_SOURCE_STRINGS_RELATIVE_PATH)
|
|
112
|
+
UI.user_error!("Source strings file not found: `#{source_path}`") unless File.file?(source_path)
|
|
113
|
+
end
|
|
114
|
+
),
|
|
115
|
+
FastlaneCore::ConfigItem.new(
|
|
116
|
+
key: :additional_source_strings_paths,
|
|
117
|
+
description: 'Paths to additional default `strings.xml` files whose keys should also be treated as valid ' \
|
|
118
|
+
'(e.g. a base module that the pruned `res_dir` overlays at build time)',
|
|
119
|
+
type: Array,
|
|
120
|
+
optional: true,
|
|
121
|
+
default_value: [],
|
|
122
|
+
verify_block: proc do |value|
|
|
123
|
+
value.each do |path|
|
|
124
|
+
UI.user_error!("Source strings file not found: `#{path}`") unless File.file?(path)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
),
|
|
128
|
+
]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def self.return_value
|
|
132
|
+
'The total number of orphaned translation entries that were pruned'
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def self.authors
|
|
136
|
+
['Automattic']
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.is_supported?(platform)
|
|
140
|
+
platform == :android
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fastlane-plugin-wpmreleasetoolkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 14.
|
|
4
|
+
version: 14.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Automattic
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: buildkit
|
|
@@ -131,7 +131,7 @@ dependencies:
|
|
|
131
131
|
version: '1.19'
|
|
132
132
|
- - ">="
|
|
133
133
|
- !ruby/object:Gem::Version
|
|
134
|
-
version: 1.19.
|
|
134
|
+
version: 1.19.4
|
|
135
135
|
type: :runtime
|
|
136
136
|
prerelease: false
|
|
137
137
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -141,7 +141,7 @@ dependencies:
|
|
|
141
141
|
version: '1.19'
|
|
142
142
|
- - ">="
|
|
143
143
|
- !ruby/object:Gem::Version
|
|
144
|
-
version: 1.19.
|
|
144
|
+
version: 1.19.4
|
|
145
145
|
- !ruby/object:Gem::Dependency
|
|
146
146
|
name: octokit
|
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -421,6 +421,7 @@ files:
|
|
|
421
421
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_translations_action.rb
|
|
422
422
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb
|
|
423
423
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_launch_emulator_action.rb
|
|
424
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_prune_orphaned_translations_action.rb
|
|
424
425
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_send_app_size_metrics.rb
|
|
425
426
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_shutdown_emulator_action.rb
|
|
426
427
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_release_notes.rb
|