From d3033f34b134f150a7ed857837926a90e015fd3d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 27 Oct 2026 10:41:40 +1100 Subject: [PATCH 1/9] Allow omitted placeholders in iOS l10n lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some languages legitimately leave out a value, e.g. Romanian "Un cuvânt" for `%1$ld word`. Unused format arguments are ignored at runtime, but `ios_lint_localizations` reports these as violations, which has blocked WordPress iOS beta builds for several releases. Tony has been patching the downloaded strings by hand each time. See AINFRA-3429. SwiftGen's type lists drop argument positions (`%2$@` alone and `%1$@` alone both come out as `[String]`), so omissions are checked by parsing the raw strings. SwiftGen stays the primary check; the parser only decides whether a reported mismatch can be forgiven. Blank translations and malformed placeholders like `%1$l` are never forgiven, as SwiftGen reports them the same way as a deliberate omission. --- Generated with the help of Claude Code, https://claude.com/claude-code Co-Authored-By: Claude Opus 5.5 --- .../actions/ios/ios_lint_localizations.rb | 12 ++- .../helper/ios/ios_l10n_linter_helper.rb | 95 ++++++++++++++++++- spec/ios_l10n_linter_helper_spec.rb | 73 ++++++++++++++ spec/ios_lint_localizations_spec.rb | 17 +++- .../omitted-placeholders-allowed.yaml | 33 +++++++ .../omitted-placeholders-not-allowed.yaml | 39 ++++++++ 6 files changed, 263 insertions(+), 6 deletions(-) create mode 100644 spec/ios_l10n_linter_helper_spec.rb create mode 100644 spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml create mode 100644 spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb index c93481502..c25c38bcf 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb @@ -38,7 +38,8 @@ def self.run_linter(params) input_dir: resolve_path(params[:input_dir]), base_lang: params[:base_lang], only_langs: params[:only_langs], - fail_on_strings_not_in_base_language: params[:fail_on_strings_not_in_base_language] + fail_on_strings_not_in_base_language: params[:fail_on_strings_not_in_base_language], + allow_omitted_placeholders: params[:allow_omitted_placeholders] ) end @@ -197,6 +198,15 @@ def self.available_options default_value: true, type: Boolean ), + FastlaneCore::ConfigItem.new( + key: :allow_omitted_placeholders, + env_name: 'FL_IOS_LINT_TRANSLATIONS_ALLOW_OMITTED_PLACEHOLDERS', + description: 'Accept translations that use only some of the base language placeholders, as long as each one they use has the same position and type (e.g. "One word" for "%1$d word"). ' \ + 'Malformed placeholders, extra placeholders and type mismatches are still reported', + optional: true, + default_value: false, + type: Boolean + ), ] end diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index b37cfa131..f976ee04e 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -11,6 +11,19 @@ class L10nLinterHelper DEFAULT_BASE_LANG = 'en' CONFIG_FILE_NAME = 'swiftgen-stringtypes.yml' + # A printf-style placeholder at the start of a string, capturing its optional `N$` position and its conversion character. + # `*` widths and precisions are deliberately not matched, as they consume an extra argument. + PLACEHOLDER_REGEX = /\A%(?:(\d+)\$)?[-+ #0']*\d*(?:\.\d*)?(?:hh|h|ll|l|q|L|z|t|j)?([@dDiuUxXoOfFeEgGaAcCsSp])/ + PLACEHOLDER_TYPES = { + '@' => :object, + 'c' => :char, 'C' => :char, + 's' => :c_string, 'S' => :c_string, + 'p' => :pointer + }.merge( + 'dDiuUxXoO'.chars.to_h { |c| [c, :integer] }, + 'fFeEgGaA'.chars.to_h { |c| [c, :float] } + ).freeze + attr_reader :install_path, :version # @param [String] install_path The path to install SwiftGen to. Usually something like "$PROJECT_DIR/vendor/swiftgen/#{SWIFTGEN_VERSION}". @@ -61,11 +74,68 @@ def install_swiftgen! # @param [String] input_dir The path (ideally absolute) to the directory containing the `.lproj` folders to parse # @param [String] base_lang The code name (i.e the basename of one of the `.lproj` folders) of the locale to use as the baseline # @param [String] fail_on_strings_not_in_base_language Whether to fail on strings not in base language + # @param [Boolean] allow_omitted_placeholders Whether to accept translations that use only some of the base language placeholders. See `only_omits_placeholders?`. # @return [Hash>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language # - def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strings_not_in_base_language: true) + def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strings_not_in_base_language: true, allow_omitted_placeholders: false) check_swiftgen_installed || install_swiftgen! - find_diffs(input_dir: input_dir, base_lang: base_lang, only_langs: only_langs, fail_on_strings_not_in_base_language: fail_on_strings_not_in_base_language) + find_diffs( + input_dir: input_dir, + base_lang: base_lang, + only_langs: only_langs, + fail_on_strings_not_in_base_language: fail_on_strings_not_in_base_language, + allow_omitted_placeholders: allow_omitted_placeholders + ) + end + + # Whether a translation is safe to format with the base string's arguments while using only some of them. + # + # That's the case when every placeholder in the translation exists in the base string, at the same position and with the same type, and the translation has fewer placeholders. + # Unused arguments are ignored at runtime, so this is legitimate when a language doesn't need a value, e.g. "One word" for a singular plural form. + # + # @param [String] base The string in the base language + # @param [String] translation The translated string + # @return [Boolean] `false` if the translation is blank, or either string has a placeholder this can't parse, like the incomplete `%1$l` + # + def self.only_omits_placeholders?(base:, translation:) + return false if translation.strip.empty? + + base_placeholders = placeholders(base) + translation_placeholders = placeholders(translation) + return false if base_placeholders.nil? || translation_placeholders.nil? + return false unless translation_placeholders.size < base_placeholders.size + + translation_placeholders.all? { |position, type| base_placeholders[position] == type } + end + + # Parses the printf-style placeholders of a string. + # + # @param [String] string The string to parse + # @return [Hash, nil] The placeholder types keyed by argument position, + # or `nil` if a placeholder is malformed, the string mixes positional and sequential placeholders, or a position is reused with a different type + # + def self.placeholders(string) + placeholders = {} + styles = [] + index = 0 + while (index = string.index('%', index)) + if string[index + 1] == '%' + index += 2 + next + end + + match = PLACEHOLDER_REGEX.match(string[index..]) + return nil if match.nil? + + styles << (match[1].nil? ? :sequential : :positional) + position = match[1]&.to_i || styles.count + type = PLACEHOLDER_TYPES[match[2]] + return nil if placeholders.key?(position) && placeholders[position] != type + + placeholders[position] = type + index += match[0].length + end + styles.uniq.size > 1 ? nil : placeholders end ################## @@ -141,6 +211,11 @@ def generate_swiftgen_config!(input_dir, output_dir, only_langs: nil) [config_file, langs] end + # @return [Hash] The raw `Localizable.strings` translations for a locale, keyed by string key + def strings_for(input_dir, lang) + Fastlane::Helper::Ios::L10nHelper.read_strings_file_as_hash(path: File.join(input_dir, "#{lang}.lproj", 'Localizable.strings')) + end + # Returns a Hash mapping the list of expected parameter types for each of the keys based in the %… placeholders found in their `.strings` files # # @param [String] dir The temporary directory in which the file to sort lines for is located @@ -162,11 +237,12 @@ def placeholder_types_for_keys(dir, lang) # @param [String] base_lang The base language used as source of truth that all other languages will be compared against # @param [Array] only_langs The list of languages to limit the generation for. Useful to focus only on a couple of issues or just one language # @param [Boolean] fail_on_strings_not_in_base_language Whether to fail on strings not in base language + # @param [Boolean] allow_omitted_placeholders Whether to accept translations that use only some of the base language placeholders # @return [Hash>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language # # @note The returned Hash contains keys only for locales with violations. Locales parsed but without any violations found will not appear in the resulting hash. # - def find_diffs(input_dir:, base_lang:, only_langs: nil, fail_on_strings_not_in_base_language: true) + def find_diffs(input_dir:, base_lang:, only_langs: nil, fail_on_strings_not_in_base_language: true, allow_omitted_placeholders: false) Dir.mktmpdir('a8c-lint-translations-') do |tmpdir| # Run SwiftGen langs = only_langs.nil? ? nil : (only_langs + [base_lang]).uniq @@ -176,15 +252,26 @@ def find_diffs(input_dir:, base_lang:, only_langs: nil, fail_on_strings_not_in_b # Run diffs params_for_base_lang = placeholder_types_for_keys(tmpdir, base_lang) langs.delete(base_lang) + base_strings = nil return langs.map do |lang| params_for_lang = placeholder_types_for_keys(tmpdir, lang) + lang_strings = nil # If the lang ends up not having any translation at all (e.g. a `.lproj` without any `.strings` file in it but maybe just a storyboard or assets catalog), ignore it next nil if params_for_lang.nil? || params_for_lang.empty? violations = params_for_lang.map do |key, param_types| next "`#{key}` was unexpected, as it is not present in the base locale." if params_for_base_lang[key].nil? && fail_on_strings_not_in_base_language - next "`#{key}` expected placeholders for #{params_for_base_lang[key]} but found #{param_types} instead." if !params_for_base_lang[key].nil? && params_for_base_lang[key] != param_types + next if params_for_base_lang[key].nil? || params_for_base_lang[key] == param_types + + # SwiftGen's type lists drop argument positions, so omissions are checked against the raw strings instead. + if allow_omitted_placeholders + base_strings ||= strings_for(input_dir, base_lang) + lang_strings ||= strings_for(input_dir, lang) + next if self.class.only_omits_placeholders?(base: base_strings[key].to_s, translation: lang_strings[key].to_s) + end + + "`#{key}` expected placeholders for #{params_for_base_lang[key]} but found #{param_types} instead." end.compact [lang, violations] unless violations.empty? diff --git a/spec/ios_l10n_linter_helper_spec.rb b/spec/ios_l10n_linter_helper_spec.rb new file mode 100644 index 000000000..ce14b1575 --- /dev/null +++ b/spec/ios_l10n_linter_helper_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Fastlane::Helper::Ios::L10nLinterHelper do + describe '.only_omits_placeholders?' do + def only_omits?(base, translation) + described_class.only_omits_placeholders?(base: base, translation: translation) + end + + it 'accepts dropping the only placeholder' do + expect(only_omits?('%1$ld word', 'Un cuvânt')).to be true + end + + it 'accepts dropping a trailing positional placeholder' do + expect(only_omits?('Post %1$@ has %2$@ like.', 'Postarea %1$@ are o apreciere.')).to be true + end + + it 'accepts dropping a leading or middle positional placeholder when the remaining positions keep their types' do + expect(only_omits?('Post %1$@ has %2$@ likes.', 'O postare are %2$@ aprecieri.')).to be true + expect(only_omits?('%1$@, %2$d, %3$@', '%1$@, %3$@')).to be true + end + + it 'accepts dropping a trailing sequential placeholder' do + expect(only_omits?('%@ and %d', 'doar %@')).to be true + end + + it 'rejects dropping a leading sequential placeholder, as it shifts the remaining arguments' do + expect(only_omits?('%@ and %d', 'doar %d')).to be false + end + + it 'treats length modifiers as the same type' do + expect(only_omits?('%1$ld of %2$ld', '%1$d')).to be true + end + + it 'ignores escaped percent signs' do + expect(only_omits?('%1$d%% of %2$d', '%1$d%%')).to be true + end + + it 'rejects a placeholder whose type differs from the base' do + expect(only_omits?('%1$d of %2$@', '%1$@')).to be false + end + + it 'rejects a placeholder at a position missing from the base' do + expect(only_omits?('%1$d of %2$@', '%3$@')).to be false + end + + it 'rejects a translation with as many placeholders as the base' do + expect(only_omits?('%1$d items', '%1$d elemente')).to be false + end + + it 'rejects a blank translation' do + expect(only_omits?('%1$@ of %2$@ used', '')).to be false + expect(only_omits?('%1$@ of %2$@ used', ' ')).to be false + end + + it 'rejects an incomplete placeholder' do + expect(only_omits?('%1$ld words', '%1$l 个字')).to be false + end + + it 'rejects a `*` width, as it consumes an extra argument' do + expect(only_omits?('%1$d and %2$d', '%*d')).to be false + end + + it 'rejects mixing positional and sequential placeholders' do + expect(only_omits?('%1$@ %2$d %3$@', '%1$@ %d')).to be false + end + + it 'rejects reusing a position with a different type' do + expect(only_omits?('%1$d %2$@ %3$@', '%1$d %1$@')).to be false + end + end +end diff --git a/spec/ios_lint_localizations_spec.rb b/spec/ios_lint_localizations_spec.rb index 9afbab6ca..1427d8c8c 100644 --- a/spec/ios_lint_localizations_spec.rb +++ b/spec/ios_lint_localizations_spec.rb @@ -65,8 +65,10 @@ # @param [Boolean, nil] fail_on_strings_not_in_base_language If `nil`, the test will run the action with the default `fail_on_strings_not_in_base_language` parameter value. # If a `Boolean` value is given, it will pass that. # Controls whether to report violations when finding strings in translations that are not present in the base language. + # @param [Boolean, nil] allow_omitted_placeholders If `nil`, the test will run the action with the default `allow_omitted_placeholders` parameter value. + # If a `Boolean` value is given, it will pass that. # - def run_l10n_linter_test(data_file:, check_duplicate_keys: nil, fail_on_strings_not_in_base_language: nil) + def run_l10n_linter_test(data_file:, check_duplicate_keys: nil, fail_on_strings_not_in_base_language: nil, allow_omitted_placeholders: nil) # Arrange: Prepare test files test_file = File.join(File.dirname(__FILE__), 'test-data', 'translations', 'ios_lint_localizations', "#{data_file}.yaml") yml = YAML.load_file(test_file) @@ -90,6 +92,7 @@ def run_l10n_linter_test(data_file:, check_duplicate_keys: nil, fail_on_strings_ } parameters[:check_duplicate_keys] = check_duplicate_keys unless check_duplicate_keys.nil? parameters[:fail_on_strings_not_in_base_language] = fail_on_strings_not_in_base_language unless fail_on_strings_not_in_base_language.nil? + parameters[:allow_omitted_placeholders] = allow_omitted_placeholders unless allow_omitted_placeholders.nil? result = run_described_fastlane_action(parameters) # Assert @@ -227,6 +230,18 @@ def run_l10n_linter_test(data_file:, check_duplicate_keys: nil, fail_on_strings_ fail_on_strings_not_in_base_language: true ) end + + it 'reports translations that omit placeholders by default' do + run_l10n_linter_test(data_file: 'omitted-placeholders-not-allowed') + end + + it 'reports translations that omit placeholders when allow_omitted_placeholders is false' do + run_l10n_linter_test(data_file: 'omitted-placeholders-not-allowed', allow_omitted_placeholders: false) + end + + it 'accepts translations that only omit placeholders when allow_omitted_placeholders is true, but still reports malformed, extra, and mismatched ones' do + run_l10n_linter_test(data_file: 'omitted-placeholders-allowed', allow_omitted_placeholders: true) + end end # Regression coverage for the unquoted-key/value parsing in `StringsFileValidationHelper`, which used diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml new file mode 100644 index 000000000..0ab1aba88 --- /dev/null +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml @@ -0,0 +1,33 @@ +test_data: + en: | + "word_count_one" = "%1$ld word"; + "word_count_zero" = "%1$ld words"; + "latest_post_likes" = "The latest post %1$@ has received %2$@ like."; + "leading_omitted" = "Post %1$@ has %2$@ likes."; + "middle_omitted" = "A %1$@, B %2$d, C %3$@"; + "sequential_trailing_omitted" = "%@ and %d"; + "sequential_leading_omitted" = "%@ and %d"; + "type_mismatch" = "%1$d items"; + "extra_placeholder" = "%1$d items"; + "incomplete_placeholder" = "%1$ld words"; + "empty_translation" = "%1$@ of %2$@ used"; + ro: | + "word_count_one" = "Un cuvânt"; + "word_count_zero" = "Niciun cuvânt"; + "latest_post_likes" = "Ultimul articol %1$@ a avut o apreciere."; + "leading_omitted" = "Un articol are %2$@ aprecieri."; + "middle_omitted" = "A %1$@, C %3$@"; + "sequential_trailing_omitted" = "doar %@"; + "sequential_leading_omitted" = "doar %d"; + "type_mismatch" = "%1$@ elemente"; + "extra_placeholder" = "%1$d elemente %2$@"; + "incomplete_placeholder" = "%1$l cuvinte"; + "empty_translation" = ""; + +result: + ro: + - "`empty_translation` expected placeholders for [String,String] but found [] instead." + - "`extra_placeholder` expected placeholders for [Int] but found [Int,String] instead." + - "`incomplete_placeholder` expected placeholders for [Int] but found [] instead." + - "`sequential_leading_omitted` expected placeholders for [String,Int] but found [Int] instead." + - "`type_mismatch` expected placeholders for [Int] but found [String] instead." diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml new file mode 100644 index 000000000..1cdc0314d --- /dev/null +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml @@ -0,0 +1,39 @@ +test_data: + en: | + "word_count_one" = "%1$ld word"; + "word_count_zero" = "%1$ld words"; + "latest_post_likes" = "The latest post %1$@ has received %2$@ like."; + "leading_omitted" = "Post %1$@ has %2$@ likes."; + "middle_omitted" = "A %1$@, B %2$d, C %3$@"; + "sequential_trailing_omitted" = "%@ and %d"; + "sequential_leading_omitted" = "%@ and %d"; + "type_mismatch" = "%1$d items"; + "extra_placeholder" = "%1$d items"; + "incomplete_placeholder" = "%1$ld words"; + "empty_translation" = "%1$@ of %2$@ used"; + ro: | + "word_count_one" = "Un cuvânt"; + "word_count_zero" = "Niciun cuvânt"; + "latest_post_likes" = "Ultimul articol %1$@ a avut o apreciere."; + "leading_omitted" = "Un articol are %2$@ aprecieri."; + "middle_omitted" = "A %1$@, C %3$@"; + "sequential_trailing_omitted" = "doar %@"; + "sequential_leading_omitted" = "doar %d"; + "type_mismatch" = "%1$@ elemente"; + "extra_placeholder" = "%1$d elemente %2$@"; + "incomplete_placeholder" = "%1$l cuvinte"; + "empty_translation" = ""; + +result: + ro: + - "`empty_translation` expected placeholders for [String,String] but found [] instead." + - "`extra_placeholder` expected placeholders for [Int] but found [Int,String] instead." + - "`incomplete_placeholder` expected placeholders for [Int] but found [] instead." + - "`latest_post_likes` expected placeholders for [String,String] but found [String] instead." + - "`leading_omitted` expected placeholders for [String,String] but found [String] instead." + - "`middle_omitted` expected placeholders for [String,Int,String] but found [String,String] instead." + - "`sequential_leading_omitted` expected placeholders for [String,Int] but found [Int] instead." + - "`sequential_trailing_omitted` expected placeholders for [String,Int] but found [String] instead." + - "`type_mismatch` expected placeholders for [Int] but found [String] instead." + - "`word_count_one` expected placeholders for [Int] but found [] instead." + - "`word_count_zero` expected placeholders for [Int] but found [] instead." From c70750a73e6af7543ac320c1d77e22e430c16223 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 27 Oct 2026 10:42:18 +1100 Subject: [PATCH 2/9] Add CHANGELOG entry for `allow_omitted_placeholders` --- Generated with the help of Claude Code, https://claude.com/claude-code Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee1965786..6584e3ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ _None_ ### New Features -_None_ +- Add an opt-in `allow_omitted_placeholders` option to `ios_lint_localizations` so translations that use only some of the base language placeholders, at the same positions and types, are not reported. [#779] ### Bug Fixes From f3e06e9aed9234656591beffb5fbcdd07ced0184 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 27 Oct 2026 11:44:11 +1100 Subject: [PATCH 3/9] Document omitted placeholders with Romanian example --- Generated with the help of Claude Code, https://claude.com/claude-code Co-Authored-By: Claude Opus 5.5 --- .../wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index f976ee04e..59b156246 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -91,7 +91,11 @@ def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strin # Whether a translation is safe to format with the base string's arguments while using only some of them. # # That's the case when every placeholder in the translation exists in the base string, at the same position and with the same type, and the translation has fewer placeholders. - # Unused arguments are ignored at runtime, so this is legitimate when a language doesn't need a value, e.g. "One word" for a singular plural form. + # Unused arguments are ignored at runtime, so this is legitimate when a language doesn't need a value. + # + # For example, the English "The latest post %1$@ has received %2$@ like.", where `%2$@` is always "1", + # can be translated to Romanian as "Ultimul articol %1$@ a avut o apreciere.", discarding `%2$@` + # because "o" is both the indefinite article and the number one for feminine nouns, so the digit would be redundant. # # @param [String] base The string in the base language # @param [String] translation The translated string From 4837cfeba3f829185f9fc673b6c2631a13995a7a Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 27 Oct 2026 12:05:20 +1100 Subject: [PATCH 4/9] Use plural example in omitted placeholders docs The previous example's singular key only exists because the app picks it with `== 1` and keeps `%2$@` to bold the count, so it didn't show why omitting a placeholder can be legitimate. A plural "one" form does, and Russian, where "one" also covers 21, shows the limit: the check proves runtime safety, not linguistic correctness. Plural categories verified with `xcstringstool` and `String(format:locale:)`. --- Generated with the help of Claude Code, https://claude.com/claude-code Co-Authored-By: Claude Opus 5.5 --- .../helper/ios/ios_l10n_linter_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index 59b156246..655b21e98 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -93,9 +93,11 @@ def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strin # That's the case when every placeholder in the translation exists in the base string, at the same position and with the same type, and the translation has fewer placeholders. # Unused arguments are ignored at runtime, so this is legitimate when a language doesn't need a value. # - # For example, the English "The latest post %1$@ has received %2$@ like.", where `%2$@` is always "1", - # can be translated to Romanian as "Ultimul articol %1$@ a avut o apreciere.", discarding `%2$@` - # because "o" is both the indefinite article and the number one for feminine nouns, so the digit would be redundant. + # For example, the English plural "one" form "%1$ld word" can be translated to Romanian as "Un cuvânt", discarding `%1$ld`, + # because Romanian uses "one" only for exactly 1, and "un" already says it. + # + # This only checks the omission is safe at runtime, not that it's right for the language. + # Russian also has a "one" form, but it covers 1, 21, 31, 101…, so "Одно слово" would wrongly read as one word for 21 words, and this would still accept it. # # @param [String] base The string in the base language # @param [String] translation The translated string From 127c7510517755ee9a6b6bd00dd8951c36f444a5 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 27 Oct 2026 15:53:12 +1100 Subject: [PATCH 5/9] Streamline a documentation comment --- .../wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index 655b21e98..30094161f 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -74,7 +74,7 @@ def install_swiftgen! # @param [String] input_dir The path (ideally absolute) to the directory containing the `.lproj` folders to parse # @param [String] base_lang The code name (i.e the basename of one of the `.lproj` folders) of the locale to use as the baseline # @param [String] fail_on_strings_not_in_base_language Whether to fail on strings not in base language - # @param [Boolean] allow_omitted_placeholders Whether to accept translations that use only some of the base language placeholders. See `only_omits_placeholders?`. + # @param [Boolean] allow_omitted_placeholders Whether to accept translations that use only some of the base language placeholders. # @return [Hash>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language # def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strings_not_in_base_language: true, allow_omitted_placeholders: false) From a5f41f304c74abd785da19654a98dc287a06076d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 24 Nov 2026 14:10:30 +1100 Subject: [PATCH 6/9] Only allow omitting trailing placeholders Foundation compacts gaps in positional arguments, so a translation like `%2$@` for `%1$@ %2$@` formats the first value, not the second. Every real-world case seen so far (Romanian plurals) drops only the last placeholder, so nothing legitimate is lost. Raised by Copilot on #779. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- CHANGELOG.md | 2 +- .../actions/ios/ios_lint_localizations.rb | 4 ++-- .../helper/ios/ios_l10n_linter_helper.rb | 10 ++++++---- spec/ios_l10n_linter_helper_spec.rb | 13 ++++++++++--- .../omitted-placeholders-allowed.yaml | 2 ++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6584e3ea7..a16bc2f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ _None_ ### New Features -- Add an opt-in `allow_omitted_placeholders` option to `ios_lint_localizations` so translations that use only some of the base language placeholders, at the same positions and types, are not reported. [#779] +- Add an opt-in `allow_omitted_placeholders` option to `ios_lint_localizations` so translations that omit the trailing base language placeholders, keeping the others at the same positions and types, are not reported. [#779] ### Bug Fixes diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb index c25c38bcf..0bc5e149c 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_lint_localizations.rb @@ -201,8 +201,8 @@ def self.available_options FastlaneCore::ConfigItem.new( key: :allow_omitted_placeholders, env_name: 'FL_IOS_LINT_TRANSLATIONS_ALLOW_OMITTED_PLACEHOLDERS', - description: 'Accept translations that use only some of the base language placeholders, as long as each one they use has the same position and type (e.g. "One word" for "%1$d word"). ' \ - 'Malformed placeholders, extra placeholders and type mismatches are still reported', + description: 'Accept translations that omit the trailing base language placeholders, as long as the ones they keep have the same positions and types (e.g. "One word" for "%1$d word"). ' \ + 'Omitting a leading or middle placeholder, malformed placeholders, extra placeholders and type mismatches are still reported', optional: true, default_value: false, type: Boolean diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index 30094161f..368879427 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -74,7 +74,7 @@ def install_swiftgen! # @param [String] input_dir The path (ideally absolute) to the directory containing the `.lproj` folders to parse # @param [String] base_lang The code name (i.e the basename of one of the `.lproj` folders) of the locale to use as the baseline # @param [String] fail_on_strings_not_in_base_language Whether to fail on strings not in base language - # @param [Boolean] allow_omitted_placeholders Whether to accept translations that use only some of the base language placeholders. + # @param [Boolean] allow_omitted_placeholders Whether to accept translations that omit the trailing base language placeholders. # @return [Hash>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language # def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strings_not_in_base_language: true, allow_omitted_placeholders: false) @@ -90,8 +90,9 @@ def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strin # Whether a translation is safe to format with the base string's arguments while using only some of them. # - # That's the case when every placeholder in the translation exists in the base string, at the same position and with the same type, and the translation has fewer placeholders. - # Unused arguments are ignored at runtime, so this is legitimate when a language doesn't need a value. + # That's the case when the translation keeps the base string's first placeholders, at the same positions and with the same types, and drops the rest. + # Unused trailing arguments are ignored at runtime, so this is legitimate when a language doesn't need a value. + # Omitting a leading or middle placeholder isn't, because Foundation compacts gaps in positional arguments and would format the wrong value. # # For example, the English plural "one" form "%1$ld word" can be translated to Romanian as "Un cuvânt", discarding `%1$ld`, # because Romanian uses "one" only for exactly 1, and "un" already says it. @@ -110,6 +111,7 @@ def self.only_omits_placeholders?(base:, translation:) translation_placeholders = placeholders(translation) return false if base_placeholders.nil? || translation_placeholders.nil? return false unless translation_placeholders.size < base_placeholders.size + return false unless translation_placeholders.keys.sort == (1..translation_placeholders.size).to_a translation_placeholders.all? { |position, type| base_placeholders[position] == type } end @@ -243,7 +245,7 @@ def placeholder_types_for_keys(dir, lang) # @param [String] base_lang The base language used as source of truth that all other languages will be compared against # @param [Array] only_langs The list of languages to limit the generation for. Useful to focus only on a couple of issues or just one language # @param [Boolean] fail_on_strings_not_in_base_language Whether to fail on strings not in base language - # @param [Boolean] allow_omitted_placeholders Whether to accept translations that use only some of the base language placeholders + # @param [Boolean] allow_omitted_placeholders Whether to accept translations that omit the trailing base language placeholders # @return [Hash>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language # # @note The returned Hash contains keys only for locales with violations. Locales parsed but without any violations found will not appear in the resulting hash. diff --git a/spec/ios_l10n_linter_helper_spec.rb b/spec/ios_l10n_linter_helper_spec.rb index ce14b1575..87696af40 100644 --- a/spec/ios_l10n_linter_helper_spec.rb +++ b/spec/ios_l10n_linter_helper_spec.rb @@ -16,9 +16,16 @@ def only_omits?(base, translation) expect(only_omits?('Post %1$@ has %2$@ like.', 'Postarea %1$@ are o apreciere.')).to be true end - it 'accepts dropping a leading or middle positional placeholder when the remaining positions keep their types' do - expect(only_omits?('Post %1$@ has %2$@ likes.', 'O postare are %2$@ aprecieri.')).to be true - expect(only_omits?('%1$@, %2$d, %3$@', '%1$@, %3$@')).to be true + it 'accepts dropping several trailing positional placeholders' do + expect(only_omits?('%1$@, %2$d, %3$@', '%1$@ doar')).to be true + end + + it 'rejects dropping a leading positional placeholder, as Foundation would format the first argument in its place' do + expect(only_omits?('Post %1$@ has %2$@ likes.', 'O postare are %2$@ aprecieri.')).to be false + end + + it 'rejects dropping a middle positional placeholder, as Foundation would shift the arguments after it' do + expect(only_omits?('%1$@, %2$d, %3$@', '%1$@, %3$@')).to be false end it 'accepts dropping a trailing sequential placeholder' do diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml index 0ab1aba88..ea3c26557 100644 --- a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml @@ -29,5 +29,7 @@ result: - "`empty_translation` expected placeholders for [String,String] but found [] instead." - "`extra_placeholder` expected placeholders for [Int] but found [Int,String] instead." - "`incomplete_placeholder` expected placeholders for [Int] but found [] instead." + - "`leading_omitted` expected placeholders for [String,String] but found [String] instead." + - "`middle_omitted` expected placeholders for [String,Int,String] but found [String,String] instead." - "`sequential_leading_omitted` expected placeholders for [String,Int] but found [Int] instead." - "`type_mismatch` expected placeholders for [Int] but found [String] instead." From 5da97dd8d74d23c5759b02c479032e01887877cb Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 24 Nov 2026 14:11:22 +1100 Subject: [PATCH 7/9] Keep length modifiers when matching placeholders Grouping every integer conversion as one type let `%1$hhd` stand in for `%1$ld`, which shows 300 as 44. Only synonyms that read the same argument (`%ld`/`%lld`/`%zd`, `%i`/`%d`, `%lc`/`%C`) still match. Raised by Copilot on #779. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../helper/ios/ios_l10n_linter_helper.rb | 42 +++++++++++++------ spec/ios_l10n_linter_helper_spec.rb | 24 ++++++++++- .../omitted-placeholders-allowed.yaml | 3 ++ .../omitted-placeholders-not-allowed.yaml | 3 ++ 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index 368879427..ce9c8413d 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -11,18 +11,11 @@ class L10nLinterHelper DEFAULT_BASE_LANG = 'en' CONFIG_FILE_NAME = 'swiftgen-stringtypes.yml' - # A printf-style placeholder at the start of a string, capturing its optional `N$` position and its conversion character. + # A printf-style placeholder at the start of a string, capturing its optional `N$` position, its length modifier and its conversion character. # `*` widths and precisions are deliberately not matched, as they consume an extra argument. - PLACEHOLDER_REGEX = /\A%(?:(\d+)\$)?[-+ #0']*\d*(?:\.\d*)?(?:hh|h|ll|l|q|L|z|t|j)?([@dDiuUxXoOfFeEgGaAcCsSp])/ - PLACEHOLDER_TYPES = { - '@' => :object, - 'c' => :char, 'C' => :char, - 's' => :c_string, 'S' => :c_string, - 'p' => :pointer - }.merge( - 'dDiuUxXoO'.chars.to_h { |c| [c, :integer] }, - 'fFeEgGaA'.chars.to_h { |c| [c, :float] } - ).freeze + PLACEHOLDER_REGEX = /\A%(?:(\d+)\$)?[-+ #0']*\d*(?:\.\d*)?(hh|h|ll|l|q|L|z|t|j)?([@dDiuUxXoOfFeEgGaAcCsSp])/ + # Length modifiers that all read a 64-bit integer on Apple platforms + LONG_INTEGER_LENGTHS = %w[l ll q z t j].freeze attr_reader :install_path, :version @@ -119,7 +112,7 @@ def self.only_omits_placeholders?(base:, translation:) # Parses the printf-style placeholders of a string. # # @param [String] string The string to parse - # @return [Hash, nil] The placeholder types keyed by argument position, + # @return [Hash, nil] The placeholder types keyed by argument position, # or `nil` if a placeholder is malformed, the string mixes positional and sequential placeholders, or a position is reused with a different type # def self.placeholders(string) @@ -137,7 +130,7 @@ def self.placeholders(string) styles << (match[1].nil? ? :sequential : :positional) position = match[1]&.to_i || styles.count - type = PLACEHOLDER_TYPES[match[2]] + type = placeholder_type(length: match[2], conversion: match[3]) return nil if placeholders.key?(position) && placeholders[position] != type placeholders[position] = type @@ -146,6 +139,29 @@ def self.placeholders(string) styles.uniq.size > 1 ? nil : placeholders end + # The argument a placeholder reads, as its conversion with only the length modifiers that change it. + # Conversions and lengths are kept distinct, rather than grouped like SwiftGen does, because reading an argument with the wrong size truncates it: `%hhd` shows 300 as 44. + # + # @param [String, nil] length The length modifier, like `l` in `%ld` + # @param [String] conversion The conversion character, like `d` in `%ld` + # @return [String] A normalized placeholder, like `ld` for both `%ld` and `%qd` + # + def self.placeholder_type(length:, conversion:) + case conversion + when 'i' then conversion = 'd' + when 'D', 'U', 'O' + length = 'l' + conversion = conversion.downcase + end + + case conversion + when 'd', 'o', 'u', 'x', 'X' then "#{LONG_INTEGER_LENGTHS.include?(length) ? 'l' : length}#{conversion}" + when 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A' then "#{'L' if length == 'L'}#{conversion}" + when 'c', 's' then length == 'l' ? conversion.upcase : conversion + else conversion + end + end + ################## private diff --git a/spec/ios_l10n_linter_helper_spec.rb b/spec/ios_l10n_linter_helper_spec.rb index 87696af40..708f4317f 100644 --- a/spec/ios_l10n_linter_helper_spec.rb +++ b/spec/ios_l10n_linter_helper_spec.rb @@ -36,8 +36,28 @@ def only_omits?(base, translation) expect(only_omits?('%@ and %d', 'doar %d')).to be false end - it 'treats length modifiers as the same type' do - expect(only_omits?('%1$ld of %2$ld', '%1$d')).to be true + it 'treats length modifiers that read the same size of integer as the same type' do + expect(only_omits?('%1$ld of %2$ld', '%1$lld')).to be true + expect(only_omits?('%1$ld of %2$ld', '%1$zd')).to be true + expect(only_omits?('%1$ld of %2$ld', '%1$D')).to be true + expect(only_omits?('%1$d of %2$d', '%1$i')).to be true + end + + it 'rejects a length modifier that reads a different size of integer, as it would truncate the value' do + expect(only_omits?('%1$ld of %2$ld', '%1$d')).to be false + expect(only_omits?('%1$ld of %2$ld', '%1$hhd')).to be false + expect(only_omits?('%1$d of %2$d', '%1$hd')).to be false + end + + it 'rejects a different conversion of the same kind of argument' do + expect(only_omits?('%1$ld of %2$ld', '%1$lu')).to be false + expect(only_omits?('%1$f of %2$f', '%1$Lf')).to be false + expect(only_omits?('%1$C and %2$C', '%1$c')).to be false + end + + it 'ignores length modifiers that do not change the argument read' do + expect(only_omits?('%1$f of %2$f', '%1$lf')).to be true + expect(only_omits?('%1$C and %2$C', '%1$lc')).to be true end it 'ignores escaped percent signs' do diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml index ea3c26557..51eac50ac 100644 --- a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml @@ -9,6 +9,7 @@ test_data: "sequential_leading_omitted" = "%@ and %d"; "type_mismatch" = "%1$d items"; "extra_placeholder" = "%1$d items"; + "length_mismatch" = "%1$ld of %2$ld"; "incomplete_placeholder" = "%1$ld words"; "empty_translation" = "%1$@ of %2$@ used"; ro: | @@ -21,6 +22,7 @@ test_data: "sequential_leading_omitted" = "doar %d"; "type_mismatch" = "%1$@ elemente"; "extra_placeholder" = "%1$d elemente %2$@"; + "length_mismatch" = "%1$hhd"; "incomplete_placeholder" = "%1$l cuvinte"; "empty_translation" = ""; @@ -30,6 +32,7 @@ result: - "`extra_placeholder` expected placeholders for [Int] but found [Int,String] instead." - "`incomplete_placeholder` expected placeholders for [Int] but found [] instead." - "`leading_omitted` expected placeholders for [String,String] but found [String] instead." + - "`length_mismatch` expected placeholders for [Int,Int] but found [Int] instead." - "`middle_omitted` expected placeholders for [String,Int,String] but found [String,String] instead." - "`sequential_leading_omitted` expected placeholders for [String,Int] but found [Int] instead." - "`type_mismatch` expected placeholders for [Int] but found [String] instead." diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml index 1cdc0314d..8f5d02e5c 100644 --- a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml @@ -9,6 +9,7 @@ test_data: "sequential_leading_omitted" = "%@ and %d"; "type_mismatch" = "%1$d items"; "extra_placeholder" = "%1$d items"; + "length_mismatch" = "%1$ld of %2$ld"; "incomplete_placeholder" = "%1$ld words"; "empty_translation" = "%1$@ of %2$@ used"; ro: | @@ -21,6 +22,7 @@ test_data: "sequential_leading_omitted" = "doar %d"; "type_mismatch" = "%1$@ elemente"; "extra_placeholder" = "%1$d elemente %2$@"; + "length_mismatch" = "%1$hhd"; "incomplete_placeholder" = "%1$l cuvinte"; "empty_translation" = ""; @@ -31,6 +33,7 @@ result: - "`incomplete_placeholder` expected placeholders for [Int] but found [] instead." - "`latest_post_likes` expected placeholders for [String,String] but found [String] instead." - "`leading_omitted` expected placeholders for [String,String] but found [String] instead." + - "`length_mismatch` expected placeholders for [Int,Int] but found [Int] instead." - "`middle_omitted` expected placeholders for [String,Int,String] but found [String,String] instead." - "`sequential_leading_omitted` expected placeholders for [String,Int] but found [Int] instead." - "`sequential_trailing_omitted` expected placeholders for [String,Int] but found [String] instead." From 67ade57ea0fbecc402bdb650a0c4a3b1019a48d2 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 24 Nov 2026 14:12:07 +1100 Subject: [PATCH 8/9] Report lookalike percent placeholders when omitting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A placeholder typed with `%` or `٪` isn't a placeholder to Foundation, so the translation looked like it omitted one and the option forgave it, hiding a violation the lint reports today. Raised by Copilot on #779. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../helper/ios/ios_l10n_linter_helper.rb | 9 +++++++-- spec/ios_l10n_linter_helper_spec.rb | 11 +++++++++++ spec/ios_lint_localizations_spec.rb | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index ce9c8413d..9e191a7ca 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -13,7 +13,10 @@ class L10nLinterHelper # A printf-style placeholder at the start of a string, capturing its optional `N$` position, its length modifier and its conversion character. # `*` widths and precisions are deliberately not matched, as they consume an extra argument. - PLACEHOLDER_REGEX = /\A%(?:(\d+)\$)?[-+ #0']*\d*(?:\.\d*)?(hh|h|ll|l|q|L|z|t|j)?([@dDiuUxXoOfFeEgGaAcCsSp])/ + PLACEHOLDER_SPEC = /(?:(\d+)\$)?[-+ #0']*\d*(?:\.\d*)?(hh|h|ll|l|q|L|z|t|j)?([@dDiuUxXoOfFeEgGaAcCsSp])/ + PLACEHOLDER_REGEX = /\A%#{PLACEHOLDER_SPEC}/ + # A placeholder typed with a lookalike of `%` (fullwidth, Arabic or small percent sign), which Foundation prints verbatim + LOOKALIKE_PLACEHOLDER_REGEX = /[\uFF05\u066A\uFE6A]#{PLACEHOLDER_SPEC}/ # Length modifiers that all read a 64-bit integer on Apple platforms LONG_INTEGER_LENGTHS = %w[l ll q z t j].freeze @@ -113,9 +116,11 @@ def self.only_omits_placeholders?(base:, translation:) # # @param [String] string The string to parse # @return [Hash, nil] The placeholder types keyed by argument position, - # or `nil` if a placeholder is malformed, the string mixes positional and sequential placeholders, or a position is reused with a different type + # or `nil` if a placeholder is malformed or uses a lookalike of `%`, the string mixes positional and sequential placeholders, or a position is reused with a different type # def self.placeholders(string) + return nil if LOOKALIKE_PLACEHOLDER_REGEX.match?(string) + placeholders = {} styles = [] index = 0 diff --git a/spec/ios_l10n_linter_helper_spec.rb b/spec/ios_l10n_linter_helper_spec.rb index 708f4317f..569d645e5 100644 --- a/spec/ios_l10n_linter_helper_spec.rb +++ b/spec/ios_l10n_linter_helper_spec.rb @@ -81,6 +81,17 @@ def only_omits?(base, translation) expect(only_omits?('%1$@ of %2$@ used', ' ')).to be false end + it 'rejects a placeholder typed with a lookalike of the percent sign' do + expect(only_omits?('String %@ here, %d times.', "String \u{FF05}@ here.")).to be false + expect(only_omits?('String %1$@ here, %2$d times.', "String \u{066A}1$@ here.")).to be false + expect(only_omits?('String %1$@ here, %2$d times.', "String \u{FE6A}1$@ here.")).to be false + end + + it 'accepts a lookalike of the percent sign that is not a placeholder' do + expect(only_omits?('%1$d%% of %2$@', "%1$d\u{066A} مكتمل")).to be true + expect(only_omits?('%1$d%% of %2$@', "%1$d\u{FF05}完了")).to be true + end + it 'rejects an incomplete placeholder' do expect(only_omits?('%1$ld words', '%1$l 个字')).to be false end diff --git a/spec/ios_lint_localizations_spec.rb b/spec/ios_lint_localizations_spec.rb index 1427d8c8c..fb9a52e62 100644 --- a/spec/ios_lint_localizations_spec.rb +++ b/spec/ios_lint_localizations_spec.rb @@ -231,6 +231,10 @@ def run_l10n_linter_test(data_file:, check_duplicate_keys: nil, fail_on_strings_ ) end + it 'still reports placeholders typed with a lookalike of the percent sign when allow_omitted_placeholders is true' do + run_l10n_linter_test(data_file: 'tricky-chars', allow_omitted_placeholders: true) + end + it 'reports translations that omit placeholders by default' do run_l10n_linter_test(data_file: 'omitted-placeholders-not-allowed') end From e3c22c5dab984ede2c0f8a8c7a38352a0a04fa6f Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 24 Nov 2026 14:12:42 +1100 Subject: [PATCH 9/9] Match keys containing newlines when omitting SwiftGen escapes `\n` and `\r` in the keys it prints, but `plutil` returns them decoded, so looking up a multiline key in the raw strings found nothing and a legitimate omission was still reported. Tabs, quotes and backslashes are printed as-is, verified against SwiftGen 6.6.2. Raised by Copilot on #779. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb | 3 ++- .../ios_lint_localizations/omitted-placeholders-allowed.yaml | 2 ++ .../omitted-placeholders-not-allowed.yaml | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb index 9e191a7ca..979011d3b 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb @@ -240,9 +240,10 @@ def generate_swiftgen_config!(input_dir, output_dir, only_langs: nil) [config_file, langs] end - # @return [Hash] The raw `Localizable.strings` translations for a locale, keyed by string key + # @return [Hash] The raw `Localizable.strings` translations for a locale, keyed by string key as SwiftGen prints it, with newlines escaped def strings_for(input_dir, lang) Fastlane::Helper::Ios::L10nHelper.read_strings_file_as_hash(path: File.join(input_dir, "#{lang}.lproj", 'Localizable.strings')) + .transform_keys { |key| key.gsub("\n", '\n').gsub("\r", '\r') } end # Returns a Hash mapping the list of expected parameter types for each of the keys based in the %… placeholders found in their `.strings` files diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml index 51eac50ac..67e78b4c6 100644 --- a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-allowed.yaml @@ -2,6 +2,7 @@ test_data: en: | "word_count_one" = "%1$ld word"; "word_count_zero" = "%1$ld words"; + "multiline\nkey" = "%1$ld\nwords"; "latest_post_likes" = "The latest post %1$@ has received %2$@ like."; "leading_omitted" = "Post %1$@ has %2$@ likes."; "middle_omitted" = "A %1$@, B %2$d, C %3$@"; @@ -15,6 +16,7 @@ test_data: ro: | "word_count_one" = "Un cuvânt"; "word_count_zero" = "Niciun cuvânt"; + "multiline\nkey" = "Un\ncuvânt"; "latest_post_likes" = "Ultimul articol %1$@ a avut o apreciere."; "leading_omitted" = "Un articol are %2$@ aprecieri."; "middle_omitted" = "A %1$@, C %3$@"; diff --git a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml index 8f5d02e5c..ebda7fc08 100644 --- a/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml +++ b/spec/test-data/translations/ios_lint_localizations/omitted-placeholders-not-allowed.yaml @@ -2,6 +2,7 @@ test_data: en: | "word_count_one" = "%1$ld word"; "word_count_zero" = "%1$ld words"; + "multiline\nkey" = "%1$ld\nwords"; "latest_post_likes" = "The latest post %1$@ has received %2$@ like."; "leading_omitted" = "Post %1$@ has %2$@ likes."; "middle_omitted" = "A %1$@, B %2$d, C %3$@"; @@ -15,6 +16,7 @@ test_data: ro: | "word_count_one" = "Un cuvânt"; "word_count_zero" = "Niciun cuvânt"; + "multiline\nkey" = "Un\ncuvânt"; "latest_post_likes" = "Ultimul articol %1$@ a avut o apreciere."; "leading_omitted" = "Un articol are %2$@ aprecieri."; "middle_omitted" = "A %1$@, C %3$@"; @@ -35,6 +37,7 @@ result: - "`leading_omitted` expected placeholders for [String,String] but found [String] instead." - "`length_mismatch` expected placeholders for [Int,Int] but found [Int] instead." - "`middle_omitted` expected placeholders for [String,Int,String] but found [String,String] instead." + - "`multiline\\nkey` expected placeholders for [Int] but found [] instead." - "`sequential_leading_omitted` expected placeholders for [String,Int] but found [Int] instead." - "`sequential_trailing_omitted` expected placeholders for [String,Int] but found [String] instead." - "`type_mismatch` expected placeholders for [Int] but found [String] instead."