Skip to content

Commit 4015c67

Browse files
authored
Merge pull request #123 from wordpress-mobile/feature/manage-multiple-release-notes-versions-2
Short release notes on Android: Download
2 parents 4006ec1 + 87691ac commit 4015c67

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/an_metadata_update_helper.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,5 @@ def is_handler_for(key)
150150

151151
end
152152
end
153-
154-
155-
156153
end
157-
154+

lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_download_helper.rb

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class MetadataDownloader
1010
def initialize(target_folder, target_files)
1111
@target_folder = target_folder
1212
@target_files = target_files
13+
@alternates = {}
1314
end
1415

1516
# Downloads data from GlotPress,
@@ -21,8 +22,10 @@ def download(target_locale, glotpress_url, is_source)
2122
response = Net::HTTP.get_response(URI.parse(response.header['location']))
2223
end
2324

25+
@alternates.clear
2426
loc_data = JSON.parse(response.body) rescue loc_data = nil
25-
parse_data(target_locale, loc_data, is_source)
27+
parse_data(target_locale, loc_data, is_source)
28+
reparse_alternates(target_locale, loc_data, is_source) unless (@alternates.length == 0)
2629
end
2730

2831
# Parse JSON data and update the local files
@@ -42,16 +45,43 @@ def parse_data(target_locale, loc_data, is_source)
4245
if (file[0].to_s == key)
4346
data = file[1]
4447
msg = is_source ? source : d[1]
45-
if (data.key?(:max_size)) && (data[:max_size] != 0) && ((msg.to_s.length - 3) > data[:max_size]) then
46-
UI.message("Rejecting #{target_locale} traslation for #{key}: translation length: #{msg.to_s.length} - max allowed length: #{data[:max_size]}")
47-
else
48-
save_metadata(target_locale, file[1][:desc], msg)
49-
end
48+
update_key(target_locale, key, file, data, msg)
5049
end
5150
end
5251
end
5352
end
5453

54+
# Parse JSON data and update the local files
55+
def reparse_alternates(target_locale, loc_data, is_source)
56+
loc_data.each do | d |
57+
key = d[0].split(/\u0004/).first
58+
source = d[0].split(/\u0004/).last
59+
60+
@alternates.each do | file |
61+
puts "Data: #{file[0].to_s} - key: #{key}"
62+
if (file[0].to_s == key)
63+
puts "Alternate: #{key}"
64+
data = file[1]
65+
msg = is_source ? source : d[1]
66+
update_key(target_locale, key, file, data, msg)
67+
end
68+
end
69+
end
70+
end
71+
72+
def update_key(target_locale, key, file, data, msg)
73+
if (data.key?(:max_size)) && (data[:max_size] != 0) && ((msg.to_s.length - 3) > data[:max_size]) then
74+
if (data.key?(:alternate_key)) then
75+
UI.message("#{target_locale} translation for #{key} exceeds maximum length (#{msg.to_s.length}). Switching to the alternate translation.")
76+
@alternates[data[:alternate_key]] = {desc: data[:desc], max_size: 0 }
77+
else
78+
UI.message("Rejecting #{target_locale} traslation for #{key}: translation length: #{msg.to_s.length} - max allowed length: #{data[:max_size]}")
79+
end
80+
else
81+
save_metadata(target_locale, file[1][:desc], msg)
82+
end
83+
end
84+
5585
# Writes the downloaded content
5686
# to the target file
5787
def save_metadata(locale, file_name, content)

0 commit comments

Comments
 (0)