woz 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -5
- data/bin/woz +21 -7
- data/lib/woz/builder.rb +83 -12
- data/lib/woz/configuration.rb +1 -0
- data/lib/woz/version.rb +1 -1
- data/spec/example_xcode_project/.wozniak +1 -0
- data/spec/example_xcode_project/Localizable.csv +5 -0
- data/spec/example_xcode_project/Localizable.xls +0 -0
- metadata +10 -10
- data/spec/example_xcode_project/.leorc +0 -12
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Woz
|
2
2
|
|
3
|
-
Generate your 'strings' files from an existing 'xls' file so your clients can translate their application by just entering all the value in the xls file. Of course woz will make sure you're able to generate the xls file from the existing strings file.
|
3
|
+
Generate your 'strings' files from an existing 'xls' (or 'csv') file so your clients can translate their application by just entering all the value in the xls file. Of course woz will make sure you're able to generate the xls file from the existing strings file.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,21 +16,38 @@ Generate a configuration file if your not planning to go by the default values:
|
|
16
16
|
|
17
17
|
This will generate a '.wozniak' file in your project directory. This file contains the default values, and you can change them according to your needs.
|
18
18
|
|
19
|
-
##
|
19
|
+
## Export to xls
|
20
20
|
|
21
21
|
When you want to generate an xls file from your existing 'strings' files you just have to enter the following command:
|
22
22
|
|
23
|
-
woz
|
23
|
+
woz export
|
24
24
|
|
25
25
|
Make sure that all the '.lproj' directories are in this directory and that the 'strings' file you specified in the '.wozniak' configuration are inside these '.lproj' directories.
|
26
26
|
|
27
27
|
This will generate 1 'xls' file inside this direcory and here you can check out all the used translations.
|
28
28
|
|
29
|
-
##
|
29
|
+
## Export to csv
|
30
|
+
|
31
|
+
When you want to generate an csv file from your existing 'strings' files you just have to enter one of the following commands:
|
32
|
+
|
33
|
+
woz export --csv
|
34
|
+
woz export -c
|
35
|
+
|
36
|
+
Exporting to csv works the same way as it does for xls.
|
37
|
+
|
38
|
+
## Export to xls and csv
|
39
|
+
|
40
|
+
You can also export tp both formats:
|
41
|
+
|
42
|
+
woz export --both
|
43
|
+
|
44
|
+
This will generate xls and csv files at the same time.
|
45
|
+
|
46
|
+
## Import into strings
|
30
47
|
|
31
48
|
When you want to do the opposite, that is generate your strings file from an xls file, than you'll just have to run this command:
|
32
49
|
|
33
|
-
woz
|
50
|
+
woz import
|
34
51
|
|
35
52
|
Make sure the xls in this directory, and that it has the following columns:
|
36
53
|
|
@@ -53,8 +70,27 @@ There is also a possibility to generate strings files from a xls file located on
|
|
53
70
|
woz strings /an_absolute_directory/the_file.xls
|
54
71
|
woz strings ~/an_absolute_directory_inside_your_home_folder/the_file.xls
|
55
72
|
|
73
|
+
The same is valid when importing from csv. Only this time you'll have to add '--csv'.
|
74
|
+
|
75
|
+
woz import --csv
|
76
|
+
|
77
|
+
When adding a custom filepath, this parameter is not important. Wozniak will check the file type and triest to import from xls or csv, whatever works...
|
78
|
+
|
79
|
+
## Todo
|
80
|
+
|
81
|
+
This is what I want to implement in the future.
|
82
|
+
|
83
|
+
- [ ] Multiple file support.
|
84
|
+
|
56
85
|
## Changelog
|
57
86
|
|
87
|
+
### 0.3.0
|
88
|
+
|
89
|
+
- Export to CSV
|
90
|
+
- Import from CSV
|
91
|
+
- Better script naming (now import and export with custom options)
|
92
|
+
- Fix import with custom filepath
|
93
|
+
|
58
94
|
### 0.2.0
|
59
95
|
|
60
96
|
- Add filename/filepath behind the 'woz strings' command in order to use that xls file for strings generation.
|
data/bin/woz
CHANGED
@@ -4,17 +4,31 @@ require "thor"
|
|
4
4
|
require "woz"
|
5
5
|
|
6
6
|
class WozCommand < Thor
|
7
|
-
desc "
|
8
|
-
|
9
|
-
|
7
|
+
desc "export", "Export the .strings files to Excel (or force an export to csv)."
|
8
|
+
method_option :both, :type => :boolean, :aliases => "-b", :default => false, :desc => "Force export to CSV and xls."
|
9
|
+
method_option :csv, :type => :boolean, :aliases => "-c", :default => false, :desc => "Force export to CSV instead of the default xls."
|
10
|
+
def export
|
11
|
+
if options[:both]
|
12
|
+
Woz::Builder.generate_csv
|
13
|
+
Woz::Builder.generate_xls
|
14
|
+
elsif options[:csv]
|
15
|
+
Woz::Builder.generate_csv
|
16
|
+
else
|
17
|
+
Woz::Builder.generate_xls
|
18
|
+
end
|
10
19
|
end
|
11
20
|
|
12
|
-
desc "
|
13
|
-
|
14
|
-
|
21
|
+
desc "import [FOLDER]", "Generate the .strings files from Excel (or force to import them from csv). Pass the filename (or path) from the csv/xls file you wish to import."
|
22
|
+
method_option :csv, :type => :boolean, :aliases => "-c", :default => false, :desc => "Force import from CSV instead of the default xls."
|
23
|
+
def import(filepath=nil)
|
24
|
+
if File.extname(filepath) == ".xls"
|
25
|
+
Woz::Builder.generate_strings(false, filepath)
|
26
|
+
else
|
27
|
+
Woz::Builder.generate_strings(options[:csv], filepath)
|
28
|
+
end
|
15
29
|
end
|
16
30
|
|
17
|
-
desc "setup", "
|
31
|
+
desc "setup", "Generate the configuration file."
|
18
32
|
def setup
|
19
33
|
Woz::Builder.init
|
20
34
|
end
|
data/lib/woz/builder.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "highline/import"
|
2
|
+
require "csv"
|
2
3
|
|
3
4
|
require "spreadsheet"
|
4
5
|
Spreadsheet.client_encoding = 'UTF-8'
|
@@ -22,12 +23,20 @@ module Woz
|
|
22
23
|
puts "# woz initialized!"
|
23
24
|
end
|
24
25
|
|
26
|
+
def generate_csv
|
27
|
+
generate_translation_csv
|
28
|
+
end
|
29
|
+
|
25
30
|
def generate_xls
|
26
31
|
generate_translation_xls
|
27
32
|
end
|
28
33
|
|
29
|
-
def generate_strings(
|
30
|
-
|
34
|
+
def generate_strings(csv=false, filepath=nil)
|
35
|
+
if csv
|
36
|
+
generate_translation_strings_from_csv(filepath)
|
37
|
+
else
|
38
|
+
generate_translation_strings_from_xls(filepath)
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
protected
|
@@ -44,6 +53,7 @@ module Woz
|
|
44
53
|
#
|
45
54
|
# Woz.configure do |config|
|
46
55
|
# config.xls_filename = "Localizations.xls"
|
56
|
+
# config.csv_filename = "Localizations.csv"
|
47
57
|
# config.strings_filename = "Localizations.strings"
|
48
58
|
# config.ask_confirmation = false
|
49
59
|
# end
|
@@ -81,6 +91,20 @@ TEXT
|
|
81
91
|
language
|
82
92
|
end
|
83
93
|
|
94
|
+
def generate_comma_seperated_values path, list
|
95
|
+
CSV.open(path, "wb") do |csv|
|
96
|
+
languages = list.values.map(&:keys).flatten.uniq
|
97
|
+
csv << [KEY_COLUMN, languages].flatten
|
98
|
+
list.each do |key, value|
|
99
|
+
row = [key]
|
100
|
+
languages.each do |language|
|
101
|
+
row << list[key][language]
|
102
|
+
end
|
103
|
+
csv << row
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
84
108
|
def generate_spreadsheet list
|
85
109
|
book = Spreadsheet::Workbook.new
|
86
110
|
sheet = book.create_worksheet
|
@@ -101,7 +125,7 @@ TEXT
|
|
101
125
|
book
|
102
126
|
end
|
103
127
|
|
104
|
-
def
|
128
|
+
def generate_translation(type=:xls)
|
105
129
|
file = File.join(Dir.pwd, "en.lproj", Woz.config.strings_filename)
|
106
130
|
output_dir = get_output_dir(file)
|
107
131
|
list = {}
|
@@ -109,16 +133,28 @@ TEXT
|
|
109
133
|
parse_strings list, File.join(Dir.pwd, entry) if entry.include? ".lproj"
|
110
134
|
end
|
111
135
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
136
|
+
filename = Woz.config.send("#{type.to_s}_filename")
|
137
|
+
if !Woz.config.ask_confirmation || !File.exists?(filename) || ask("! the project's #{type.to_s} file will be overwritten, type 'y' and enter to continue: ") == "y"
|
138
|
+
if type == :xls
|
139
|
+
content = generate_spreadsheet list
|
140
|
+
content.write(File.join(output_dir, filename))
|
141
|
+
else
|
142
|
+
generate_comma_seperated_values File.join(output_dir, filename), list
|
143
|
+
end
|
144
|
+
puts "# #{type.to_s} generated at #{File.join(output_dir, filename)}"
|
117
145
|
else
|
118
|
-
puts "!
|
146
|
+
puts "! #{type.to_s} generation canceled"
|
119
147
|
end
|
120
148
|
end
|
121
149
|
|
150
|
+
def generate_translation_csv
|
151
|
+
generate_translation(:csv)
|
152
|
+
end
|
153
|
+
|
154
|
+
def generate_translation_xls
|
155
|
+
generate_translation(:xls)
|
156
|
+
end
|
157
|
+
|
122
158
|
def parse_xls file
|
123
159
|
book = Spreadsheet.open file
|
124
160
|
sheet = book.worksheet 0
|
@@ -140,15 +176,50 @@ TEXT
|
|
140
176
|
list
|
141
177
|
end
|
142
178
|
|
143
|
-
def
|
179
|
+
def parse_csv filepath
|
180
|
+
index = 0
|
181
|
+
languages = []
|
182
|
+
list = {}
|
183
|
+
CSV.foreach(filepath) do |row|
|
184
|
+
if index == 0
|
185
|
+
languages = row.select { |i| i != KEY_COLUMN && i != "" }
|
186
|
+
list = languages.inject({}) do |hash, language|
|
187
|
+
hash[language] = {}
|
188
|
+
hash
|
189
|
+
end
|
190
|
+
else
|
191
|
+
languages.each_with_index do |language, e|
|
192
|
+
list[language][row[0]] = row[e+1]
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
index += 1
|
197
|
+
end
|
198
|
+
list
|
199
|
+
end
|
200
|
+
|
201
|
+
def generate_translation_strings_from_xls(xls_filepath=nil)
|
144
202
|
filepath = File.expand_path(xls_filepath || Woz.config.xls_filename)
|
145
|
-
puts filepath.inspect
|
146
203
|
file = File.join(filepath)
|
147
|
-
output_dir = get_output_dir(File.join(File.expand_path(Woz.config.xls_filename)))
|
148
204
|
|
149
205
|
fail "! xls file not found, specify the filename in the .wozniak file" unless File.exists?(file)
|
150
206
|
|
151
207
|
list = parse_xls file
|
208
|
+
generate_translation_strings(list)
|
209
|
+
end
|
210
|
+
|
211
|
+
def generate_translation_strings_from_csv(csv_filepath=nil)
|
212
|
+
filepath = File.expand_path(csv_filepath || Woz.config.csv_filename)
|
213
|
+
file = File.join(filepath)
|
214
|
+
|
215
|
+
fail "! csv file not found, specify the filename in the .wozniak file" unless File.exists?(file)
|
216
|
+
|
217
|
+
list = parse_csv filepath
|
218
|
+
generate_translation_strings(list)
|
219
|
+
end
|
220
|
+
|
221
|
+
def generate_translation_strings(list)
|
222
|
+
output_dir = get_output_dir(File.join(File.expand_path(Woz.config.xls_filename)))
|
152
223
|
cocoa_array = "#define kLanguages [NSArray arrayWithObjects:"
|
153
224
|
cocoa_languages_array = []
|
154
225
|
list.keys.compact.each do |language|
|
data/lib/woz/configuration.rb
CHANGED
data/lib/woz/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
16
|
-
requirement: &
|
16
|
+
requirement: &70294884558340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.6.15
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70294884558340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thor
|
27
|
-
requirement: &
|
27
|
+
requirement: &70294884557840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.16.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70294884557840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: spreadsheet
|
38
|
-
requirement: &
|
38
|
+
requirement: &70294884557380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.7.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70294884557380
|
47
47
|
description: Generate strings files from an xls and vice versa.
|
48
48
|
email:
|
49
49
|
- jelle@fousa.be
|
@@ -63,8 +63,8 @@ files:
|
|
63
63
|
- lib/woz/configuration.rb
|
64
64
|
- lib/woz/logger.rb
|
65
65
|
- lib/woz/version.rb
|
66
|
-
- spec/example_xcode_project/.leorc
|
67
66
|
- spec/example_xcode_project/.wozniak
|
67
|
+
- spec/example_xcode_project/Localizable.csv
|
68
68
|
- spec/example_xcode_project/Localizable.xls
|
69
69
|
- spec/example_xcode_project/de.lproj/Localizable.strings
|
70
70
|
- spec/example_xcode_project/en.lproj/Localizable.strings
|
@@ -96,8 +96,8 @@ signing_key:
|
|
96
96
|
specification_version: 3
|
97
97
|
summary: Easy strings file generate.
|
98
98
|
test_files:
|
99
|
-
- spec/example_xcode_project/.leorc
|
100
99
|
- spec/example_xcode_project/.wozniak
|
100
|
+
- spec/example_xcode_project/Localizable.csv
|
101
101
|
- spec/example_xcode_project/Localizable.xls
|
102
102
|
- spec/example_xcode_project/de.lproj/Localizable.strings
|
103
103
|
- spec/example_xcode_project/en.lproj/Localizable.strings
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# [Leo](http://github.com/fousa/leo)
|
2
|
-
# This file is used by Leo to make exporting to
|
3
|
-
# xls or strings even easier.
|
4
|
-
#
|
5
|
-
# Leo.configure do |config|
|
6
|
-
# config.xls_name = "Localizable.xls"
|
7
|
-
# config.strings_name = "Localizable.strings"
|
8
|
-
# config.ask_confirmation = false
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# You can now run `leo xls` to create a translation
|
12
|
-
# xls file.
|