localio 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/lib/localio/localizable_writer.rb +5 -1
- data/lib/localio/templates/swift_constant_localizable.erb +11 -0
- data/lib/localio/version.rb +1 -1
- data/lib/localio/writers/swift_writer.rb +52 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdd3d840e27f6923ad8fd8ddd0e9f69f95d2562c
|
4
|
+
data.tar.gz: 93e138747d484545e9ed2622e14299f724b5e6f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcfc1620fcbd10f7b21eeb7100570492ab830465404e5ac4be9250a3e6abc3510bec5cfbac295545f8353e048766e209bb55689d615a8902a73fb0236605bb02
|
7
|
+
data.tar.gz: 0442d761f8a0adba2be7cc2653c746acda122a43a2cc5e3d0170a395b0f88bf5c98b4c231f2aca25ba8be27ab4befd8d3c4ce6fbb296d3db068fe59123c31418
|
data/README.md
CHANGED
@@ -71,7 +71,8 @@ Option | Description
|
|
71
71
|
#### Supported platforms
|
72
72
|
|
73
73
|
* `:android` for Android string.xml files. The `output_path` needed is the path for the `res` directory.
|
74
|
-
* `:ios` for iOS Localizable.strings files. The `output_path` needed is base directory where `en.lproj/` and such would go.
|
74
|
+
* `:ios` for iOS Localizable.strings files. The `output_path` needed is base directory where `en.lproj/` and such would go. Also creates header file with Objective-C macros.
|
75
|
+
* `:swift` for iOS Localizable.strings files. The `output_path` needed is base directory where `en.lproj/` and such would go. Also creates source file with Swift constants.
|
75
76
|
* `:rails` for Rails YAML files. The `output_path` needed is your `config/locales` directory.
|
76
77
|
* `:json` for an easy JSON format for localizables. The `output_path` is yours to decide :)
|
77
78
|
* `:java_properties` for .properties files used mainly in Java. Files named language_(lang).properties will be generated in `output_path`'s root directory.
|
@@ -145,15 +146,15 @@ If you don't specify a formatter for keys, :smart will be used.
|
|
145
146
|
|
146
147
|
Here you have some examples on how the behavior would be:
|
147
148
|
|
148
|
-
Platform
|
149
|
-
|
150
|
-
`:none`
|
151
|
-
`:snake_case`
|
152
|
-
`:camel_case`
|
153
|
-
`:smart` (ios)
|
154
|
-
`:smart` (android)
|
155
|
-
`:smart` (ruby)
|
156
|
-
`:smart` (json)
|
149
|
+
Platform | "App name" | "ANOTHER_KIND_OF_KEY"
|
150
|
+
---------------------|--------------|----------------------
|
151
|
+
`:none` | `App name` | `ANOTHER_KIND_OF_KEY`
|
152
|
+
`:snake_case` | `app_name` | `another_kind_of_key`
|
153
|
+
`:camel_case` | `appName` | `AnotherKindOfKey`
|
154
|
+
`:smart` (ios/swift) | `_App_name` | `_Another_kind_of_key`
|
155
|
+
`:smart` (android) | `app_name` | `another_kind_of_key`
|
156
|
+
`:smart` (ruby) | `app_name` | `another_kind_of_key`
|
157
|
+
`:smart` (json) | `app_name` | `another_kind_of_key`
|
157
158
|
|
158
159
|
Example of use:
|
159
160
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'localio/writers/android_writer'
|
2
2
|
require 'localio/writers/ios_writer'
|
3
|
+
require 'localio/writers/swift_writer'
|
3
4
|
require 'localio/writers/json_writer'
|
4
5
|
require 'localio/writers/rails_writer'
|
5
6
|
require 'localio/writers/java_properties_writer'
|
6
7
|
|
8
|
+
|
7
9
|
module LocalizableWriter
|
8
10
|
def self.write(platform, languages, terms, path, formatter, options)
|
9
11
|
case platform
|
@@ -11,6 +13,8 @@ module LocalizableWriter
|
|
11
13
|
AndroidWriter.write languages, terms, path, formatter, options
|
12
14
|
when :ios
|
13
15
|
IosWriter.write languages, terms, path, formatter, options
|
16
|
+
when :swift
|
17
|
+
SwiftWriter.write languages, terms, path, formatter, options
|
14
18
|
when :json
|
15
19
|
JsonWriter.write languages, terms, path, formatter, options
|
16
20
|
when :rails
|
@@ -21,4 +25,4 @@ module LocalizableWriter
|
|
21
25
|
raise ArgumentError, 'Platform not supported! Current possibilities are :android, :ios, :json, :rails, :java_properties'
|
22
26
|
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/*
|
2
|
+
LocalizableConstants.swift
|
3
|
+
|
4
|
+
GENERATED - DO NOT MODIFY - use localio instead.
|
5
|
+
|
6
|
+
Created by localio on <%= Time.now.localtime %>.
|
7
|
+
*/
|
8
|
+
|
9
|
+
<% @segments.each do |term| %>
|
10
|
+
let <%= term.key %>: String = { return NSLocalizedString("<%= term.translation %>", comment: "") }()<%
|
11
|
+
end %>
|
data/lib/localio/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'localio/template_handler'
|
2
|
+
require 'localio/segments_list_holder'
|
3
|
+
require 'localio/segment'
|
4
|
+
require 'localio/formatter'
|
5
|
+
|
6
|
+
class SwiftWriter
|
7
|
+
def self.write(languages, terms, path, formatter, options)
|
8
|
+
puts 'Writing iOS translations...'
|
9
|
+
|
10
|
+
constant_segments = nil
|
11
|
+
languages.keys.each do |lang|
|
12
|
+
output_path = File.join(path, "#{lang}.lproj/")
|
13
|
+
|
14
|
+
# We have now to iterate all the terms for the current language, extract them, and store them into a new array
|
15
|
+
|
16
|
+
segments = SegmentsListHolder.new lang
|
17
|
+
constant_segments = SegmentsListHolder.new lang
|
18
|
+
terms.each do |term|
|
19
|
+
key = Formatter.format(term.keyword, formatter, method(:swift_key_formatter))
|
20
|
+
translation = term.values[lang]
|
21
|
+
segment = Segment.new(key, translation, lang)
|
22
|
+
segment.key = nil if term.is_comment?
|
23
|
+
segments.segments << segment
|
24
|
+
|
25
|
+
unless term.is_comment?
|
26
|
+
constant_key = swift_constant_formatter term.keyword
|
27
|
+
constant_value = key
|
28
|
+
constant_segment = Segment.new(constant_key, constant_value, lang)
|
29
|
+
constant_segments.segments << constant_segment
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
TemplateHandler.process_template 'ios_localizable.erb', output_path, 'Localizable.strings', segments
|
34
|
+
puts " > #{lang.yellow}"
|
35
|
+
end
|
36
|
+
|
37
|
+
unless constant_segments.nil?
|
38
|
+
TemplateHandler.process_template 'swift_constant_localizable.erb', path, 'LocalizableConstants.swift', constant_segments
|
39
|
+
puts ' > ' + 'LocalizableConstants.swift'.yellow
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.swift_key_formatter(key)
|
46
|
+
'_'+key.space_to_underscore.strip_tag.capitalize
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.swift_constant_formatter(key)
|
50
|
+
'kLocale'+key.space_to_underscore.strip_tag.camel_case
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nacho Lopez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/localio/templates/java_properties_localizable.erb
|
159
159
|
- lib/localio/templates/json_localizable.erb
|
160
160
|
- lib/localio/templates/rails_localizable.erb
|
161
|
+
- lib/localio/templates/swift_constant_localizable.erb
|
161
162
|
- lib/localio/term.rb
|
162
163
|
- lib/localio/version.rb
|
163
164
|
- lib/localio/writers/android_writer.rb
|
@@ -165,6 +166,7 @@ files:
|
|
165
166
|
- lib/localio/writers/java_properties_writer.rb
|
166
167
|
- lib/localio/writers/json_writer.rb
|
167
168
|
- lib/localio/writers/rails_writer.rb
|
169
|
+
- lib/localio/writers/swift_writer.rb
|
168
170
|
- localio.gemspec
|
169
171
|
homepage: http://github.com/mrmans0n/localio
|
170
172
|
licenses:
|