Skip to content

Commit 649b103

Browse files
committed
Add a8c-src-lib attribute to the <string> XML nodes when merging strings from libs
To help identify them more easily in the merged file and make it clear for developers where they come from (and thus where the source of truth for each string is)
1 parent dfca603 commit 649b103

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def self.details
3232
end
3333

3434
def self.available_options
35+
libs_hash_description = <<~KEYS
36+
- `:library`: The library display name
37+
- `:strings_path`: The path to the `strings.xml` file of the library
38+
- `:exclusions`: An optional `Array` of string keys to exclude from merging
39+
- `:source_id`: An optional `String` which will be added as the `a8c-src-lib` XML attribute
40+
to strings coming from this library, to help identify their source in the merged file.
41+
KEYS
3542
[
3643
FastlaneCore::ConfigItem.new(key: :app_strings_path,
3744
description: 'The path of the main strings file',
@@ -41,10 +48,7 @@ def self.available_options
4148
# See `Fastlane::Helper::Android::LocalizeHelper.merge_lib`'s YARD doc for more details on the keys expected for each Hash.
4249
FastlaneCore::ConfigItem.new(key: :libs_strings_path,
4350
env_name: 'LOCALIZE_LIBS_STRINGS_PATH',
44-
description: 'The list of libs to merge. ' \
45-
+ 'Each item in the provided array must be a Hash with the keys `:library` (The library display name),' \
46-
+ '`:strings_path` (The path to the `strings.xml` file of the library) and ' \
47-
+ '`:exclusions` (Array of string keys to exclude from merging)',
51+
description: "The list of libs to merge. Each item in the provided array must be a Hash with the following keys:\n#{libs_hash_description}",
4852
optional: false,
4953
type: Array),
5054
]

lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module Fastlane
99
module Helper
1010
module Android
1111
module LocalizeHelper
12+
LIB_SOURCE_XML_ATTR = 'a8c-src-lib'.freeze
13+
1214
# Checks if string_line has the content_override flag set
1315
def self.skip_string_by_tag(string_line)
1416
skip = string_line.attr('content_override') == 'true' unless string_line.attr('content_override').nil?
@@ -35,6 +37,7 @@ def self.skip_string_by_exclusion_list(library, string_name)
3537
def self.merge_string(main_strings, library, string_line)
3638
string_name = string_line.attr('name')
3739
string_content = string_line.content
40+
lib_src_id = library[:source_id]
3841

3942
# Skip strings in the exclusions list
4043
return :skipped if skip_string_by_exclusion_list(library, string_name)
@@ -58,12 +61,14 @@ def self.merge_string(main_strings, library, string_line)
5861
else
5962
# It has the tools:ignore flag, so update the content without touching the other attributes
6063
this_string.content = string_content
64+
this_string[LIB_SOURCE_XML_ATTR] = lib_src_id unless lib_src_id.nil?
6165
return result
6266
end
6367
end
6468
end
6569

6670
# String not found, or removed because needing update and not in the exclusion list: add to the main file
71+
string_line[LIB_SOURCE_XML_ATTR] = lib_src_id unless lib_src_id.nil?
6772
main_strings.xpath('//string').last().add_next_sibling("\n#{' ' * 4}#{string_line.to_xml().strip}")
6873
return result
6974
end

0 commit comments

Comments
 (0)