Skip to content

Commit d107e3f

Browse files
authored
Merge pull request #440 from woocommerce/feature/pull-remote-strings
Add localised strings to the app
2 parents 4151ac5 + 8aa75c9 commit d107e3f

File tree

20 files changed

+15132
-4
lines changed

20 files changed

+15132
-4
lines changed

Scripts/fix-translation

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env swift
2+
3+
import Foundation
4+
5+
guard CommandLine.arguments.count > 1 else {
6+
print("Usage: fix-translation path/to/Localizable.strings")
7+
exit(1)
8+
}
9+
10+
func fix(file: String) throws {
11+
var encoding = String.Encoding.utf8
12+
let contents = try String(contentsOfFile: file, usedEncoding: &encoding)
13+
let regexp = try NSRegularExpression(pattern: "^\"(.*)\" = \"\";$", options: [])
14+
var output = ""
15+
contents.enumerateLines { line, _ in
16+
let replaced = regexp.stringByReplacingMatches(in: line, options: [], range: NSRange(location: 0, length: line.count), withTemplate: "\"$1\" = \"$1\";")
17+
output.append(replaced as String)
18+
output.append("\n")
19+
}
20+
try output.write(toFile: file, atomically: true, encoding: encoding)
21+
}
22+
23+
do {
24+
try CommandLine.arguments.dropFirst().forEach { file in
25+
try fix(file: file)
26+
}
27+
} catch {
28+
print(error)
29+
}

Scripts/update-translations.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
# Supported languages:
5+
# ar,zh-Hans,zh-Hant,nl,fr,de,he,id,ko,pt,ru,es,sv,tr,ja,it
6+
# * Arabic
7+
# * Chinese (China) [zh-Hans]
8+
# * Chinese (Taiwan) [zh-Hant]
9+
# * Dutch
10+
# * French
11+
# * German
12+
# * Hebrew
13+
# * Indonesian
14+
# * Korean
15+
# * Portuguese (Brazil)
16+
# * Russian
17+
# * Spanish
18+
# * Swedish
19+
# * Turkish
20+
# * Japanese
21+
# * Italian
22+
23+
24+
if Dir.pwd =~ /Scripts/
25+
puts "Must run script from root folder"
26+
exit
27+
end
28+
29+
ALL_LANGS={
30+
'ar' => 'ar', # Arabic
31+
'de' => 'de', # German
32+
'es' => 'es', # Spanish
33+
'fr' => 'fr', # French
34+
'he' => 'he', # Hebrew
35+
'id' => 'id', # Indonesian
36+
'it' => 'it', # Italian
37+
'ja' => 'ja', # Japanese
38+
'ko' => 'ko', # Korean
39+
'nl' => 'nl', # Dutch
40+
'pt-br' => 'pt-BR', # Portuguese (Brazil)
41+
'ru' => 'ru', # Russian
42+
'sv' => 'sv', # Swedish
43+
'tr' => 'tr', # Turkish
44+
'zh-cn' => 'zh-Hans', # Chinese (China)
45+
'zh-tw' => 'zh-Hant', # Chinese (Taiwan)
46+
}
47+
48+
langs = {}
49+
if ARGV.count > 0
50+
for key in ARGV
51+
unless local = ALL_LANGS[key]
52+
puts "Unknown language #{key}"
53+
exit 1
54+
end
55+
langs[key] = local
56+
end
57+
else
58+
langs = ALL_LANGS
59+
end
60+
61+
langs.each do |code,local|
62+
lang_dir = File.join('WooCommerce', 'Resources', "#{local}.lproj")
63+
puts "Updating #{code}"
64+
system "mkdir -p #{lang_dir}"
65+
system "if [ -e #{lang_dir}/Localizable.strings ]; then cp #{lang_dir}/Localizable.strings #{lang_dir}/Localizable.strings.bak; fi"
66+
system "curl -fso #{lang_dir}/Localizable.strings 'https://translate.wordpress.com/projects/woocommerce%2Fwoocommerce-ios/#{code}/default/export-translations?format=strings'" or begin
67+
puts "Error downloading #{code}"
68+
end
69+
system "./Scripts/fix-translation #{lang_dir}/Localizable.strings"
70+
system "plutil -lint #{lang_dir}/Localizable.strings" and system "rm #{lang_dir}/Localizable.strings.bak"
71+
system "grep -a '\\x00\\x20\\x00\\x22\\x00\\x22\\x00\\x3b$' #{lang_dir}/Localizable.strings"
72+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
/* Class = "UITabBarItem"; title = "Item"; ObjectID = "8Hc-T2-dpT"; */
3+
"8Hc-T2-dpT.title" = "Item";
4+
5+
/* Class = "UITabBarItem"; title = "Item"; ObjectID = "a4j-YK-Adk"; */
6+
"a4j-YK-Adk.title" = "Item";
7+
8+
/* Class = "UITabBarItem"; title = "Item"; ObjectID = "etY-Vs-MSy"; */
9+
"etY-Vs-MSy.title" = "Item";

0 commit comments

Comments
 (0)