xcmultilingual 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/DemoApp/DemoApp.xcworkspace/xcuserdata/moritanaoki.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/DemoApp/DemoApp/Multilingual.swift +1 -1
- data/DemoApp/custom_template.erb +44 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/xcmultilingual/cli.rb +2 -1
- data/lib/xcmultilingual/version.rb +1 -1
- data/lib/xcmultilingual/writer.rb +6 -9
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80dd2cbcb739918e3734f51840bf3b0164a58ce8
|
4
|
+
data.tar.gz: e1becbf16ff9b941cf28b31c56f9ce9295760669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 987a6e66a6b0dbb402adcfc3a1fa2d6d5c2a80dd22ca067f8efdf208e051bddca39397224bfc84bea309ab75d6663ab9ea84adcf957bf88b4d5ec4c16841a025
|
7
|
+
data.tar.gz: 66b8bc6153b88c37565b9f6e10693b6b96a7add952e16605dc1e06293f322d1bd334811ca66c2d798d1d6164a2335cd1d3af951e96271994c9d48f3c141765df
|
data/DemoApp/DemoApp.xcworkspace/xcuserdata/moritanaoki.xcuserdatad/UserInterfaceState.xcuserstate
CHANGED
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
//
|
2
|
+
// <%= @filename %>
|
3
|
+
// xcmultilingual - Custom
|
4
|
+
//
|
5
|
+
// Created by xcmultilingual.
|
6
|
+
//
|
7
|
+
//
|
8
|
+
|
9
|
+
import Foundation
|
10
|
+
|
11
|
+
struct <%= @name %> {
|
12
|
+
<% @bundle_data.each do |bundle| -%>
|
13
|
+
<% nsbundle = bundle.name ? "Multilingual.bundle(\"#{bundle.relative_path}\")" : "NSBundle.mainBundle()" -%>
|
14
|
+
<% bundle_name = bundle.name.nil? ? "" : bundle.name.capitalize -%>
|
15
|
+
<% bundle.tables.each do |table| -%>
|
16
|
+
<% class_name = bundle_name + table.name -%>
|
17
|
+
enum <%= class_name %>: String {
|
18
|
+
<% table.keys.each do |key| -%>
|
19
|
+
case <%= key %> = "<%= key %>"
|
20
|
+
<% end # keys -%>
|
21
|
+
|
22
|
+
func string() -> String {
|
23
|
+
return NSLocalizedString(rawValue, tableName: "<%= table.name %>", bundle: <%= nsbundle %>, value: "\(rawValue)", comment: "")
|
24
|
+
}
|
25
|
+
|
26
|
+
static func keys() -> [String] {
|
27
|
+
return ["<%= table.keys.join("\", \"") %>"]
|
28
|
+
}
|
29
|
+
|
30
|
+
static func localizations() -> [String] {
|
31
|
+
return <%= class_name %>.keys().map { <%= class_name %>(rawValue: $0)!.string() }
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
<%- end # table -%>
|
36
|
+
<%- end # bundle -%>
|
37
|
+
|
38
|
+
private static func bundle(relativePath: String) -> NSBundle {
|
39
|
+
var components = (__FILE__ as String).pathComponents
|
40
|
+
components.removeLast()
|
41
|
+
let bundlePath = join("/", components) + "/" + relativePath
|
42
|
+
return NSBundle(path: bundlePath) ?? NSBundle.mainBundle()
|
43
|
+
}
|
44
|
+
}
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -137,6 +137,7 @@ Easy!
|
|
137
137
|
|
138
138
|
options:
|
139
139
|
- `-name` or `-n`: Change Localization struct name. Default is Multilingual.
|
140
|
+
- `-template` or `-t`: Use custom template for generating swift file. You can copy original and change where you want!
|
140
141
|
- `--verbose`: Output execution logs
|
141
142
|
|
142
143
|
**help:** Write `update` after help and show update options' help.
|
data/lib/xcmultilingual/cli.rb
CHANGED
@@ -7,8 +7,8 @@ module Xcmultilingual
|
|
7
7
|
class_option :verbose, :type => :boolean
|
8
8
|
|
9
9
|
desc "update DESTINATION", "update xcmultilingual swift file"
|
10
|
-
# option :destination, :aliases => "-d", :required => true, :desc => "generating file destination"
|
11
10
|
option :name, :aliases => "-n", :default => "Multilingual", :desc => "Localization struct name"
|
11
|
+
option :template_path, :aliases => "-t", :desc => "User generated template file path"
|
12
12
|
def update(destination)
|
13
13
|
parser = Parser.new(destination)
|
14
14
|
parser.verbose = options[:verbose] || false
|
@@ -16,6 +16,7 @@ module Xcmultilingual
|
|
16
16
|
|
17
17
|
writer = Writer.new(destination, bundle_data)
|
18
18
|
writer.name = options[:name]
|
19
|
+
writer.template_path = options[:template_path] if options[:template_path]
|
19
20
|
writer.verbose = options[:verbose] || false
|
20
21
|
writer.write
|
21
22
|
|
@@ -2,11 +2,12 @@ require 'erb'
|
|
2
2
|
|
3
3
|
module Xcmultilingual
|
4
4
|
class Writer
|
5
|
-
attr_accessor :name, :verbose
|
5
|
+
attr_accessor :name, :template_path, :verbose
|
6
6
|
|
7
7
|
def initialize(destination, bundle_data)
|
8
8
|
@destination = destination
|
9
9
|
@bundle_data = bundle_data
|
10
|
+
@template_path = template_path()
|
10
11
|
@filename = File.basename(@destination)
|
11
12
|
end
|
12
13
|
|
@@ -20,8 +21,8 @@ module Xcmultilingual
|
|
20
21
|
end
|
21
22
|
|
22
23
|
File.open("#{@destination}", "w") do |file|
|
23
|
-
|
24
|
-
body = ERB.new(File.open(
|
24
|
+
path = File.expand_path(@template_path)
|
25
|
+
body = ERB.new(File.open(path).read, nil, '-').result(binding)
|
25
26
|
file.write(body)
|
26
27
|
end
|
27
28
|
puts "+ END UPDATING\n\n" if @verbose
|
@@ -29,12 +30,8 @@ module Xcmultilingual
|
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
def
|
33
|
-
File.dirname(__FILE__) + '/templates'
|
34
|
-
end
|
35
|
-
|
36
|
-
def templates_file(dir)
|
37
|
-
dir + "/swift.erb"
|
33
|
+
def template_path()
|
34
|
+
File.dirname(__FILE__) + '/templates/swift.erb'
|
38
35
|
end
|
39
36
|
end
|
40
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcmultilingual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoki Morita
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- DemoApp/Pods/Target Support Files/Pods/Pods.debug.xcconfig
|
178
178
|
- DemoApp/Pods/Target Support Files/Pods/Pods.modulemap
|
179
179
|
- DemoApp/Pods/Target Support Files/Pods/Pods.release.xcconfig
|
180
|
+
- DemoApp/custom_template.erb
|
180
181
|
- Gemfile
|
181
182
|
- Gemfile.lock
|
182
183
|
- LICENSE
|