xcmultilingual 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DemoApp/DemoApp/Multilingual.swift +20 -16
- data/DemoApp/DemoApp/ViewController.swift +12 -12
- data/Gemfile.lock +1 -1
- data/lib/xcmultilingual/bundle.rb +9 -3
- data/lib/xcmultilingual/cli.rb +4 -1
- data/lib/xcmultilingual/parser.rb +3 -6
- data/lib/xcmultilingual/templates/swift.erb +8 -7
- data/lib/xcmultilingual/version.rb +1 -1
- data/lib/xcmultilingual/writer.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da9fbf5ba45832c00e8cee478c30c1e7f56059c9
|
4
|
+
data.tar.gz: d4fa56b66ea906b632dbdaa94573daa1d576e85e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2a5c99476070187fadce16261b3e96901ef50dd65da776444035293b4c5a1ac90a8763ba40b04081b7bf96c24dc5d8b03bad1c9f8bf92cb3b7a695f87ffaf10
|
7
|
+
data.tar.gz: 6611c99675c2c1e0cce6f7722f432ab51555bfbc33642bd20bd2d60d74d74468f0796c371b1667be07a0f60b68090d84afd8b1ff4947cb917dece78a4ca15020
|
@@ -28,12 +28,13 @@ struct Multilingual {
|
|
28
28
|
return NSLocalizedString(rawValue, tableName: "Animal", bundle: NSBundle.mainBundle(), value: "\(rawValue)", comment: "")
|
29
29
|
}
|
30
30
|
|
31
|
-
static
|
31
|
+
static let name = "Animal"
|
32
|
+
|
33
|
+
static var keys: [String] {
|
32
34
|
return ["CAT", "DOG", "BEAR", "DEER", "SQUIRREL", "ELEPHANT", "GIRAFFE", "TIGER", "LION", "RABBIT", "RHINOCEROS", "GORILLA", "MONKEY"]
|
33
35
|
}
|
34
|
-
|
35
|
-
|
36
|
-
return Animal.keys().map { Animal(rawValue: $0)!.string() }
|
36
|
+
static var localizations: [String] {
|
37
|
+
return Animal.keys.map { Animal(rawValue: $0)!.string() }
|
37
38
|
}
|
38
39
|
}
|
39
40
|
|
@@ -46,12 +47,13 @@ struct Multilingual {
|
|
46
47
|
return NSLocalizedString(rawValue, tableName: "Localizable", bundle: NSBundle.mainBundle(), value: "\(rawValue)", comment: "")
|
47
48
|
}
|
48
49
|
|
49
|
-
static
|
50
|
+
static let name = "Localizable"
|
51
|
+
|
52
|
+
static var keys: [String] {
|
50
53
|
return ["HELLO", "GOODMORNING", "GOODEVENING"]
|
51
54
|
}
|
52
|
-
|
53
|
-
|
54
|
-
return Localizable.keys().map { Localizable(rawValue: $0)!.string() }
|
55
|
+
static var localizations: [String] {
|
56
|
+
return Localizable.keys.map { Localizable(rawValue: $0)!.string() }
|
55
57
|
}
|
56
58
|
}
|
57
59
|
|
@@ -62,12 +64,13 @@ struct Multilingual {
|
|
62
64
|
return NSLocalizedString(rawValue, tableName: "Sample Localization", bundle: Multilingual.bundle("Loalizations/sample2.bundle"), value: "\(rawValue)", comment: "")
|
63
65
|
}
|
64
66
|
|
65
|
-
static
|
67
|
+
static let name = "Sample Localization"
|
68
|
+
|
69
|
+
static var keys: [String] {
|
66
70
|
return ["SAMPLE 2"]
|
67
71
|
}
|
68
|
-
|
69
|
-
|
70
|
-
return Sample2Sample_Localization.keys().map { Sample2Sample_Localization(rawValue: $0)!.string() }
|
72
|
+
static var localizations: [String] {
|
73
|
+
return Sample2Sample_Localization.keys.map { Sample2Sample_Localization(rawValue: $0)!.string() }
|
71
74
|
}
|
72
75
|
}
|
73
76
|
|
@@ -78,12 +81,13 @@ struct Multilingual {
|
|
78
81
|
return NSLocalizedString(rawValue, tableName: "Sample", bundle: Multilingual.bundle("sample.bundle"), value: "\(rawValue)", comment: "")
|
79
82
|
}
|
80
83
|
|
81
|
-
static
|
84
|
+
static let name = "Sample"
|
85
|
+
|
86
|
+
static var keys: [String] {
|
82
87
|
return ["SAMPLE"]
|
83
88
|
}
|
84
|
-
|
85
|
-
|
86
|
-
return SampleSample.keys().map { SampleSample(rawValue: $0)!.string() }
|
89
|
+
static var localizations: [String] {
|
90
|
+
return SampleSample.keys.map { SampleSample(rawValue: $0)!.string() }
|
87
91
|
}
|
88
92
|
}
|
89
93
|
|
@@ -23,24 +23,24 @@ class ViewController: UITableViewController {
|
|
23
23
|
|
24
24
|
let tables = [
|
25
25
|
Table(
|
26
|
-
name:
|
27
|
-
keys: Multilingual.Localizable.keys
|
28
|
-
localizations: Multilingual.Localizable.localizations
|
26
|
+
name: Multilingual.Localizable.name,
|
27
|
+
keys: Multilingual.Localizable.keys,
|
28
|
+
localizations: Multilingual.Localizable.localizations
|
29
29
|
),
|
30
30
|
Table(
|
31
|
-
name:
|
32
|
-
keys: Multilingual.Animal.keys
|
33
|
-
localizations: Multilingual.Animal.localizations
|
31
|
+
name: Multilingual.Animal.name,
|
32
|
+
keys: Multilingual.Animal.keys,
|
33
|
+
localizations: Multilingual.Animal.localizations
|
34
34
|
),
|
35
35
|
Table(
|
36
|
-
name:
|
37
|
-
keys: Multilingual.SampleSample.keys
|
38
|
-
localizations: Multilingual.SampleSample.localizations
|
36
|
+
name: Multilingual.SampleSample.name,
|
37
|
+
keys: Multilingual.SampleSample.keys,
|
38
|
+
localizations: Multilingual.SampleSample.localizations
|
39
39
|
),
|
40
40
|
Table(
|
41
|
-
name:
|
42
|
-
keys: Multilingual.Sample2Sample_Localization.keys
|
43
|
-
localizations: Multilingual.Sample2Sample_Localization.localizations
|
41
|
+
name: Multilingual.Sample2Sample_Localization.name,
|
42
|
+
keys: Multilingual.Sample2Sample_Localization.keys,
|
43
|
+
localizations: Multilingual.Sample2Sample_Localization.localizations
|
44
44
|
)
|
45
45
|
]
|
46
46
|
}
|
data/Gemfile.lock
CHANGED
@@ -3,15 +3,21 @@ module Xcmultilingual
|
|
3
3
|
def description
|
4
4
|
name_description = name.nil? ? "MAIN BUNDLE" : name
|
5
5
|
relative_path_description = relative_path.nil? ? "NO RELATIVE PATH" : relative_path
|
6
|
-
tables_description = tables.map { |table| table.description }.join("")
|
7
|
-
"
|
6
|
+
tables_description = tables.map { |table| table.description }.join(" / ")
|
7
|
+
"[#{name_description}]\nname: #{name_description}, relative_path: #{relative_path_description}, tables: #{tables_description}"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
Table = Struct.new("Table", :name, :keys) do
|
12
12
|
def description
|
13
13
|
keys_description = keys.join(", ")
|
14
|
-
"
|
14
|
+
"[Table] name: #{name}, keys: #{keys_description}"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
class String
|
20
|
+
def safe
|
21
|
+
return self.gsub(" ", "_")
|
22
|
+
end
|
23
|
+
end
|
data/lib/xcmultilingual/cli.rb
CHANGED
@@ -20,10 +20,13 @@ module Xcmultilingual
|
|
20
20
|
writer.verbose = options[:verbose] || false
|
21
21
|
writer.write
|
22
22
|
|
23
|
-
puts "
|
23
|
+
puts "" if options[:verbose]
|
24
|
+
puts "+++ DONE ++++++++++++++++++++++++" if options[:verbose]
|
24
25
|
puts "" if options[:verbose]
|
25
26
|
puts " See #{destination}" if options[:verbose]
|
26
27
|
puts "" if options[:verbose]
|
28
|
+
puts "+++++++++++++++++++++++++++++++++" if options[:verbose]
|
29
|
+
puts "" if options[:verbose]
|
27
30
|
end
|
28
31
|
|
29
32
|
map %w[--version -v] => :__print_version
|
@@ -9,8 +9,7 @@ module Xcmultilingual
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def parse
|
12
|
-
puts "
|
13
|
-
puts "" if @verbose
|
12
|
+
puts "[START PARSING]" if @verbose
|
14
13
|
|
15
14
|
destination_path = File.expand_path(@destination)
|
16
15
|
destination_dir = File.dirname(destination_path)
|
@@ -41,7 +40,7 @@ module Xcmultilingual
|
|
41
40
|
safe_line = line.scrub('?')
|
42
41
|
if key = find_key(safe_line)
|
43
42
|
bundles[bundle_name][:tables][name] << key
|
44
|
-
puts "
|
43
|
+
puts "<#{File.basename(file_path)}> #{line}" if @verbose
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
@@ -54,13 +53,11 @@ module Xcmultilingual
|
|
54
53
|
bundle.tables << table
|
55
54
|
end
|
56
55
|
|
57
|
-
puts "" if @verbose
|
58
56
|
puts "#{bundle.description}" if @verbose
|
59
57
|
bundle_data << bundle
|
60
58
|
end
|
61
59
|
|
62
|
-
puts "" if @verbose
|
63
|
-
puts "+ PARSE SUCCEEDED" if @verbose
|
60
|
+
puts "[PARSE SUCCEEDED]" if @verbose
|
64
61
|
puts "" if @verbose
|
65
62
|
|
66
63
|
bundle_data
|
@@ -11,24 +11,25 @@ import Foundation
|
|
11
11
|
struct <%= @name %> {
|
12
12
|
<% @bundle_data.each do |bundle| -%>
|
13
13
|
<% nsbundle = bundle.name ? "Multilingual.bundle(\"#{bundle.relative_path}\")" : "NSBundle.mainBundle()" -%>
|
14
|
-
<% bundle_name = bundle.name.nil? ? "" : bundle.name.
|
14
|
+
<% bundle_name = bundle.name.nil? ? "" : bundle.name.safe.capitalize -%>
|
15
15
|
<% bundle.tables.each do |table| -%>
|
16
|
-
<% class_name = bundle_name + table.name.
|
16
|
+
<% class_name = bundle_name + table.name.safe -%>
|
17
17
|
enum <%= class_name %>: String {
|
18
18
|
<% table.keys.each do |key| -%>
|
19
|
-
case <%= key.
|
19
|
+
case <%= key.safe %> = "<%= key %>"
|
20
20
|
<% end # keys -%>
|
21
21
|
|
22
22
|
func string() -> String {
|
23
23
|
return NSLocalizedString(rawValue, tableName: "<%= table.name %>", bundle: <%= nsbundle %>, value: "\(rawValue)", comment: "")
|
24
24
|
}
|
25
25
|
|
26
|
-
static
|
26
|
+
static let name = "<%= table.name %>"
|
27
|
+
|
28
|
+
static var keys: [String] {
|
27
29
|
return ["<%= table.keys.join("\", \"") %>"]
|
28
30
|
}
|
29
|
-
|
30
|
-
|
31
|
-
return <%= class_name %>.keys().map { <%= class_name %>(rawValue: $0)!.string() }
|
31
|
+
static var localizations: [String] {
|
32
|
+
return <%= class_name %>.keys.map { <%= class_name %>(rawValue: $0)!.string() }
|
32
33
|
}
|
33
34
|
}
|
34
35
|
|
@@ -12,12 +12,12 @@ module Xcmultilingual
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def write
|
15
|
-
puts "
|
15
|
+
puts "[START UPDATING]" if @verbose
|
16
16
|
|
17
17
|
if !File.exist?("#{@destination}")
|
18
|
-
puts "
|
18
|
+
puts "There is no destination file." if @verbose
|
19
19
|
puts "\n+ FAILED UPDATING\n" if @verbose
|
20
|
-
|
20
|
+
exit 2
|
21
21
|
end
|
22
22
|
|
23
23
|
File.open("#{@destination}", "w") do |file|
|
@@ -25,7 +25,7 @@ module Xcmultilingual
|
|
25
25
|
body = ERB.new(File.open(path).read, nil, '-').result(binding)
|
26
26
|
file.write(body)
|
27
27
|
end
|
28
|
-
puts "
|
28
|
+
puts "[END UPDATING]" if @verbose
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|