Skip to content

Commit

Permalink
Merge pull request #545 from Automattic/issue/fixing-update-translati…
Browse files Browse the repository at this point in the history
…ons-script

Fixing Update-Translations Script
  • Loading branch information
jleandroperez authored Nov 29, 2019
2 parents 15bae98 + a028ec9 commit 5e2dfa9
Show file tree
Hide file tree
Showing 19 changed files with 7,666 additions and 6,308 deletions.
20 changes: 2 additions & 18 deletions Scripts/update-translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,12 @@ def copy_comment(f, trans_strings, value)
# Backup the current file
system "if [ -e #{lang_dir}/Localizable.strings ]; then cp #{lang_dir}/Localizable.strings #{lang_dir}/Localizable.strings.bak; fi"

# Download translations in JSON format in order to get the string keys
system "curl -sSfL --globoff -o #{lang_dir}/Localizable.json https://translate.wordpress.com/projects/simplenote%2Fios/#{code}/default/export-translations?format=json" or begin
puts "Error downloading #{code}"
end
trans_json = JSON.parse(File.read("#{lang_dir}/Localizable.json"))

# Download translations in strings format in order to get the comments
system "curl -sSfL --globoff -o #{lang_dir}/Localizable.strings.tmp https://translate.wordpress.com/projects/simplenote%2Fios/#{code}/default/export-translations?format=strings" or begin
system "curl -fLso #{lang_dir}/Localizable.strings https://translate.wordpress.com/projects/simplenote%2Fios/#{code}/default/export-translations?format=strings" or begin
puts "Error downloading #{code}"
end
trans_strings = File.read("#{lang_dir}/Localizable.strings.tmp")

File.open("#{lang_dir}/Localizable.strings", "w") do |f|
copy_header(f, trans_strings)
Hash[trans_json.to_a.reverse].each do | key, value |
copy_comment(f, trans_strings, value[0]) unless value[0].nil?
f.write("\"#{key.split("\u0004")[0]}\" = \"#{value[0]}\";\n\n") unless value[0].nil?
end
end

system "./Scripts/fix-translation #{lang_dir}/Localizable.strings"
system "plutil -lint #{lang_dir}/Localizable.strings" and system "rm #{lang_dir}/Localizable.strings.bak"
system "rm #{lang_dir}/Localizable.strings.tmp"
system "rm #{lang_dir}/Localizable.json"
system "grep -a '\\x00\\x20\\x00\\x22\\x00\\x22\\x00\\x3b$' #{lang_dir}/Localizable.strings"
end
Loading

0 comments on commit 5e2dfa9

Please sign in to comment.