woz 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jelle Vandebeeck
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,60 @@
1
+ # Woz
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.
4
+
5
+ ## Installation
6
+
7
+ Install the gem yourself:
8
+
9
+ $ gem install woz
10
+
11
+ ## Setup
12
+
13
+ Generate a configuration file if your not planning to go by the default values:
14
+
15
+ woz setup
16
+
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
+
19
+ ## Generate xls
20
+
21
+ When you want to generate an xls file from your existing 'strings' files you just have to enter the following command:
22
+
23
+ woz xls
24
+
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
+
27
+ This will generate 1 'xls' file inside this direcory and here you can check out all the used translations.
28
+
29
+ ## Generate strings
30
+
31
+ 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
+
33
+ woz strings
34
+
35
+ Make sure the xls in this directory, and that it has the following columns:
36
+
37
+ keys (this it the column that defines the key)
38
+ nl (the first language with the different strings, in this case Dutch)
39
+ en (or English)
40
+ fr (or even French)
41
+
42
+ To make it even more clear, here is a simple representation of the xls file:
43
+
44
+ keys nl fr en
45
+ title Titel Titre Title
46
+ name Name Nom Name
47
+
48
+ This will genereate different '.lproj' directories with the localized files inside of them.
49
+
50
+ ## License
51
+
52
+ Check out the LICENSE.txt file. Really awesome reading material...
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/woz ADDED
@@ -0,0 +1,25 @@
1
+ #! /usr/bin/ruby
2
+
3
+ require "thor"
4
+ require "woz"
5
+
6
+ class WozCommand < Thor
7
+ desc "xls", "creates a xls with the current strings files."
8
+ def xls
9
+ Woz::Builder.generate_xls
10
+ end
11
+
12
+ desc "strings", "creates the strings files from the available xls file."
13
+ def strings
14
+ Woz::Builder.generate_strings
15
+ end
16
+
17
+ desc "setup", "creates the woz configuration file."
18
+ def setup
19
+ Woz::Builder.init
20
+ end
21
+ end
22
+
23
+ load ".wozniak" if File.exists?(".wozniak")
24
+
25
+ WozCommand.start
@@ -0,0 +1,190 @@
1
+ require "highline/import"
2
+
3
+ require "spreadsheet"
4
+ Spreadsheet.client_encoding = 'UTF-8'
5
+
6
+ module Woz
7
+ class Builder
8
+ KEY_COLUMN = "keys"
9
+
10
+ class << self
11
+ def init
12
+ file = File.join(Dir.pwd, config_file_name)
13
+
14
+ if File.exists?(file)
15
+ warn "# '#{file}' already exists"
16
+ elsif File.exists?(file.downcase)
17
+ warn "# '#{file.downcase}' exists, which could conflict with `#{file}'"
18
+ else
19
+ puts "# writing '#{file}'"
20
+ File.open(file, "w") { |f| f.write(instructions_text) }
21
+ end
22
+ puts "# woz initialized!"
23
+ end
24
+
25
+ def generate_xls
26
+ generate_translation_xls
27
+ end
28
+
29
+ def generate_strings
30
+ generate_translation_strings
31
+ end
32
+
33
+ protected
34
+
35
+ def config_file_name
36
+ ".wozniak"
37
+ end
38
+
39
+ def instructions_text
40
+ <<TEXT
41
+ # [Woz](http://github.com/fousa/woz)
42
+ # This file is used by Woz to make exporting to
43
+ # xls or strings even easier.
44
+ #
45
+ # Woz.configure do |config|
46
+ # config.xls_filename = "Localizations.xls"
47
+ # config.strings_filename = "Localizations.strings"
48
+ # config.ask_confirmation = false
49
+ # end
50
+ #
51
+ # You can now run `woz xls` to create a translation
52
+ # xls file.
53
+ TEXT
54
+ end
55
+
56
+ def get_output_dir name
57
+ name = File.dirname(name)
58
+ name = get_output_dir(name) if name.include? ".lproj"
59
+ name
60
+ end
61
+
62
+ def parse_strings list, file
63
+ fail "! strings file not found, specify the filename in the .wozniak file" unless File.exists?(File.join(file, Woz.config.strings_filename))
64
+
65
+ language = get_language file
66
+ puts "# parsing #{language}"
67
+ File.open(File.join(file, Woz.config.strings_filename), "r").each do |row|
68
+ if row.start_with? '"'
69
+ if splitted = row.split(/"/, 5)
70
+ if list[splitted[1]].nil?
71
+ list[splitted[1]] = {}
72
+ end
73
+ list[splitted[1]][language] = splitted[3]
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ def get_language name
80
+ language = File.basename(name).gsub ".lproj", ""
81
+ language
82
+ end
83
+
84
+ def generate_spreadsheet list
85
+ book = Spreadsheet::Workbook.new
86
+ sheet = book.create_worksheet
87
+
88
+ languages = list.values.map(&:keys).flatten.uniq
89
+ sheet.row(0).concat [KEY_COLUMN, languages].flatten
90
+
91
+ index = 1
92
+ list.each do |key, value|
93
+ sheet.row(index).push key
94
+ languages.each do |language|
95
+ sheet.row(index).push list[key][language]
96
+ end
97
+
98
+ index += 1
99
+ end
100
+
101
+ book
102
+ end
103
+
104
+ def generate_translation_xls
105
+ file = File.join(Dir.pwd, "en.lproj", Woz.config.strings_filename)
106
+ output_dir = get_output_dir(file)
107
+ list = {}
108
+ Dir.foreach(output_dir) do |entry|
109
+ parse_strings list, File.join(Dir.pwd, entry) if entry.include? ".lproj"
110
+ end
111
+
112
+ xls = generate_spreadsheet list
113
+
114
+ if !Woz.config.ask_confirmation || ask("! this xls file will be overwrite type 'y' to confirm: ") == "y"
115
+ xls.write(File.join(output_dir, Woz.config.xls_filename))
116
+ puts "# xls generated at #{File.join(output_dir, Woz.config.xls_filename)}"
117
+ else
118
+ puts "! xls generation canceled"
119
+ end
120
+ end
121
+
122
+ def parse_xls file
123
+ book = Spreadsheet.open file
124
+ sheet = book.worksheet 0
125
+
126
+ languages = sheet.row(0).select { |i| i != KEY_COLUMN && i != "" }
127
+
128
+ list = languages.inject({}) do |hash, language|
129
+ hash[language] = {}
130
+ hash
131
+ end
132
+
133
+ sheet.each_with_index do |row, i|
134
+ next if i == 0
135
+
136
+ languages.each_with_index do |language, e|
137
+ list[language][row[0]] = row[e+1]
138
+ end
139
+ end
140
+ list
141
+ end
142
+
143
+ def generate_translation_strings
144
+ file = File.join(Dir.pwd, Woz.config.xls_filename)
145
+ output_dir = get_output_dir(file)
146
+
147
+ fail "! xls file not found, specify the filename in the .wozniak file" unless File.exists?(file)
148
+
149
+ list = parse_xls file
150
+ cocoa_array = "#define kLanguages [NSArray arrayWithObjects:"
151
+ cocoa_languages_array = []
152
+ list.keys.compact.each do |language|
153
+ puts "# parsing #{language}"
154
+ proj_dir = File.join(output_dir, "#{language}.lproj")
155
+ Dir.mkdir(proj_dir) unless File.directory?(proj_dir)
156
+
157
+ file_path = File.join(proj_dir, Woz.config.strings_filename)
158
+ cocoa_languages_array << "@\"#{language}\""
159
+
160
+ new_file = !File.exists?(file_path)
161
+ if new_file || !Woz.config.ask_confirmation || ask("! this #{language} strings file will be overwrite type 'y' to confirm: ") == "y"
162
+ if new_file
163
+ file = File.new(file_path, "w")
164
+ else
165
+ file = File.open(file_path, "w")
166
+ end
167
+ list[language].each do |key, value|
168
+ if value.nil?
169
+ file.puts "\"#{key}\" = \"MISSING VALUE\";" unless key.nil?
170
+ else
171
+ file.puts "\"#{key}\" = \"#{value}\";"
172
+ end
173
+ end
174
+ puts "# #{language} strings generated at #{file_path}"
175
+ else
176
+ puts "! #{language} strings generation canceled"
177
+ end
178
+ end
179
+ cocoa_languages_array << "nil"
180
+ cocoa_array << "#{cocoa_languages_array.join(', ')}]"
181
+ cocoa_array
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+
188
+
189
+
190
+
@@ -0,0 +1,12 @@
1
+ require "ostruct"
2
+
3
+ module Woz
4
+ class Configuration < OpenStruct
5
+ def self.default
6
+ new \
7
+ :xls_filename => "Localizations.xls",
8
+ :strings_filename => "Localizations.strings",
9
+ :ask_confirmation => false
10
+ end
11
+ end
12
+ end
data/lib/woz/logger.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Woz
2
+ class Logger
3
+ def describe(header)
4
+ width = 50
5
+ log "#" * width
6
+ log header.center(width)
7
+ log "#" * width
8
+ end
9
+
10
+ def log(str)
11
+ puts str
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Woz
2
+ VERSION = "0.1.0"
3
+ end
data/lib/woz.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "woz/version"
2
+ require "woz/configuration"
3
+ require "woz/builder"
4
+ require "woz/logger"
5
+
6
+ module Woz
7
+ class << self
8
+ def config
9
+ @config ||= Configuration.default
10
+ end
11
+
12
+ def configure
13
+ yield config
14
+ end
15
+
16
+ def run(cmd)
17
+ puts "Executing #{cmd}"
18
+ puts system("#{cmd}")
19
+ end
20
+
21
+ def logger
22
+ @logger ||= Leo::Logger.new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
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.
@@ -0,0 +1,12 @@
1
+ # [Woz](http://github.com/fousa/woz)
2
+ # This file is used by Woz to make exporting to
3
+ # xls or strings even easier.
4
+ #
5
+ Woz.configure do |config|
6
+ config.xls_filename = "Localizable.xls"
7
+ config.strings_filename = "Localizable.strings"
8
+ config.ask_confirmation = false
9
+ end
10
+ #
11
+ # You can now run `woz xls` to create a translation
12
+ # xls file.
@@ -0,0 +1,3 @@
1
+ "beer" = "biere";
2
+ "title" = "MISSING VALUE";
3
+ "name" = "MISSING VALUE";
@@ -0,0 +1,3 @@
1
+ "beer" = "MISSING VALUE";
2
+ "title" = "title";
3
+ "name" = "name";
@@ -0,0 +1,3 @@
1
+ "beer" = "bière";
2
+ "title" = "titre";
3
+ "name" = "nom";
@@ -0,0 +1,3 @@
1
+ "beer" = "bier";
2
+ "title" = "titel";
3
+ "name" = "naam";
data/woz.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'woz/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "woz"
8
+ gem.version = Woz::VERSION
9
+ gem.authors = ["Jelle Vandebeeck"]
10
+ gem.email = ["jelle@fousa.be"]
11
+ gem.description = %q{Generate strings files from an xls and vice versa.}
12
+ gem.summary = %q{Easy strings file generate.}
13
+ gem.homepage = "http://github.com/fousa/woz"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'highline', '1.6.15'
21
+ gem.add_dependency 'thor', '0.16.0'
22
+ gem.add_dependency 'spreadsheet', '0.7.3'
23
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: woz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jelle Vandebeeck
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: highline
16
+ requirement: &70249543876360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.15
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70249543876360
25
+ - !ruby/object:Gem::Dependency
26
+ name: thor
27
+ requirement: &70249543875740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 0.16.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70249543875740
36
+ - !ruby/object:Gem::Dependency
37
+ name: spreadsheet
38
+ requirement: &70249543875160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
43
+ version: 0.7.3
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70249543875160
47
+ description: Generate strings files from an xls and vice versa.
48
+ email:
49
+ - jelle@fousa.be
50
+ executables:
51
+ - woz
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/woz
61
+ - lib/woz.rb
62
+ - lib/woz/builder.rb
63
+ - lib/woz/configuration.rb
64
+ - lib/woz/logger.rb
65
+ - lib/woz/version.rb
66
+ - spec/example_xcode_project/.leorc
67
+ - spec/example_xcode_project/.wozniak
68
+ - spec/example_xcode_project/Localizable.xls
69
+ - spec/example_xcode_project/de.lproj/Localizable.strings
70
+ - spec/example_xcode_project/en.lproj/Localizable.strings
71
+ - spec/example_xcode_project/fr.lproj/Localizable.strings
72
+ - spec/example_xcode_project/nl.lproj/Localizable.strings
73
+ - woz.gemspec
74
+ homepage: http://github.com/fousa/woz
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.15
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Easy strings file generate.
98
+ test_files:
99
+ - spec/example_xcode_project/.leorc
100
+ - spec/example_xcode_project/.wozniak
101
+ - spec/example_xcode_project/Localizable.xls
102
+ - spec/example_xcode_project/de.lproj/Localizable.strings
103
+ - spec/example_xcode_project/en.lproj/Localizable.strings
104
+ - spec/example_xcode_project/fr.lproj/Localizable.strings
105
+ - spec/example_xcode_project/nl.lproj/Localizable.strings
106
+ has_rdoc: