localio-simonz 0.0.21.pre.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 +7 -0
- data/.gitignore +20 -0
- data/CONTRIBUTING.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +197 -0
- data/Rakefile +9 -0
- data/bin/localize +11 -0
- data/lib/localio.rb +61 -0
- data/lib/localio/filter.rb +43 -0
- data/lib/localio/formatter.rb +20 -0
- data/lib/localio/localizable_writer.rb +28 -0
- data/lib/localio/locfile.rb +65 -0
- data/lib/localio/module.rb +15 -0
- data/lib/localio/processor.rb +18 -0
- data/lib/localio/processors/google_drive_processor.rb +105 -0
- data/lib/localio/processors/xls_processor.rb +84 -0
- data/lib/localio/processors/xlsx_processor.rb +82 -0
- data/lib/localio/segment.rb +14 -0
- data/lib/localio/segments_list_holder.rb +12 -0
- data/lib/localio/string_helper.rb +64 -0
- data/lib/localio/template_handler.rb +21 -0
- data/lib/localio/templates/android_localizable.erb +11 -0
- data/lib/localio/templates/ios_constant_localizable.erb +11 -0
- data/lib/localio/templates/ios_localizable.erb +17 -0
- data/lib/localio/templates/java_properties_localizable.erb +10 -0
- data/lib/localio/templates/json_localizable.erb +16 -0
- data/lib/localio/templates/rails_localizable.erb +13 -0
- data/lib/localio/templates/swift_constant_localizable.erb +11 -0
- data/lib/localio/term.rb +14 -0
- data/lib/localio/version.rb +3 -0
- data/lib/localio/writers/android_writer.rb +42 -0
- data/lib/localio/writers/ios_writer.rb +56 -0
- data/lib/localio/writers/java_properties_writer.rb +37 -0
- data/lib/localio/writers/json_writer.rb +38 -0
- data/lib/localio/writers/rails_writer.rb +38 -0
- data/lib/localio/writers/swift_writer.rb +56 -0
- data/localio.gemspec +35 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fc78f3e23be709d44107ef9688dce80205afa7d
|
4
|
+
data.tar.gz: f1cd5ac9842b97da9c10208321317718354e0da2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0231862b3e735f05157493e5f9f43d6217f94507e9ca8e017c9aac4ee68025bd52505aa3688452ffd4526abc9c450491efe017fc89807e735b0a3dd4a297ab82
|
7
|
+
data.tar.gz: 5933d8278a4ca90c37b949e3e664318f5eca0e7934fabd3ad580913bbb3760442f55a9d04bd2bcf852e0372b588ec98970cf5340072feb8bdecf74e628d84cdc
|
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nacho L.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# Localio
|
2
|
+
|
3
|
+
Localio generates automatically localizable files for many platforms like Rails, Android, iOS, Java .properties files and JSON files using a centralized spreadsheet as source. The spreadsheet can be in Google Drive or a simple local Excel file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'localio'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install localio
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You have to create a custom file, Locfile, similar to Rakefile or Gemfile, with some information for this to work. Also you must have some spreadsheet with a particular format, either in Google Drive or in Excel (XLS or XLSX) format.
|
22
|
+
|
23
|
+
In your Locfile directory you can then execute
|
24
|
+
|
25
|
+
````
|
26
|
+
localize
|
27
|
+
````
|
28
|
+
|
29
|
+
and your localizable files will be created with the parameters specified in the Locfile.
|
30
|
+
|
31
|
+
You can also specify in the first parameter a file with another name, and it will work as well.
|
32
|
+
|
33
|
+
### The Spreadsheet
|
34
|
+
|
35
|
+
You will need a little spreadsheet with all the localization literals and their intended keys for internal use while coding.
|
36
|
+
|
37
|
+
There is a basic example in this Google Drive link: [https://docs.google.com/spreadsheet/ccc?key=0AmX_w4-5HkOgdFFoZ19iSUlRSERnQTJ4NVZiblo2UXc&usp=sharing](https://docs.google.com/spreadsheet/ccc?key=0AmX_w4-5HkOgdFFoZ19iSUlRSERnQTJ4NVZiblo2UXc&usp=sharing). You just have to duplicate and save to your account, or download and save it as XLS file.
|
38
|
+
|
39
|
+
**NOTE** Localio will only search for translations on the first worksheet of the spreadsheet.
|
40
|
+
|
41
|
+
### Locfile
|
42
|
+
|
43
|
+
A minimal `Locfile` example could be:
|
44
|
+
|
45
|
+
````ruby
|
46
|
+
platform :ios
|
47
|
+
|
48
|
+
output_path 'out/'
|
49
|
+
|
50
|
+
source :google_drive,
|
51
|
+
:spreadsheet => '[Localizables] My Project!',
|
52
|
+
:login => 'your_email@gmail.com',
|
53
|
+
:password => 'your_password'
|
54
|
+
|
55
|
+
formatting :smart # This is optional, formatting :smart is used by default.
|
56
|
+
````
|
57
|
+
|
58
|
+
This would connect localio to your Google Drive and process the spreadsheet with title "[Localizables] My Project!".
|
59
|
+
|
60
|
+
The list of possible commands is this.
|
61
|
+
|
62
|
+
Option | Description | Default
|
63
|
+
----------------------------|------------------------------------------------------------------|--------
|
64
|
+
`platform` | (Req.) Target platform for the localizable files. | `nil`
|
65
|
+
`source` | (Req.) Information on where to find the spreadsheet w/ the info | `nil`
|
66
|
+
`output_path` | (Req.) Target directory for the localizables. | `out/`
|
67
|
+
`formatting` | The formatter that will be used for key processing. | `smart`
|
68
|
+
`except` | Filter applied to the keys, process all except the matches. | `nil`
|
69
|
+
`only` | Filter applied to the keys, only process the matches. | `nil`
|
70
|
+
|
71
|
+
#### Supported platforms
|
72
|
+
|
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. 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.
|
76
|
+
* `:rails` for Rails YAML files. The `output_path` needed is your `config/locales` directory.
|
77
|
+
* `:json` for an easy JSON format for localizables. The `output_path` is yours to decide :)
|
78
|
+
* `:java_properties` for .properties files used mainly in Java. Files named language_(lang).properties will be generated in `output_path`'s root directory.
|
79
|
+
|
80
|
+
#### Supported sources
|
81
|
+
|
82
|
+
##### Google Drive
|
83
|
+
|
84
|
+
`source :google_drive` will get the translation strings from Google Drive.
|
85
|
+
|
86
|
+
You will have to provide some required parameters too. Here is a list of all the parameters.
|
87
|
+
|
88
|
+
Option | Description
|
89
|
+
----------------------------|-------------------------------------------------------------------------
|
90
|
+
`:spreadsheet` | (Req.) Title of the spreadsheet you want to use. Can be a partial match.
|
91
|
+
`:login` | (Req.) Your Google login.
|
92
|
+
`:password` | (Req.) Your Google password.
|
93
|
+
|
94
|
+
**NOTE** As it is a very bad practice to put your login and your password in a plain file, specially when you would want to upload your project to some repository, it is **VERY RECOMMENDED** that you use environment variables in here. Ruby syntax is accepted so you can use `ENV['GOOGLE_LOGIN']` and `ENV['GOOGLE_PASSWORD']` in here.
|
95
|
+
|
96
|
+
For example, this.
|
97
|
+
|
98
|
+
````ruby
|
99
|
+
source :google_drive,
|
100
|
+
:spreadsheet => '[Localizables] My Project!',
|
101
|
+
:login => ENV['GOOGLE_LOGIN'],
|
102
|
+
:password => ENV['GOOGLE_PASSWORD']
|
103
|
+
````
|
104
|
+
|
105
|
+
And in your .bashrc (or .bash_profile, .zshrc or whatever), you could export those environment variables like this:
|
106
|
+
|
107
|
+
````ruby
|
108
|
+
export GOOGLE_LOGIN="your_login"
|
109
|
+
export GOOGLE_PASSWORD="your_password"
|
110
|
+
````
|
111
|
+
|
112
|
+
##### XLS
|
113
|
+
|
114
|
+
`source :xls` will use a local XLS file. In the parameter's hash you should specify a `:path`.
|
115
|
+
|
116
|
+
Option | Description
|
117
|
+
----------------------------|-------------------------------------------------------------------------
|
118
|
+
`:path` | (Req.) Path for your XLS file.
|
119
|
+
|
120
|
+
````ruby
|
121
|
+
source :xls,
|
122
|
+
:path => 'YourExcelFileWithTranslations.xls'
|
123
|
+
````
|
124
|
+
|
125
|
+
##### XLSX
|
126
|
+
|
127
|
+
`source :xlsx` will use a local XLSX file. In the parameter's hash you should specify a `:path`.
|
128
|
+
|
129
|
+
Option | Description
|
130
|
+
----------------------------|-------------------------------------------------------------------------
|
131
|
+
`:path` | (Req.) Path for your XLSX file.
|
132
|
+
|
133
|
+
````ruby
|
134
|
+
source :xlsx,
|
135
|
+
:path => 'YourExcelFileWithTranslations.xlsx'
|
136
|
+
````
|
137
|
+
|
138
|
+
#### Key formatters
|
139
|
+
|
140
|
+
If you don't specify a formatter for keys, :smart will be used.
|
141
|
+
|
142
|
+
* `:none` for no formatting.
|
143
|
+
* `:snake_case` for snake case formatting (ie "this_kind_of_key").
|
144
|
+
* `:camel_case` for camel case formatting (ie "ThisKindOfKey").
|
145
|
+
* `:smart` use a different formatting depending on the platform.
|
146
|
+
|
147
|
+
Here you have some examples on how the behavior would be:
|
148
|
+
|
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`
|
158
|
+
|
159
|
+
Example of use:
|
160
|
+
|
161
|
+
````ruby
|
162
|
+
formatting :camel_case
|
163
|
+
````
|
164
|
+
|
165
|
+
Normally you would want a smart formatter, because it is adjusted (or tries to) to the usual code conventions of each platform for localizable strings.
|
166
|
+
|
167
|
+
### Advanced options
|
168
|
+
|
169
|
+
#### Filtering content
|
170
|
+
|
171
|
+
We can establish filters to the keys by using regular expressions.
|
172
|
+
|
173
|
+
The exclusions are managed with the `except` command. For example, if we don't want to include the translations where the key has the "[a]" string, we could include this in the Locfile.
|
174
|
+
|
175
|
+
````ruby
|
176
|
+
except :keys => '[\[][a][\]]'
|
177
|
+
````
|
178
|
+
|
179
|
+
We can filter inversely too, with the command `only`. For example, if we only want the translations that contain the '[a]' token, we should use:
|
180
|
+
|
181
|
+
````ruby
|
182
|
+
only :keys => '[\[][a][\]]'
|
183
|
+
````
|
184
|
+
|
185
|
+
#### Overriding default language
|
186
|
+
|
187
|
+
This only makes sense with `platform :android` at the moment. If we want to override (for whatever reason) the default language flag in the source spreadsheet, we can use `:override_default => 'language'`.
|
188
|
+
|
189
|
+
For example, if we wanted to override the default (english) and use spanish instead, we could do this:
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
platform :android, :override_default => 'es'
|
193
|
+
```
|
194
|
+
|
195
|
+
## Contributing
|
196
|
+
|
197
|
+
Please read the [contributing guide](https://github.com/mrmans0n/localio/blob/master/CONTRIBUTING.md).
|
data/Rakefile
ADDED
data/bin/localize
ADDED
data/lib/localio.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'localio/version'
|
2
|
+
require 'localio/locfile'
|
3
|
+
require 'localio/processor'
|
4
|
+
require 'localio/localizable_writer'
|
5
|
+
require 'localio/filter'
|
6
|
+
|
7
|
+
module Localio
|
8
|
+
|
9
|
+
def self.from_cmdline(args)
|
10
|
+
if args.empty?
|
11
|
+
if File.exist? 'Locfile'
|
12
|
+
process_locfile('Locfile')
|
13
|
+
else
|
14
|
+
raise ArgumentError, 'Locfile not found in current directory, and no compatible file supplied in arguments.'
|
15
|
+
end
|
16
|
+
else
|
17
|
+
process_locfile(args.shift)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_configuration(configuration)
|
22
|
+
@configuration = configuration
|
23
|
+
generate_localizables
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.process_locfile(path)
|
29
|
+
@configuration = Locfile.load(path)
|
30
|
+
generate_localizables
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.generate_localizables
|
34
|
+
process_to_memory
|
35
|
+
apply_filters
|
36
|
+
build_localizables
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.process_to_memory
|
40
|
+
@localizables = Processor.load_localizables @configuration.platform_options,
|
41
|
+
@configuration.source_service,
|
42
|
+
@configuration.source_options
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.apply_filters
|
46
|
+
@localizables[:segments] = Filter.apply_filter @localizables[:segments],
|
47
|
+
@configuration.only,
|
48
|
+
@configuration.except
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.build_localizables
|
52
|
+
LocalizableWriter.write @configuration.platform_name,
|
53
|
+
@localizables[:languages],
|
54
|
+
@localizables[:segments],
|
55
|
+
@configuration.output_path,
|
56
|
+
@configuration.formatting,
|
57
|
+
:default_language => @localizables[:default_language]
|
58
|
+
puts 'Done!'.green
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Filter
|
2
|
+
def self.apply_filter(segments, only, except)
|
3
|
+
|
4
|
+
segments = only segments, only[:keys] unless only.nil?
|
5
|
+
segments = except segments, except[:keys] unless except.nil?
|
6
|
+
|
7
|
+
segments
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.only segments, keys_filter
|
13
|
+
|
14
|
+
filtered_segments = []
|
15
|
+
segments.each do |segment|
|
16
|
+
is_okay = true
|
17
|
+
unless keys_filter.nil?
|
18
|
+
result = /#{keys_filter}/ =~ segment.keyword
|
19
|
+
is_okay = false if result.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
filtered_segments << segment if is_okay
|
23
|
+
end
|
24
|
+
|
25
|
+
filtered_segments
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.except segments, keys_filter
|
29
|
+
filtered_segments = []
|
30
|
+
segments.each do |segment|
|
31
|
+
is_okay = true
|
32
|
+
unless keys_filter.nil?
|
33
|
+
result = /#{keys_filter}/ =~ segment.keyword
|
34
|
+
is_okay = false unless result.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
filtered_segments << segment if is_okay
|
38
|
+
end
|
39
|
+
|
40
|
+
filtered_segments
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'localio/string_helper'
|
2
|
+
|
3
|
+
module Formatter
|
4
|
+
def self.format(key, formatter, callback)
|
5
|
+
case formatter
|
6
|
+
when :smart
|
7
|
+
# Smart formatting is given by the processor.
|
8
|
+
# I don't like this very much but creating more classes seemed overkill.
|
9
|
+
callback.call(key)
|
10
|
+
when :none
|
11
|
+
key
|
12
|
+
when :camel_case
|
13
|
+
key.space_to_underscore.strip_tag.camel_case
|
14
|
+
when :snake_case
|
15
|
+
key.space_to_underscore.strip_tag.downcase
|
16
|
+
else
|
17
|
+
raise ArgumentError, 'Unknown formatting used. Must use :smart, :none, :camel_case or :snake_case'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'localio/writers/android_writer'
|
2
|
+
require 'localio/writers/ios_writer'
|
3
|
+
require 'localio/writers/swift_writer'
|
4
|
+
require 'localio/writers/json_writer'
|
5
|
+
require 'localio/writers/rails_writer'
|
6
|
+
require 'localio/writers/java_properties_writer'
|
7
|
+
|
8
|
+
|
9
|
+
module LocalizableWriter
|
10
|
+
def self.write(platform, languages, terms, path, formatter, options)
|
11
|
+
case platform
|
12
|
+
when :android
|
13
|
+
AndroidWriter.write languages, terms, path, formatter, options
|
14
|
+
when :ios
|
15
|
+
IosWriter.write languages, terms, path, formatter, options
|
16
|
+
when :swift
|
17
|
+
SwiftWriter.write languages, terms, path, formatter, options
|
18
|
+
when :json
|
19
|
+
JsonWriter.write languages, terms, path, formatter, options
|
20
|
+
when :rails
|
21
|
+
RailsWriter.write languages, terms, path, formatter, options
|
22
|
+
when :java_properties
|
23
|
+
JavaPropertiesWriter.write languages, terms, path, formatter, options
|
24
|
+
else
|
25
|
+
raise ArgumentError, 'Platform not supported! Current possibilities are :android, :ios, :json, :rails, :java_properties'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|