Skip to content

Commit 5cf371e

Browse files
authored
Merge pull request #351 from wordpress-mobile/libs-merge/source-id
Add option to identify the source library when merging strings.xml files
2 parents dfca603 + b85a7d7 commit 5cf371e

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

CHANGELOG.md

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

1111
### New Features
1212

13-
_None_
13+
* Add the option for `an_localize_libs` to provide a `source_id` for each library being merged.
14+
If provided, that identifier will be added as an `a8c-src-lib` XML attribute to the `<string>` nodes being updated with strings from said library.
15+
This can be useful to help identify where each string come from in the resulting, merged `strings.xml`. [#351]
1416

1517
### Bug Fixes
1618

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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ 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?
1517
if skip
16-
puts " - Skipping #{string_line.attr('name')} string"
18+
UI.message " - Skipping #{string_line.attr('name')} string"
1719
return true
1820
end
1921

@@ -22,11 +24,11 @@ def self.skip_string_by_tag(string_line)
2224

2325
# Checks if string_name is in the excluesion list
2426
def self.skip_string_by_exclusion_list(library, string_name)
25-
return false unless library.key?(:exclusions)
27+
return false if library[:exclusions].nil?
2628

2729
skip = library[:exclusions].include?(string_name)
2830
if skip
29-
puts " - Skipping #{string_name} string"
31+
UI.message " - Skipping #{string_name} string"
3032
return true
3133
end
3234
end
@@ -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
@@ -113,12 +118,12 @@ def self.merge_lib(main, library)
113118
res = merge_string(main_strings, library, string_line)
114119
case res
115120
when :updated
116-
puts "#{string_line.attr('name')} updated."
121+
UI.verbose "#{string_line.attr('name')} updated."
117122
updated_count = updated_count + 1
118123
when :found
119124
untouched_count = untouched_count + 1
120125
when :added
121-
puts "#{string_line.attr('name')} added."
126+
UI.verbose "#{string_line.attr('name')} added."
122127
added_count = added_count + 1
123128
when :skipped
124129
skipped_count = skipped_count + 1

0 commit comments

Comments
 (0)