Skip to content

Commit 904e2de

Browse files
committed
DRY the default source strings path into constants
Extract the repeated `values/strings.xml` path into DEFAULT_SOURCE_STRINGS_FILE_NAME and DEFAULT_SOURCE_STRINGS_RELATIVE_PATH, and use them in run, the locale glob, and the res_dir verify_block.
1 parent 756965b commit 904e2de

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _None_
1010

1111
### New Features
1212

13-
- `android_prune_orphaned_translations` action: removes `<string>`, `<string-array>` and `<plurals>` entries from `values-*/strings.xml` whose keys are not declared in the source `values/strings.xml optionally unioned with `additional_source_strings_paths`. [#734]
13+
- `android_prune_orphaned_translations` action: removes `<string>`, `<string-array>` and `<plurals>` entries from `values-*/strings.xml` whose keys are not declared in the source `values/strings.xml` optionally unioned with `additional_source_strings_paths`. [#734]
1414

1515
### Bug Fixes
1616

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_prune_orphaned_translations_action.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ class AndroidPruneOrphanedTranslationsAction < Action
1111
# `values-land`) are left untouched.
1212
LOCALE_VALUES_DIR_REGEX = /\Avalues-(?:b\+[a-zA-Z]+(?:\+[a-zA-Z0-9]+)*|[a-z]{2,3}(?:-r(?:[A-Z]{2}|\d{3}))?)\z/
1313

14+
DEFAULT_SOURCE_STRINGS_FILE_NAME = 'strings.xml'
15+
DEFAULT_SOURCE_STRINGS_RELATIVE_PATH = File.join('values', DEFAULT_SOURCE_STRINGS_FILE_NAME).freeze
16+
1417
def self.run(params)
1518
res_dir = params[:res_dir]
16-
source_paths = [File.join(res_dir, 'values', 'strings.xml')] + params[:additional_source_strings_paths]
19+
source_paths = [File.join(res_dir, DEFAULT_SOURCE_STRINGS_RELATIVE_PATH)] + params[:additional_source_strings_paths]
1720
valid_keys = collect_keys(source_paths)
1821

19-
locale_files = Dir.glob(File.join(res_dir, 'values-*', 'strings.xml')).select do |file|
22+
locale_files = Dir.glob(File.join(res_dir, 'values-*', DEFAULT_SOURCE_STRINGS_FILE_NAME)).select do |file|
2023
File.basename(File.dirname(file)).match?(LOCALE_VALUES_DIR_REGEX)
2124
end
2225
total_pruned = 0
@@ -96,7 +99,7 @@ def self.available_options
9699
type: String,
97100
optional: false,
98101
verify_block: proc do |value|
99-
source_path = File.join(value, 'values', 'strings.xml')
102+
source_path = File.join(value, DEFAULT_SOURCE_STRINGS_RELATIVE_PATH)
100103
UI.user_error!("Source strings file not found: `#{source_path}`") unless File.file?(source_path)
101104
end
102105
),

0 commit comments

Comments
 (0)