You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous implementation used a `diff` of textual outputs from SwiftGen, which worked so far because in the host app projects, locales which were missing translations for some keys were previously replaced by `”key” = “key”` entries (this was back when we assumes that our keys were always going to be the English copies)
But since the recent improvements in our Localization Tooling, this is not the case anymore, and any key that does not have a translation in a given local is now just omitted and not present in that locale’s `Localizable.strings` — just as it has always been intended.
This made the logic of the linter break as it relied on this assumption to make the `diff` it ran on the textual outputs be useful. But now that the `Localizable.strings` files for translations might actually miss a lot of the keys present in the reference locale, we needed to be smarter
This changes the approach from doing a plain textual `diff` of the outputs, to parsing the outputs of SwiftGen into a `Hash<Key, ExpectedParametersList>`, so we can then filter and ignore the keys that are missing in each locale, and only raise violations for keys that are present in both the localization and the reference locale (typically English), in other words, only for keys for which there are actual translations to compare the placeholders for.
Copy file name to clipboardExpand all lines: lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb
+20-34Lines changed: 20 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -58,8 +58,7 @@ def install_swiftgen!
58
58
#
59
59
# @param [String] input_dir The path (ideally absolute) to the directory containing the `.lproj` folders to parse
60
60
# @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
61
-
# @return [Hash<String, String>] A hash whose keys are the language codes (basename of `.lproj` folders) for which violations were found,
62
-
# and the values are the output of the `diff` showing these violations.
61
+
# @return [Hash<String, Array<String>>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language
# Because we use English copy verbatim as key names, some keys are the same except for the upper/lowercase.
143
-
# We need to sort the output again because SwiftGen only sort case-insensitively so that means keys that are
144
-
# the same except case might be in swapped order for different outputs
141
+
# Returns a Hash mapping the list of expected parameter types for each of the keys based in the %… placeholders found in their `.strings` files
145
142
#
146
143
# @param [String] dir The temporary directory in which the file to sort lines for is located
147
144
# @param [String] lang The code for the locale we need to sort the output lines for
145
+
# @return [Hash<String, String>] A hash whose keys are the strings keys, and corresponding value is a String describing the types expected as parameters.
# Prepares the template and config files, then run SwiftGen, run `diff` on each generated output against the baseline, and returns a Hash of the violations found.
159
157
#
160
158
# @param [String] input_dir The directory where the `.lproj` folders to scan are located
161
159
# @param [String] base_lang The base language used as source of truth that all other languages will be compared against
162
160
# @param [Array<String>] only_langs The list of languages to limit the generation for. Useful to focus only on a couple of issues or just one language
163
-
# @return [Hash<String, String>] A hash of violations, keyed by language code, whose values are the diff output.
161
+
# @return [Hash<String, Array<String>>] A hash of violations, keyed by language code, whose values are the list of violation messages for that language
164
162
#
165
163
# @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.
# 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
180
-
nextniliffile.nil? || only_empty_lines?(file)
181
-
182
-
# Compute the diff
183
-
diff=`diff -U0 "#{base_file}" "#{file}"`
184
-
# Remove the lines starting with `---`/`+++` which contains the file names (which are temp files we don't want to expose in the final diff to users)
185
-
# Note: We still keep the `@@ from-file-line-numbers to-file-line-numbers @@` lines to help the user know the index of the key to find it faster,
186
-
# and also to serve as a clear visual separator between diff entries in the output.
187
-
# Those numbers won't be matching the original `.strings` file line numbers because they are line numbers in the SwiftGen-generated intermediate
188
-
# file instead, but they can still give an indication at the index in the list of keys at which this difference is located.
0 commit comments