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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@
6
6
7
7
### Breaking Changes
8
8
9
-
_None_
9
+
* Update the API of `ios_merge_strings_files` and `ios_extract_keys_from_strings_files` to support using prefixes for string keys when merging/splitting the files.
10
+
The actions now expect a `Hash` (instead of an `Array`) for the list of files to provide an associated prefix (or `nil` or `''` when none) for each file to merge/split. [#345]
description: 'The path(s) to the `<base-locale>.lproj/<target-tablename>.strings` file(s) for which we want to extract the keys to. ' \
86
-
+ 'Each of those files should containing the original strings (typically `en` or `Base` locale) and will be used to determine which keys to extract from the `source_tablename`. ' \
87
-
+ 'For each of those, the path(s) in which the translations will be extracted will be the files with the same basename in each of the other `*.lproj` sibling folders',
88
-
type: Array,
104
+
description: 'The path(s) to the `<base-locale>.lproj/<target-tablename>.strings` file(s) for which we want to extract the keys to, and the prefix to remove from their keys. ' \
105
+
+ 'Each key in the Hash should point to a file containing the original strings (typically `en` or `Base` locale), and will be used to determine which keys to extract from the `source_tablename`. ' \
106
+
+ 'For each key, the associated value is an optional prefix to remove from the keys (which can be useful if you used a prefix during `ios_merge_strings_files` to avoid duplicates). Can be nil or empty if no prefix was used during merge for that file.' \
107
+
+ 'Note: For each entry, the path(s) in which the translations will be extracted to will be the files with the same basename as the key in each of the other `*.lproj` sibling folders. ',
108
+
type: Hash,
89
109
verify_block: procdo |values|
90
110
UI.user_error!('`target_original_files` must contain at least one path to an original `.strings` file.')ifvalues.empty?
91
-
values.eachdo |v|
92
-
UI.user_error!("Path `#{v}` (found in `target_original_files`) does not exist.")unlessFile.exist?(v)
93
-
UI.user_error!"Expected `#{v}` (found in `target_original_files`) to be a path ending in a `*.lproj/*.strings`."unlessFile.extname(v) == '.strings' && File.extname(File.dirname(v)) == '.lproj'
111
+
values.eachdo |path,_|
112
+
UI.user_error!("Path `#{path}` (found in `target_original_files`) does not exist.")unlessFile.exist?(path)
113
+
UI.user_error!"Expected `#{path}` (found in `target_original_files`) to be a path ending in a `*.lproj/*.strings`."unlessFile.extname(path) == '.strings' && File.extname(File.dirname(path)) == '.lproj'
94
114
end
95
115
end),
96
116
]
97
117
end
98
118
99
119
defself.return_type
100
-
# Describes what type of data is expected to be returned
101
-
# see RETURN_TYPES in https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/action.rb
102
-
nil
120
+
:array_of_strings
103
121
end
104
122
105
123
defself.return_value
106
-
# Freeform textual description of the return value
124
+
'The list of files which have been generated and written to disk by the action'
UI.important"Duplicate key found while merging the `.strings` files: `#{dup_key}`"
10
15
end
16
+
UI.important'Tip: To avoid those key conflicts, you might want to consider providing different prefixes in the `Hash` you used for the `paths:` parameter.'unlessduplicates.empty?
11
17
duplicates
12
18
end
13
19
@@ -21,12 +27,11 @@ def self.description
21
27
22
28
defself.details
23
29
<<~DETAILS
24
-
Merge multiple `.strings` files into one.
30
+
Merge multiple `.strings` files into another one.
25
31
26
-
Especially useful to prepare a single `.strings` file merging strings from both `Localizable.strings` from
27
-
the app code — typically previously extracted from `ios_generate_strings_file_from_code` —
28
-
and string files like `InfoPlist.strings` — which values may not be generated from the codebase but
29
-
manually maintained by developers.
32
+
Especially useful to prepare a single `.strings` file merging string files like `InfoPlist.strings` — whose
33
+
content are typically manually maintained by developers — within the main `Localizable.strings` file — which
34
+
would have typically been previously generated from the codebase via `ios_generate_strings_file_from_code`.
30
35
31
36
The action only supports merging files which are in the OpenStep (`"key" = "value";`) text format (which is
32
37
the most common format for `.strings` files, and the one generated by `genstrings`), but can handle the case
@@ -38,19 +43,18 @@ def self.details
38
43
defself.available_options
39
44
[
40
45
FastlaneCore::ConfigItem.new(
41
-
key: :paths,
42
-
env_name: 'FL_IOS_MERGE_STRINGS_FILES_PATHS',
43
-
description: 'The paths of all the `.strings` files to merge together',
description: 'A hash of the paths of all the `.strings` files to merge into the `destination`, with the prefix to be used for their keys as associated value',
# Merge the content of multiple `.strings` files into a new `.strings` text file.
38
40
#
39
-
# @param [Array<String>] paths The paths of the `.strings` files to merge together
40
-
# @param [String] into The path to the merged `.strings` file to generate as a result.
41
+
# @param [Hash<String, String>] paths The paths of the `.strings` files to merge together, associated with the prefix to prepend to each of their respective keys
42
+
# @param [String] output_path The path to the merged `.strings` file to generate as a result.
41
43
# @return [Array<String>] List of duplicate keys found while validating the merge.
42
44
#
43
45
# @note For now, this method only supports merging `.strings` file in `:text` format
# We need to ensure the line and RegExp are using the same encoding, so we transcode everything to UTF-8.
75
+
line.encode!(Encoding::UTF_8)
76
+
# The `/u` modifier on the RegExps is to make them UTF-8
77
+
line.gsub!(/^(\s*")/u,"\\1#{prefix}")# Lines starting with a quote are considered to be start of a key; add prefix right after the quote
78
+
line.gsub!(/^(\s*)([A-Z0-9_]+)(\s*=\s*")/ui,"\\1\"#{prefix}\\2\"\\3")# Lines starting with an identifier followed by a '=' are considered to be an unquoted key (typical in InfoPlist.strings files for example)
79
+
end
80
+
tmp_file.write(line)
81
+
end
69
82
tmp_file.write("\n")
70
83
end
71
84
tmp_file.close# ensure we flush the content to disk
0 commit comments