66module Fastlane
77 module Actions
88 class AndroidPruneOrphanedTranslationsAction < Action
9- # Matches an Android `values-<qualifier>` directory whose qualifier is a locale (a language code, optional
10- # region, or a BCP-47 `b+` form), so non-locale qualifier dirs (e.g. `values-night`, `values-v21`,
11- # `values-land`) are left untouched.
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.
1212 LOCALE_VALUES_DIR_REGEX = /\A values-(?:b\+ [a-zA-Z]+(?:\+ [a-zA-Z0-9]+)*|[a-z]{2,3}(?:-r(?:[A-Z]{2}|\d {3}))?)\z /
1313
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+
1422 DEFAULT_SOURCE_STRINGS_FILE_NAME = 'strings.xml'
1523 DEFAULT_SOURCE_STRINGS_RELATIVE_PATH = File . join ( 'values' , DEFAULT_SOURCE_STRINGS_FILE_NAME ) . freeze
1624
@@ -20,7 +28,8 @@ def self.run(params)
2028 valid_keys = collect_keys ( source_paths )
2129
2230 locale_files = Dir . glob ( File . join ( res_dir , 'values-*' , DEFAULT_SOURCE_STRINGS_FILE_NAME ) ) . select do |file |
23- File . basename ( File . dirname ( file ) ) . match? ( LOCALE_VALUES_DIR_REGEX )
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-' ) )
2433 end
2534 total_pruned = 0
2635
0 commit comments