From 649b103eec94149933497e9fb31657e1166816ff Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 7 Apr 2022 18:36:43 +0200 Subject: [PATCH 1/5] Add `a8c-src-lib` attribute to the 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) --- .../actions/android/an_localize_libs_action.rb | 12 ++++++++---- .../helper/android/android_localize_helper.rb | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb index 4ebac3ec9..8c82c36f3 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb @@ -32,6 +32,13 @@ def self.details end def self.available_options + libs_hash_description = <<~KEYS + - `:library`: The library display name + - `:strings_path`: The path to the `strings.xml` file of the library + - `:exclusions`: An optional `Array` of string keys to exclude from merging + - `:source_id`: An optional `String` which will be added as the `a8c-src-lib` XML attribute + to strings coming from this library, to help identify their source in the merged file. + KEYS [ FastlaneCore::ConfigItem.new(key: :app_strings_path, description: 'The path of the main strings file', @@ -41,10 +48,7 @@ def self.available_options # See `Fastlane::Helper::Android::LocalizeHelper.merge_lib`'s YARD doc for more details on the keys expected for each Hash. FastlaneCore::ConfigItem.new(key: :libs_strings_path, env_name: 'LOCALIZE_LIBS_STRINGS_PATH', - description: 'The list of libs to merge. ' \ - + 'Each item in the provided array must be a Hash with the keys `:library` (The library display name),' \ - + '`:strings_path` (The path to the `strings.xml` file of the library) and ' \ - + '`:exclusions` (Array of string keys to exclude from merging)', + 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}", optional: false, type: Array), ] diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb index ea41f683d..199c74b8d 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb @@ -9,6 +9,8 @@ module Fastlane module Helper module Android module LocalizeHelper + LIB_SOURCE_XML_ATTR = 'a8c-src-lib'.freeze + # Checks if string_line has the content_override flag set def self.skip_string_by_tag(string_line) 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) def self.merge_string(main_strings, library, string_line) string_name = string_line.attr('name') string_content = string_line.content + lib_src_id = library[:source_id] # Skip strings in the exclusions list return :skipped if skip_string_by_exclusion_list(library, string_name) @@ -58,12 +61,14 @@ def self.merge_string(main_strings, library, string_line) else # It has the tools:ignore flag, so update the content without touching the other attributes this_string.content = string_content + this_string[LIB_SOURCE_XML_ATTR] = lib_src_id unless lib_src_id.nil? return result end end end # String not found, or removed because needing update and not in the exclusion list: add to the main file + string_line[LIB_SOURCE_XML_ATTR] = lib_src_id unless lib_src_id.nil? main_strings.xpath('//string').last().add_next_sibling("\n#{' ' * 4}#{string_line.to_xml().strip}") return result end From b4db3f468eafd0dd787a71aea24082db76f37fc3 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 7 Apr 2022 19:15:15 +0200 Subject: [PATCH 2/5] Support case of passing a `nil` exclusions list So that both omitting the key entirely, and providing it but with a nil value, are both the same as using an empty exclusion list --- .../wpmreleasetoolkit/helper/android/android_localize_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb index 199c74b8d..595cc9423 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb @@ -24,7 +24,7 @@ def self.skip_string_by_tag(string_line) # Checks if string_name is in the excluesion list def self.skip_string_by_exclusion_list(library, string_name) - return false unless library.key?(:exclusions) + return false if library[:exclusions].nil? skip = library[:exclusions].include?(string_name) if skip From 2688e7801ece797ffd872da6680ede97c292f159 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 7 Apr 2022 19:15:37 +0200 Subject: [PATCH 3/5] Change `puts` to fastlane's `UI` logging methods --- .../helper/android/android_localize_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb index 595cc9423..02487f3b8 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb @@ -15,7 +15,7 @@ module LocalizeHelper def self.skip_string_by_tag(string_line) skip = string_line.attr('content_override') == 'true' unless string_line.attr('content_override').nil? if skip - puts " - Skipping #{string_line.attr('name')} string" + UI.message " - Skipping #{string_line.attr('name')} string" return true end @@ -28,7 +28,7 @@ def self.skip_string_by_exclusion_list(library, string_name) skip = library[:exclusions].include?(string_name) if skip - puts " - Skipping #{string_name} string" + UI.message " - Skipping #{string_name} string" return true end end @@ -118,12 +118,12 @@ def self.merge_lib(main, library) res = merge_string(main_strings, library, string_line) case res when :updated - puts "#{string_line.attr('name')} updated." + UI.verbose "#{string_line.attr('name')} updated." updated_count = updated_count + 1 when :found untouched_count = untouched_count + 1 when :added - puts "#{string_line.attr('name')} added." + UI.verbose "#{string_line.attr('name')} added." added_count = added_count + 1 when :skipped skipped_count = skipped_count + 1 From 09dc09afb636325e0b18e24ba12db99124f23586 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 7 Apr 2022 20:01:45 +0200 Subject: [PATCH 4/5] Add CHANGELOG entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 530ad664f..f93c47c05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,9 @@ _None_ ### New Features -_None_ +* Add the option for `an_localize_libs` to provide a `source_id` for each library being merged. + If provided, that identifier will be added as an `a8c-src-lib` XML attribute to the `` nodes being updated with strings from said library. + This can be useful to help identify where each string come from in the resulting, merged `strings.xml`. [#351] ### Bug Fixes From b85a7d7026fee597347494472dab0560a7ae9d71 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Mon, 11 Apr 2022 20:10:14 +0200 Subject: [PATCH 5/5] Fix tab vs space in CHANGELOG Co-authored-by: Gio Lodi --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f93c47c05..6a799080a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ _None_ * Add the option for `an_localize_libs` to provide a `source_id` for each library being merged. If provided, that identifier will be added as an `a8c-src-lib` XML attribute to the `` nodes being updated with strings from said library. - This can be useful to help identify where each string come from in the resulting, merged `strings.xml`. [#351] + This can be useful to help identify where each string come from in the resulting, merged `strings.xml`. [#351] ### Bug Fixes