localio 0.0.2 → 0.0.3
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/CONTRIBUTING.md +8 -0
- data/README.md +82 -19
- data/bin/localize +6 -1
- data/lib/localio.rb +1 -1
- data/lib/localio/formatter.rb +1 -1
- data/lib/localio/localizable_writer.rb +1 -1
- data/lib/localio/processor.rb +2 -2
- data/lib/localio/processors/google_drive_processor.rb +8 -8
- data/lib/localio/processors/xls_processor.rb +6 -6
- data/lib/localio/processors/xlsx_processor.rb +6 -6
- data/lib/localio/version.rb +1 -1
- data/localio.gemspec +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ab1bb80d6ff76d09f5a49870da6def8a557327c
|
4
|
+
data.tar.gz: 0d5ac9d5fbeacb0ae31ea0bffcb7ba5ad0e192e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfaeda3f347fef27740843416e499de7e0e634ab3cdece0c0bfd03ada9e789cd32bdbd6736a7469d847a911acc19ec85c33e3db614d0a8c4f7f5913aea055a25
|
7
|
+
data.tar.gz: ed4cc7851740012f89fedfcaeb00083d33cfd61a6f4e49f2fc49fc47328ee9439fa0d85d0126c58a625dbb13ba95c3d6479e15d42e14220a27641611a42d872b
|
data/CONTRIBUTING.md
ADDED
data/README.md
CHANGED
@@ -44,9 +44,11 @@ platform :ios
|
|
44
44
|
output_path 'out/'
|
45
45
|
|
46
46
|
source :google_drive,
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
:spreadsheet => '[Localizables] My Project!',
|
48
|
+
:login => 'your_email@gmail.com',
|
49
|
+
:password => 'your_password'
|
50
|
+
|
51
|
+
formatting :smart # This is optional, formatting :smart is used by default.
|
50
52
|
````
|
51
53
|
|
52
54
|
This would connect localio to your Google Drive and process the spreadsheet with title "[Localizables] My Project!".
|
@@ -55,35 +57,96 @@ The list of possible commands is this.
|
|
55
57
|
|
56
58
|
Option | Description | Default
|
57
59
|
----------------------------|------------------------------------------------------------------|--------
|
58
|
-
`platform` | (Req.) Target platform for the localizable files. |
|
59
|
-
`source` | (Req.) Information on where to find the spreadsheet w/ the info |
|
60
|
+
`platform` | (Req.) Target platform for the localizable files. | `nil`
|
61
|
+
`source` | (Req.) Information on where to find the spreadsheet w/ the info | `nil`
|
60
62
|
`output_path` | (Req.) Target directory for the localizables. | `out/`
|
61
63
|
`formatting` | The formatter that will be used for key processing. | `smart`
|
62
64
|
|
63
|
-
|
64
65
|
#### Supported platforms
|
65
66
|
|
66
|
-
* `:android` for Android string.xml files.
|
67
|
-
* `:ios` for iOS Localizable.strings files.
|
68
|
-
* `:rails` for Rails YAML files.
|
69
|
-
* `:json` for an easy JSON format for localizables.
|
67
|
+
* `:android` for Android string.xml files. The `output_path` needed is the path for the `res` directory.
|
68
|
+
* `:ios` for iOS Localizable.strings files. The `output_path` needed is base directory where `en.lproj/` and such would go.
|
69
|
+
* `:rails` for Rails YAML files. The `output_path` needed is your `config/locales` directory.
|
70
|
+
* `:json` for an easy JSON format for localizables. The `output_path` is yours to decide :)
|
70
71
|
|
71
72
|
#### Supported sources
|
72
73
|
|
73
|
-
|
74
|
-
|
74
|
+
##### Google Drive
|
75
|
+
|
76
|
+
`source :google_drive` will get the translation strings from Google Drive.
|
77
|
+
|
78
|
+
You will have to provide some required parameters too. Here is a list of all the parameters.
|
79
|
+
|
80
|
+
Option | Description
|
81
|
+
----------------------------|-------------------------------------------------------------------------
|
82
|
+
`:spreadsheet` | (Req.) Title of the spreadsheet you want to use. Can be a partial match.
|
83
|
+
`:login` | (Req.) Your Google login.
|
84
|
+
`:password` | (Req.) Your Google password.
|
85
|
+
|
86
|
+
**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.
|
87
|
+
|
88
|
+
For example, this.
|
89
|
+
|
90
|
+
````ruby
|
91
|
+
source :google_drive,
|
92
|
+
:spreadsheet => '[Localizables] My Project!',
|
93
|
+
:login => ENV['GOOGLE_LOGIN'],
|
94
|
+
:password => ENV['GOOGLE_PASSWORD']
|
95
|
+
````
|
96
|
+
|
97
|
+
And in your .bashrc (or .bash_profile, .zshrc or whatever), you could export those environment variables like this:
|
98
|
+
|
99
|
+
````ruby
|
100
|
+
export GOOGLE_LOGIN="your_login"
|
101
|
+
export GOOGLE_PASSWORD="your_password"
|
102
|
+
````
|
103
|
+
|
104
|
+
##### XLS
|
105
|
+
|
106
|
+
`source :xls` will use a local XLS file. In the parameter's hash you should specify a `:path`.
|
107
|
+
|
108
|
+
Option | Description
|
109
|
+
----------------------------|-------------------------------------------------------------------------
|
110
|
+
`:path` | (Req.) Path for your XLS file.
|
111
|
+
|
112
|
+
````ruby
|
113
|
+
source :xls,
|
114
|
+
:path => 'YourExcelFileWithTranslations.xls'
|
115
|
+
````
|
116
|
+
|
117
|
+
##### XLSX
|
118
|
+
|
119
|
+
Currently XLSX is not supported though the code is there (not tested, though) and it will be included in a future release.
|
75
120
|
|
76
121
|
#### Key formatters
|
77
122
|
|
123
|
+
If you don't specify a formatter for keys, :smart will be used.
|
124
|
+
|
78
125
|
* `:none` for no formatting.
|
79
|
-
* `:snake_case` for snake case formatting (ie "
|
80
|
-
* `:camel_case` for camel case formatting (ie "
|
126
|
+
* `:snake_case` for snake case formatting (ie "this_kind_of_key").
|
127
|
+
* `:camel_case` for camel case formatting (ie "ThisKindOfKey").
|
81
128
|
* `:smart` use a different formatting depending on the platform.
|
82
129
|
|
130
|
+
Here you have some examples on how the behavior would be:
|
131
|
+
|
132
|
+
Platform | "App name" | "ANOTHER_KIND_OF_KEY"
|
133
|
+
-------------------|--------------|----------------------
|
134
|
+
`:none` | App name | ANOTHER_KIND_OF_KEY
|
135
|
+
`:snake_case` | app_name | another_kind_of_key
|
136
|
+
`:camel_case` | appName | AnotherKindOfKey
|
137
|
+
`:smart` (ios) | _App_name | _Another_kind_of_key
|
138
|
+
`:smart` (android) | app_name | another_kind_of_key
|
139
|
+
`:smart` (ruby) | app_name | another_kind_of_key
|
140
|
+
`:smart` (json) | app_name | another_kind_of_key
|
141
|
+
|
142
|
+
Example of use:
|
143
|
+
|
144
|
+
````ruby
|
145
|
+
formatting :camel_case
|
146
|
+
````
|
147
|
+
|
148
|
+
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.
|
149
|
+
|
83
150
|
## Contributing
|
84
151
|
|
85
|
-
|
86
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
-
5. Create new Pull Request
|
152
|
+
Please read the [contributing guide](https://github.com/mrmans0n/localio/blob/master/CONTRIBUTING.md).
|
data/bin/localize
CHANGED
data/lib/localio.rb
CHANGED
@@ -10,7 +10,7 @@ module Localio
|
|
10
10
|
if File.exist? 'Locfile'
|
11
11
|
process_locfile('Locfile')
|
12
12
|
else
|
13
|
-
|
13
|
+
raise ArgumentError, 'Locfile not found in current directory, and no compatible file supplied in arguments.'
|
14
14
|
end
|
15
15
|
else
|
16
16
|
process_locfile(ARGV.shift)
|
data/lib/localio/formatter.rb
CHANGED
@@ -14,7 +14,7 @@ module Formatter
|
|
14
14
|
when :snake_case
|
15
15
|
key.space_to_underscore.strip_tag.downcase
|
16
16
|
else
|
17
|
-
|
17
|
+
raise ArgumentError, 'Unknown formatting used. Must use :smart, :none, :camel_case or :snake_case'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -15,7 +15,7 @@ module LocalizableWriter
|
|
15
15
|
when :rails
|
16
16
|
RailsWriter.write languages, terms, path, formatter, options
|
17
17
|
else
|
18
|
-
|
18
|
+
raise ArgumentError, 'Platform not supported! Current possibilities are :android, :ios, :json, :rails'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/localio/processor.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'localio/processors/google_drive_processor'
|
2
2
|
require 'localio/processors/xls_processor'
|
3
|
-
require 'localio/processors/xlsx_processor'
|
3
|
+
# require 'localio/processors/xlsx_processor'
|
4
4
|
|
5
5
|
module Processor
|
6
6
|
def self.load_localizables(service, options)
|
@@ -13,7 +13,7 @@ module Processor
|
|
13
13
|
raise 'Temporarily disabled due to rubyzip problems. Sorry!'
|
14
14
|
# XlsxProcessor.load_localizables options
|
15
15
|
else
|
16
|
-
|
16
|
+
raise ArgumentError, 'Unsupported service! Try with :google_drive, :xlsx or :xls in the source argument'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -7,18 +7,18 @@ class GoogleDriveProcessor
|
|
7
7
|
|
8
8
|
# Parameter validations
|
9
9
|
spreadsheet = options[:spreadsheet]
|
10
|
-
|
10
|
+
raise ArgumentError, ':spreadsheet required for Google Drive source!' if spreadsheet.nil?
|
11
11
|
login = options[:login]
|
12
|
-
|
12
|
+
raise ArgumentError, ':login required for Google Drive source!' if login.nil?
|
13
13
|
password = options[:password]
|
14
|
-
|
14
|
+
raise ArgumentError, ':password required for Google Drive source!' if password.nil?
|
15
15
|
|
16
16
|
# Log in and get spreadsheet
|
17
17
|
puts 'Logging in to Google Drive...'
|
18
18
|
begin
|
19
19
|
session = GoogleDrive.login(login, password)
|
20
20
|
rescue
|
21
|
-
|
21
|
+
raise 'Couldn\'t access Google Drive. Check your credentials in :login and :password'
|
22
22
|
end
|
23
23
|
puts 'Logged in!'
|
24
24
|
|
@@ -39,7 +39,7 @@ class GoogleDriveProcessor
|
|
39
39
|
|
40
40
|
# TODO we could pass a :page_index in the options hash and get that worksheet instead, defaulting to zero?
|
41
41
|
worksheet = matching_spreadsheets[0].worksheets[0]
|
42
|
-
|
42
|
+
raise 'Unable to retrieve the first worksheet from the spreadsheet. Are there any pages?' if worksheet.nil?
|
43
43
|
|
44
44
|
# At this point we have the worksheet, so we want to store all the key / values
|
45
45
|
first_valid_row_index = nil
|
@@ -50,9 +50,9 @@ class GoogleDriveProcessor
|
|
50
50
|
last_valid_row_index = row if worksheet[row, 1].downcase == '[end]'
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
raise IndexError, 'Invalid format: Could not find any [key] keyword in the A column of the worksheet' if first_valid_row_index.nil?
|
54
|
+
raise IndexError, 'Invalid format: Could not find any [end] keyword in the A column of the worksheet' if last_valid_row_index.nil?
|
55
|
+
raise IndexError, 'Invalid format: [end] must not be before [key] in the A column' if first_valid_row_index > last_valid_row_index
|
56
56
|
|
57
57
|
languages = Hash.new('languages')
|
58
58
|
default_language = nil
|
@@ -7,7 +7,7 @@ class XlsProcessor
|
|
7
7
|
|
8
8
|
# Parameter validations
|
9
9
|
path = options[:path]
|
10
|
-
|
10
|
+
raise ArgumentError, ':path attribute is missing from the source, and it is required for xls spreadsheets' if path.nil?
|
11
11
|
|
12
12
|
Spreadsheet.client_encoding = 'UTF-8'
|
13
13
|
|
@@ -15,7 +15,7 @@ class XlsProcessor
|
|
15
15
|
|
16
16
|
# TODO we could pass a :page_index in the options hash and get that worksheet instead, defaulting to zero?
|
17
17
|
worksheet = book.worksheet 0
|
18
|
-
|
18
|
+
raise 'Unable to retrieve the first worksheet from the spreadsheet. Are there any pages?' if worksheet.nil?
|
19
19
|
|
20
20
|
# At this point we have the worksheet, so we want to store all the key / values
|
21
21
|
first_valid_row_index = nil
|
@@ -26,9 +26,9 @@ class XlsProcessor
|
|
26
26
|
last_valid_row_index = row if worksheet[row, 0].to_s.downcase == '[end]'
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
raise IndexError, 'Invalid format: Could not find any [key] keyword in the A column of the worksheet' if first_valid_row_index.nil?
|
30
|
+
raise IndexError, 'Invalid format: Could not find any [end] keyword in the A column of the worksheet' if last_valid_row_index.nil?
|
31
|
+
raise IndexError, 'Invalid format: [end] must not be before [key] in the A column' if first_valid_row_index > last_valid_row_index
|
32
32
|
|
33
33
|
languages = Hash.new('languages')
|
34
34
|
default_language = nil
|
@@ -41,7 +41,7 @@ class XlsProcessor
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
raise 'There are no language columns in the worksheet' if languages.count == 0
|
45
45
|
|
46
46
|
default_language = languages[0] if default_language.to_s == ''
|
47
47
|
|
@@ -7,13 +7,13 @@ class XlsxProcessor
|
|
7
7
|
|
8
8
|
# Parameter validations
|
9
9
|
path = options[:path]
|
10
|
-
|
10
|
+
raise ArgumentError, ':path attribute is missing from the source, and it is required for xlsx spreadsheets' if path.nil?
|
11
11
|
|
12
12
|
book = SimpleXlsxReader.open path
|
13
13
|
|
14
14
|
# TODO we could pass a :page_index in the options hash and get that worksheet instead, defaulting to zero?
|
15
15
|
worksheet = book.sheets.first
|
16
|
-
|
16
|
+
raise 'Unable to retrieve the first worksheet from the spreadsheet. Are there any pages?' if worksheet.nil?
|
17
17
|
|
18
18
|
# At this point we have the worksheet, so we want to store all the key / values
|
19
19
|
first_valid_row_index = nil
|
@@ -24,9 +24,9 @@ class XlsxProcessor
|
|
24
24
|
last_valid_row_index = row if worksheet[row, 0].to_s.downcase == '[end]'
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
raise IndexError, 'Invalid format: Could not find any [key] keyword in the A column of the worksheet' if first_valid_row_index.nil?
|
28
|
+
raise IndexError, 'Invalid format: Could not find any [end] keyword in the A column of the worksheet' if last_valid_row_index.nil?
|
29
|
+
raise IndexError, 'Invalid format: [end] must not be before [key] in the A column' if first_valid_row_index > last_valid_row_index
|
30
30
|
|
31
31
|
languages = Hash.new('languages')
|
32
32
|
default_language = nil
|
@@ -39,7 +39,7 @@ class XlsxProcessor
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
raise 'There are no language columns in the worksheet' if languages.count == 0
|
43
43
|
|
44
44
|
default_language = languages[0] if default_language.to_s == ''
|
45
45
|
|
data/lib/localio/version.rb
CHANGED
data/localio.gemspec
CHANGED
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency "micro-optparse", "~> 1.1.5"
|
31
31
|
spec.add_dependency "google_drive", "~> 0.3.6"
|
32
32
|
spec.add_dependency "spreadsheet", "~> 0.8.9"
|
33
|
-
spec.add_dependency "simple_xlsx_reader", "~> 0.9.7"
|
33
|
+
# spec.add_dependency "simple_xlsx_reader", "~> 0.9.7"
|
34
34
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nacho Lopez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.8.9
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simple_xlsx_reader
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ~>
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.9.7
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.9.7
|
111
97
|
description: Automatic Localizable file generation for multiple platforms (Rails,
|
112
98
|
Android, iOS, JSON)
|
113
99
|
email:
|
@@ -118,6 +104,7 @@ extensions: []
|
|
118
104
|
extra_rdoc_files: []
|
119
105
|
files:
|
120
106
|
- .gitignore
|
107
|
+
- CONTRIBUTING.md
|
121
108
|
- Gemfile
|
122
109
|
- LICENSE.txt
|
123
110
|
- README.md
|