ymdp 0.1.8.1 → 0.1.9
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.
- data/README.rdoc +2 -11
- data/ymdp.gemspec +5 -8
- metadata +15 -9
- data/bin/ymdp +0 -50
- data/lib/ymdp/translator/base.rb +0 -390
- data/spec/translator_spec.rb +0 -322
data/README.rdoc
CHANGED
@@ -1,17 +1,8 @@
|
|
1
1
|
= ymdp
|
2
2
|
|
3
|
-
|
3
|
+
Framework for developing applications in the Yahoo! Mail Development Platform.
|
4
4
|
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
14
5
|
|
15
6
|
== Copyright
|
16
7
|
|
17
|
-
Copyright (c) 2010
|
8
|
+
Copyright (c) 2010 Capital Thought. See LICENSE for details.
|
data/ymdp.gemspec
CHANGED
@@ -5,15 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ymdp}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Coleman"]
|
12
|
-
s.date = %q{2010-01-
|
13
|
-
s.default_executable = %q{ymdp}
|
12
|
+
s.date = %q{2010-01-22}
|
14
13
|
s.description = %q{Framework for developing applications in the Yahoo! Mail Development Platform.}
|
15
14
|
s.email = %q{progressions@gmail.com}
|
16
|
-
s.executables = ["ymdp"]
|
17
15
|
s.extra_rdoc_files = [
|
18
16
|
"LICENSE",
|
19
17
|
"README.rdoc"
|
@@ -27,7 +25,6 @@ Gem::Specification.new do |s|
|
|
27
25
|
"README.rdoc",
|
28
26
|
"Rakefile",
|
29
27
|
"VERSION",
|
30
|
-
"bin/ymdp",
|
31
28
|
"lib/ymdp.rb",
|
32
29
|
"lib/ymdp/application.rb",
|
33
30
|
"lib/ymdp/application_view.rb",
|
@@ -54,7 +51,6 @@ Gem::Specification.new do |s|
|
|
54
51
|
"lib/ymdp/tag_helper.rb",
|
55
52
|
"lib/ymdp/tasks/keys.rake",
|
56
53
|
"lib/ymdp/tasks/ymdp.rake",
|
57
|
-
"lib/ymdp/translator/base.rb",
|
58
54
|
"spec/application_spec.rb",
|
59
55
|
"spec/application_view_spec.rb",
|
60
56
|
"spec/compiler_spec.rb",
|
@@ -130,7 +126,6 @@ Gem::Specification.new do |s|
|
|
130
126
|
"spec/spec.opts",
|
131
127
|
"spec/spec_helper.rb",
|
132
128
|
"spec/stubs.rb",
|
133
|
-
"spec/translator_spec.rb",
|
134
129
|
"spec/validator_spec.rb",
|
135
130
|
"spec/ymdp_base_spec.rb",
|
136
131
|
"spec/ymdp_spec.rb",
|
@@ -158,7 +153,6 @@ Gem::Specification.new do |s|
|
|
158
153
|
"spec/git_helper_spec.rb",
|
159
154
|
"spec/spec_helper.rb",
|
160
155
|
"spec/stubs.rb",
|
161
|
-
"spec/translator_spec.rb",
|
162
156
|
"spec/validator_spec.rb",
|
163
157
|
"spec/ymdp_base_spec.rb",
|
164
158
|
"spec/ymdp_spec.rb"
|
@@ -183,6 +177,7 @@ Gem::Specification.new do |s|
|
|
183
177
|
s.add_runtime_dependency(%q<serenity>, [">= 0"])
|
184
178
|
s.add_runtime_dependency(%q<ymdp_generator>, [">= 0"])
|
185
179
|
s.add_runtime_dependency(%q<ymdt>, [">= 0"])
|
180
|
+
s.add_runtime_dependency(%q<yrb>, [">= 0"])
|
186
181
|
else
|
187
182
|
s.add_dependency(%q<rspec>, [">= 1.2.6"])
|
188
183
|
s.add_dependency(%q<haml>, [">= 0"])
|
@@ -198,6 +193,7 @@ Gem::Specification.new do |s|
|
|
198
193
|
s.add_dependency(%q<serenity>, [">= 0"])
|
199
194
|
s.add_dependency(%q<ymdp_generator>, [">= 0"])
|
200
195
|
s.add_dependency(%q<ymdt>, [">= 0"])
|
196
|
+
s.add_dependency(%q<yrb>, [">= 0"])
|
201
197
|
end
|
202
198
|
else
|
203
199
|
s.add_dependency(%q<rspec>, [">= 1.2.6"])
|
@@ -214,6 +210,7 @@ Gem::Specification.new do |s|
|
|
214
210
|
s.add_dependency(%q<serenity>, [">= 0"])
|
215
211
|
s.add_dependency(%q<ymdp_generator>, [">= 0"])
|
216
212
|
s.add_dependency(%q<ymdt>, [">= 0"])
|
213
|
+
s.add_dependency(%q<yrb>, [">= 0"])
|
217
214
|
end
|
218
215
|
end
|
219
216
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ymdp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Coleman
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
13
|
-
default_executable:
|
12
|
+
date: 2010-01-22 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -152,10 +152,20 @@ dependencies:
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: "0"
|
154
154
|
version:
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: yrb
|
157
|
+
type: :runtime
|
158
|
+
version_requirement:
|
159
|
+
version_requirements: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: "0"
|
164
|
+
version:
|
155
165
|
description: Framework for developing applications in the Yahoo! Mail Development Platform.
|
156
166
|
email: progressions@gmail.com
|
157
|
-
executables:
|
158
|
-
|
167
|
+
executables: []
|
168
|
+
|
159
169
|
extensions: []
|
160
170
|
|
161
171
|
extra_rdoc_files:
|
@@ -170,7 +180,6 @@ files:
|
|
170
180
|
- README.rdoc
|
171
181
|
- Rakefile
|
172
182
|
- VERSION
|
173
|
-
- bin/ymdp
|
174
183
|
- lib/ymdp.rb
|
175
184
|
- lib/ymdp/application.rb
|
176
185
|
- lib/ymdp/application_view.rb
|
@@ -197,7 +206,6 @@ files:
|
|
197
206
|
- lib/ymdp/tag_helper.rb
|
198
207
|
- lib/ymdp/tasks/keys.rake
|
199
208
|
- lib/ymdp/tasks/ymdp.rake
|
200
|
-
- lib/ymdp/translator/base.rb
|
201
209
|
- spec/application_spec.rb
|
202
210
|
- spec/application_view_spec.rb
|
203
211
|
- spec/compiler_spec.rb
|
@@ -273,7 +281,6 @@ files:
|
|
273
281
|
- spec/spec.opts
|
274
282
|
- spec/spec_helper.rb
|
275
283
|
- spec/stubs.rb
|
276
|
-
- spec/translator_spec.rb
|
277
284
|
- spec/validator_spec.rb
|
278
285
|
- spec/ymdp_base_spec.rb
|
279
286
|
- spec/ymdp_spec.rb
|
@@ -323,7 +330,6 @@ test_files:
|
|
323
330
|
- spec/git_helper_spec.rb
|
324
331
|
- spec/spec_helper.rb
|
325
332
|
- spec/stubs.rb
|
326
|
-
- spec/translator_spec.rb
|
327
333
|
- spec/validator_spec.rb
|
328
334
|
- spec/ymdp_base_spec.rb
|
329
335
|
- spec/ymdp_spec.rb
|
data/bin/ymdp
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
dir = File.dirname(__FILE__)
|
6
|
-
|
7
|
-
new_application_dir = "#{dir}/../lib/new_application"
|
8
|
-
|
9
|
-
@command = ARGV[0]
|
10
|
-
|
11
|
-
if @command == "init"
|
12
|
-
|
13
|
-
# Create the structure for a YMDP project
|
14
|
-
|
15
|
-
@project_name = ARGV[1]
|
16
|
-
|
17
|
-
@message = <<MESSAGE
|
18
|
-
Creating YMDP directory for project #{@project_name}
|
19
|
-
|
20
|
-
First, run:
|
21
|
-
|
22
|
-
gem bundle
|
23
|
-
|
24
|
-
Then:
|
25
|
-
|
26
|
-
./script/config
|
27
|
-
|
28
|
-
Then open config.yml and set your username and password.
|
29
|
-
Then open servers.yml and set your server keys.
|
30
|
-
|
31
|
-
Then run:
|
32
|
-
|
33
|
-
bin/rake create:all
|
34
|
-
|
35
|
-
to fetch your applications from Yahoo! Mail's servers.
|
36
|
-
|
37
|
-
MESSAGE
|
38
|
-
|
39
|
-
puts @message
|
40
|
-
|
41
|
-
FileUtils.mkdir_p(@project_name)
|
42
|
-
FileUtils.cp_r("#{new_application_dir}/.", @project_name)
|
43
|
-
elsif @command == "update"
|
44
|
-
puts "Updating scripts..."
|
45
|
-
FileUtils.cp_r(Dir.glob("#{new_application_dir}/config/*.example"), "./config", :verbose => true)
|
46
|
-
FileUtils.cp_r("#{new_application_dir}/lib/tasks/.", "./lib/tasks", :verbose => true)
|
47
|
-
FileUtils.cp_r("#{new_application_dir}/script/.", "./script", :verbose => true)
|
48
|
-
FileUtils.cp_r("#{new_application_dir}/ymdp", "./", :verbose => true)
|
49
|
-
end
|
50
|
-
|
data/lib/ymdp/translator/base.rb
DELETED
@@ -1,390 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rtranslate'
|
3
|
-
require 'timer'
|
4
|
-
require 'compiler/template'
|
5
|
-
|
6
|
-
module YMDP
|
7
|
-
module Yaml #:nodoc:
|
8
|
-
module Support #:nodoc:
|
9
|
-
FILENAME_REGEXP = /(.*)_(..-..)\.yml$/
|
10
|
-
|
11
|
-
def language_path(lang)
|
12
|
-
"#{base_path}/app/assets/yrb/#{lang}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def base_filename(path)
|
16
|
-
filename = path.split("/").last
|
17
|
-
filename =~ FILENAME_REGEXP
|
18
|
-
$1
|
19
|
-
end
|
20
|
-
|
21
|
-
def language(path)
|
22
|
-
filename = path.split("/").last
|
23
|
-
filename =~ FILENAME_REGEXP
|
24
|
-
$2
|
25
|
-
end
|
26
|
-
|
27
|
-
def destination_path(filename, lang)
|
28
|
-
filename ||= base_filename(filename)
|
29
|
-
"#{language_path(lang)}/#{filename}_#{lang}.yml"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module YRB #:nodoc:
|
35
|
-
module Support #:nodoc:
|
36
|
-
FILENAME_REGEXP = /(.*)_(..-..)\.pres$/
|
37
|
-
|
38
|
-
def language_path(lang)
|
39
|
-
"#{base_path}/app/assets/yrb/#{lang}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def base_filename(path)
|
43
|
-
filename = path.split("/").last
|
44
|
-
filename =~ FILENAME_REGEXP
|
45
|
-
$1
|
46
|
-
end
|
47
|
-
|
48
|
-
def language(path)
|
49
|
-
filename = path.split("/").last
|
50
|
-
filename =~ FILENAME_REGEXP
|
51
|
-
$2
|
52
|
-
end
|
53
|
-
|
54
|
-
def destination_path(filename, lang)
|
55
|
-
filename ||= base_filename(filename)
|
56
|
-
"#{language_path(lang)}/#{filename}_#{lang}.pres"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
module Translator #:nodoc:
|
62
|
-
module Support #:nodoc:
|
63
|
-
# Mapping of the way Yahoo! Mail represents country codes with the way Google Translate does.
|
64
|
-
#
|
65
|
-
# The key is the Yahoo! Mail representation, and the value is the code Google Translate would expect.
|
66
|
-
#
|
67
|
-
LOCALES = {
|
68
|
-
"de-DE" => "de",
|
69
|
-
"en-MY" => "en",
|
70
|
-
"en-SG" => "en",
|
71
|
-
"es-MX" => "es",
|
72
|
-
"it-IT" => "it",
|
73
|
-
"vi-VN" => "vi",
|
74
|
-
"zh-Hant-TW" => "zh-TW",
|
75
|
-
"en-AA" => "en",
|
76
|
-
"en-NZ" => "en",
|
77
|
-
"en-US" => "en",
|
78
|
-
"fr-FR" => "fr",
|
79
|
-
"ko-KR" => "ko",
|
80
|
-
"zh-Hans-CN" => "zh-CN",
|
81
|
-
"en-AU" => "en",
|
82
|
-
"en-PH" => "en",
|
83
|
-
"es-ES" => "es",
|
84
|
-
"id-ID" => "id",
|
85
|
-
"pt-BR" => "PORTUGUESE",
|
86
|
-
"zh-Hant-HK" => "zh-CN",
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
# Finds English language translation keys which have not been translated
|
91
|
-
# and translates them through Google Translate.
|
92
|
-
#
|
93
|
-
class Base < YMDP::Base
|
94
|
-
include YMDP::Translator::Support
|
95
|
-
|
96
|
-
def self.original_translations
|
97
|
-
Dir["#{language_path('en-US')}/#{all_source_files}"]
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.all_source_files
|
101
|
-
raise "Define in child"
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.template
|
105
|
-
raise "Define in child"
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.language_path(lang)
|
109
|
-
raise "Define in child"
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.translate
|
113
|
-
Timer.new(:title => "YMDP").time do
|
114
|
-
original_translations.each do |path|
|
115
|
-
$stdout.puts "Processing #{display_path(path)}"
|
116
|
-
template.new(path).copy
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# instance methods
|
122
|
-
|
123
|
-
attr_accessor :path, :lang, :filename
|
124
|
-
|
125
|
-
def initialize(path)
|
126
|
-
@path = path
|
127
|
-
@lang = language(path)
|
128
|
-
@filename = base_filename(path)
|
129
|
-
end
|
130
|
-
|
131
|
-
def language(path)
|
132
|
-
raise "Define in child"
|
133
|
-
end
|
134
|
-
|
135
|
-
def copy
|
136
|
-
copy_lines_to_all_locales
|
137
|
-
end
|
138
|
-
|
139
|
-
def non_us_locales
|
140
|
-
@non_us_locales ||= LOCALES.select do |lang, code|
|
141
|
-
lang != "en-US"
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def copy_lines_to_all_locales
|
146
|
-
non_us_locales.each do |lang, code|
|
147
|
-
destination = destination_path(filename, lang)
|
148
|
-
new_content = each_line do |line|
|
149
|
-
copy_and_translate_line(line, lang)
|
150
|
-
end
|
151
|
-
write_content(destination, new_content)
|
152
|
-
clear_all_keys
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
def write_content(destination, content)
|
157
|
-
unless content.blank?
|
158
|
-
$stdout.puts "Writing to #{display_path(destination)}"
|
159
|
-
$stdout.puts content
|
160
|
-
$stdout.puts
|
161
|
-
File.open(destination, "a") do |f|
|
162
|
-
f.puts
|
163
|
-
f.puts new_translation_message
|
164
|
-
f.puts content
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def new_translation_message
|
170
|
-
now = Time.now
|
171
|
-
|
172
|
-
date = now.day
|
173
|
-
month = now.month
|
174
|
-
year = now.year
|
175
|
-
|
176
|
-
timestamp = "#{date}/#{month}/#{year}"
|
177
|
-
output = []
|
178
|
-
output << "# "
|
179
|
-
output << "# Keys translated automatically on #{timestamp}."
|
180
|
-
output << "# "
|
181
|
-
|
182
|
-
output.join("\n")
|
183
|
-
end
|
184
|
-
|
185
|
-
def each_line
|
186
|
-
output = []
|
187
|
-
@lines ||= File.readlines(path)
|
188
|
-
|
189
|
-
@lines.each do |line|
|
190
|
-
new_line = yield line
|
191
|
-
output << new_line unless line.blank?
|
192
|
-
end
|
193
|
-
output.flatten.join("\n")
|
194
|
-
end
|
195
|
-
|
196
|
-
def all_keys(lang)
|
197
|
-
unless @all_keys
|
198
|
-
@all_keys = {}
|
199
|
-
Dir["#{language_path(lang)}/#{all_source_files}"].each do |p|
|
200
|
-
@all_keys = @all_keys.merge(parse_template(p))
|
201
|
-
end
|
202
|
-
end
|
203
|
-
@all_keys
|
204
|
-
end
|
205
|
-
|
206
|
-
def parse_template(p)
|
207
|
-
raise "Define in child"
|
208
|
-
end
|
209
|
-
|
210
|
-
def clear_all_keys
|
211
|
-
@all_keys = nil
|
212
|
-
end
|
213
|
-
|
214
|
-
def copy_and_translate_line(line, lang)
|
215
|
-
line = line.split("\n").first
|
216
|
-
if comment?(line) || line.blank?
|
217
|
-
nil
|
218
|
-
else
|
219
|
-
translate_new_key(line, lang)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def key_is_new?(k, lang)
|
224
|
-
k && !all_keys(lang).has_key?(k)
|
225
|
-
end
|
226
|
-
|
227
|
-
def translate_new_key(line, lang)
|
228
|
-
k, v = key_and_value_from_line(line)
|
229
|
-
if key_is_new?(k, lang)
|
230
|
-
format(k, translate(v, lang))
|
231
|
-
else
|
232
|
-
nil
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def translate(value, lang)
|
237
|
-
code = LOCALES[lang]
|
238
|
-
value = pre_process(value, lang)
|
239
|
-
translation = Translate.t(value, "ENGLISH", code)
|
240
|
-
post_process(translation, lang)
|
241
|
-
end
|
242
|
-
|
243
|
-
def pre_process(value, lang)
|
244
|
-
vars = []
|
245
|
-
index = 0
|
246
|
-
while value =~ /(\{\d+\})/
|
247
|
-
vars << $1
|
248
|
-
value.sub!(/(\{\d+\})/, "[#{index}]")
|
249
|
-
index += 1
|
250
|
-
end
|
251
|
-
value
|
252
|
-
end
|
253
|
-
|
254
|
-
def post_process(value, lang)
|
255
|
-
if lang =~ /zh/
|
256
|
-
value.gsub!("<strong>", "")
|
257
|
-
value.gsub!("</strong>", "")
|
258
|
-
end
|
259
|
-
|
260
|
-
value.gsub!(/^#{194.chr}#{160.chr}/, "")
|
261
|
-
|
262
|
-
value.gsub!(" ]", "]")
|
263
|
-
value.gsub!("«", "\"")
|
264
|
-
value.gsub!("»", "\"")
|
265
|
-
value.gsub!(/\"\.$/, ".\"")
|
266
|
-
value.gsub!(/\\ \"/, "\\\"")
|
267
|
-
value.gsub!(/<\/ /, "<\/")
|
268
|
-
value.gsub!(/(“|”)/, "\"")
|
269
|
-
value.gsub!("<strong> ", "<strong>")
|
270
|
-
value.gsub!(" </strong>", "</strong>")
|
271
|
-
value.gsub!(""", "\"")
|
272
|
-
value.gsub!("'", "\"")
|
273
|
-
value.gsub!("> ", ">")
|
274
|
-
|
275
|
-
value.gsub!("\"", "'")
|
276
|
-
value.gsub!(" \"O", " \\\"O")
|
277
|
-
|
278
|
-
while value =~ /\[(\d)\]/
|
279
|
-
index = $1.to_i
|
280
|
-
value.sub!(/\[#{index}\]/, "{#{index}}")
|
281
|
-
end
|
282
|
-
|
283
|
-
value.gsub!(/\((0)\)/, "{0}")
|
284
|
-
value.gsub!(/\((1)\)/, "{1}")
|
285
|
-
value.gsub!(/\((2)\)/, "{2}")
|
286
|
-
value.gsub!("(0)", "{0}")
|
287
|
-
|
288
|
-
value.strip
|
289
|
-
end
|
290
|
-
|
291
|
-
def format(key, value)
|
292
|
-
raise "Define in child"
|
293
|
-
end
|
294
|
-
|
295
|
-
def key_and_value_from_line(line)
|
296
|
-
raise "Define in child"
|
297
|
-
end
|
298
|
-
|
299
|
-
def comment?(line)
|
300
|
-
raise "Define in child"
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
# Usage:
|
305
|
-
# YMDP::Translator::Yaml.new().copy
|
306
|
-
#
|
307
|
-
class Yaml < Base
|
308
|
-
include YMDP::Yaml::Support
|
309
|
-
extend YMDP::Yaml::Support
|
310
|
-
|
311
|
-
def self.template
|
312
|
-
Yaml
|
313
|
-
end
|
314
|
-
|
315
|
-
def self.all_source_files
|
316
|
-
"*.yml"
|
317
|
-
end
|
318
|
-
|
319
|
-
def all_source_files
|
320
|
-
"*.yml"
|
321
|
-
end
|
322
|
-
|
323
|
-
def parse_template(path)
|
324
|
-
YAML.load_file(path)
|
325
|
-
end
|
326
|
-
|
327
|
-
def format(key, value)
|
328
|
-
"#{key}: #{value}"
|
329
|
-
end
|
330
|
-
|
331
|
-
def key_and_value_from_line(line)
|
332
|
-
if line =~ /^([^\:]+):(.*)/
|
333
|
-
return $1, $2.strip
|
334
|
-
else
|
335
|
-
return nil, nil
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
def comment?(line)
|
340
|
-
line =~ /^[\s]*#/
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
# Usage:
|
345
|
-
# YMDP::Translator::YRB.new().copy
|
346
|
-
#
|
347
|
-
class YRB < Base
|
348
|
-
include YMDP::YRB::Support
|
349
|
-
extend YMDP::YRB::Support
|
350
|
-
|
351
|
-
def self.template
|
352
|
-
YRB
|
353
|
-
end
|
354
|
-
|
355
|
-
def self.all_source_files
|
356
|
-
"*.pres"
|
357
|
-
end
|
358
|
-
|
359
|
-
def all_source_files
|
360
|
-
"*.pres"
|
361
|
-
end
|
362
|
-
|
363
|
-
def parse_template(p)
|
364
|
-
YMDP::Compiler::Template::YRB.new(:file => p, :domain => "staging").to_hash
|
365
|
-
end
|
366
|
-
|
367
|
-
def format(key, value)
|
368
|
-
"#{key}=#{value}"
|
369
|
-
end
|
370
|
-
|
371
|
-
def translate(value, lang)
|
372
|
-
unless value.blank?
|
373
|
-
super(value, lang)
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
def key_and_value_from_line(line)
|
378
|
-
if line =~ /^([^\=]+)=(.+)/
|
379
|
-
return $1, $2
|
380
|
-
else
|
381
|
-
return nil, nil
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
def comment?(line)
|
386
|
-
line =~ /^[\s]*#/
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
data/spec/translator_spec.rb
DELETED
@@ -1,322 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'translator/base'
|
4
|
-
|
5
|
-
describe "Translator" do
|
6
|
-
before(:each) do
|
7
|
-
stub_timer
|
8
|
-
stub_screen_io
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "Yaml" do
|
12
|
-
before(:each) do
|
13
|
-
YAML.stub!(:load_file).and_return({"hi" => "what"})
|
14
|
-
@original_translations = ["application_en-US.yml", "sidebar_en-US.yml"]
|
15
|
-
Dir.stub!(:[]).with(/app\/assets\/yrb\/en-US\/\*\.yml/).and_return(@original_translations)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "class methods" do
|
19
|
-
it "should output a message for each file" do
|
20
|
-
File.stub!(:readlines).and_return([""])
|
21
|
-
@original_translations.each do |file|
|
22
|
-
$stdout.should_receive(:puts).with(/Processing /)
|
23
|
-
end
|
24
|
-
YMDP::Translator::Yaml.translate
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should instantiate a new template" do
|
28
|
-
@original_translations.each do |file|
|
29
|
-
@yaml = mock('yaml', :copy => true)
|
30
|
-
YMDP::Translator::Yaml.should_receive(:new).with(file).and_return(@yaml)
|
31
|
-
end
|
32
|
-
YMDP::Translator::Yaml.translate
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should copy the new template" do
|
36
|
-
@original_translations.each do |file|
|
37
|
-
@yaml = mock('yaml', :copy => true)
|
38
|
-
@yaml.should_receive(:copy)
|
39
|
-
YMDP::Translator::Yaml.stub!(:new).with(file).and_return(@yaml)
|
40
|
-
end
|
41
|
-
YMDP::Translator::Yaml.translate
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "instance methods" do
|
46
|
-
before(:each) do
|
47
|
-
@path = "path_en-US.yml"
|
48
|
-
@yml = YMDP::Translator::Yaml.new(@path)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should instantiate" do
|
52
|
-
@yml.should_not be_nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should copy keys" do
|
56
|
-
File.stub!(:readlines).with("path_en-US.yml").and_return(["key: value\n"])
|
57
|
-
#
|
58
|
-
@file = mock('file', :puts => true)
|
59
|
-
@file.should_receive(:puts).with(/key: translated value/)
|
60
|
-
|
61
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
62
|
-
|
63
|
-
size = YMDP::Translator::Yaml::LOCALES.size - 1
|
64
|
-
|
65
|
-
YMDP::Translator::Yaml::LOCALES.each do |lang, code|
|
66
|
-
unless lang == "en-US"
|
67
|
-
Dir.should_receive(:[]).with(/app\/assets\/yrb\/#{lang}\/\*\.yml/).and_return(["keys_#{lang}.yml"])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
Translate.stub!(:t).with("value", "ENGLISH", anything).exactly(size).and_return("translated value")
|
72
|
-
|
73
|
-
@yml.copy
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should not copy comments" do
|
77
|
-
File.stub!(:readlines).with("path_en-US.yml").and_return(["# comment\n"])
|
78
|
-
|
79
|
-
@file = mock('file', :puts => true)
|
80
|
-
@file.should_not_receive(:puts).with(/key: translated value/)
|
81
|
-
|
82
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
83
|
-
|
84
|
-
size = YMDP::Translator::Yaml::LOCALES.size - 1
|
85
|
-
Translate.stub!(:t).with("value", "ENGLISH", anything).exactly(size).and_return("translated value")
|
86
|
-
|
87
|
-
@yml.copy
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should not copy empty keys" do
|
91
|
-
File.stub!(:readlines).with("path_en-US.yml").and_return(["KEY=\n"])
|
92
|
-
|
93
|
-
@file = mock('file', :puts => true)
|
94
|
-
@file.should_not_receive(:puts).with(/key: translated value/)
|
95
|
-
|
96
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
97
|
-
|
98
|
-
size = YMDP::Translator::Yaml::LOCALES.size - 1
|
99
|
-
Translate.stub!(:t).with("value", "ENGLISH", anything).exactly(size).and_return("translated value")
|
100
|
-
|
101
|
-
@yml.copy
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should copy keys with variables" do
|
105
|
-
File.stub!(:readlines).with("path_en-US.yml").and_return(["key: value {0}\n"])
|
106
|
-
|
107
|
-
@file = mock('file', :puts => true)
|
108
|
-
@file.should_receive(:puts).with(/key: translated value {0}/)
|
109
|
-
|
110
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
111
|
-
|
112
|
-
size = YMDP::Translator::Yaml::LOCALES.size - 1
|
113
|
-
|
114
|
-
YMDP::Translator::Yaml::LOCALES.each do |lang, code|
|
115
|
-
unless lang == "en-US"
|
116
|
-
Dir.should_receive(:[]).with(/app\/assets\/yrb\/#{lang}\/\*\.yml/).and_return(["keys_#{lang}.yml"])
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
Translate.stub!(:t).with("value [0]", "ENGLISH", anything).exactly(size).and_return("translated value [0]")
|
121
|
-
|
122
|
-
@yml.copy
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "YRB" do
|
128
|
-
before(:each) do
|
129
|
-
@original_translations = ["application_en-US.pres", "sidebar_en-US.pres"]
|
130
|
-
Dir.stub!(:[]).with(/app\/assets\/yrb\/en-US\/\*\.pres/).and_return(@original_translations)
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "class methods" do
|
134
|
-
it "should output a message for each file" do
|
135
|
-
File.stub!(:readlines).and_return([""])
|
136
|
-
@original_translations.each do |file|
|
137
|
-
$stdout.should_receive(:puts).with(/Processing /)
|
138
|
-
end
|
139
|
-
YMDP::Translator::YRB.translate
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should instantiate a new template" do
|
143
|
-
@original_translations.each do |file|
|
144
|
-
@yrb = mock('yrb', :copy => true)
|
145
|
-
YMDP::Translator::YRB.should_receive(:new).with(file).and_return(@yrb)
|
146
|
-
end
|
147
|
-
YMDP::Translator::YRB.translate
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should copy the new template" do
|
151
|
-
@original_translations.each do |file|
|
152
|
-
@yrb = mock('yrb', :copy => true)
|
153
|
-
@yrb.should_receive(:copy)
|
154
|
-
YMDP::Translator::YRB.stub!(:new).with(file).and_return(@yrb)
|
155
|
-
end
|
156
|
-
YMDP::Translator::YRB.translate
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "instance methods" do
|
161
|
-
before(:each) do
|
162
|
-
@path = "path_en-US.pres"
|
163
|
-
@yrb = YMDP::Translator::YRB.new(@path)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should instantiate" do
|
167
|
-
@yrb.should_not be_nil
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should copy keys" do
|
171
|
-
File.stub!(:readlines).with("path_en-US.pres").and_return(["KEY=value\n"])
|
172
|
-
|
173
|
-
@file = mock('file', :puts => true)
|
174
|
-
@file.should_receive(:puts).with(/KEY=translated value/)
|
175
|
-
|
176
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
177
|
-
|
178
|
-
size = YMDP::Translator::YRB::LOCALES.size - 1
|
179
|
-
|
180
|
-
@template = mock('template', :to_hash => {"key" => "value"})
|
181
|
-
YMDP::Compiler::Template::YRB.stub!(:new).and_return(@template)
|
182
|
-
|
183
|
-
YMDP::Translator::YRB::LOCALES.each do |lang, code|
|
184
|
-
unless lang == "en-US"
|
185
|
-
Dir.should_receive(:[]).with(/app\/assets\/yrb\/#{lang}\/\*\.pres/).and_return(["keys_#{lang}.pres"])
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
Translate.stub!(:t).with("value", "ENGLISH", anything).exactly(size).and_return("translated value")
|
190
|
-
|
191
|
-
@yrb.copy
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should not copy comments" do
|
195
|
-
File.stub!(:readlines).with("path_en-US.pres").and_return(["# comment\n"])
|
196
|
-
|
197
|
-
@file = mock('file', :puts => true)
|
198
|
-
@file.should_not_receive(:puts).with(/KEY=translated value/)
|
199
|
-
|
200
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
201
|
-
|
202
|
-
size = YMDP::Translator::YRB::LOCALES.size - 1
|
203
|
-
Translate.stub!(:t).with("value", "ENGLISH", anything).exactly(size).and_return("translated value")
|
204
|
-
|
205
|
-
@yrb.copy
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should not copy empty keys" do
|
209
|
-
File.stub!(:readlines).with("path_en-US.pres").and_return(["KEY=\n"])
|
210
|
-
|
211
|
-
@file = mock('file', :puts => true)
|
212
|
-
@file.should_not_receive(:puts).with(/KEY=translated value/)
|
213
|
-
|
214
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
215
|
-
|
216
|
-
size = YMDP::Translator::YRB::LOCALES.size - 1
|
217
|
-
Translate.stub!(:t).with("value", "ENGLISH", anything).exactly(size).and_return("translated value")
|
218
|
-
|
219
|
-
@yrb.copy
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should copy keys with variables" do
|
223
|
-
File.stub!(:readlines).with("path_en-US.pres").and_return(["KEY=value {0}\n"])
|
224
|
-
|
225
|
-
@file = mock('file', :puts => true)
|
226
|
-
@file.should_receive(:puts).with(/KEY=translated value {0}/)
|
227
|
-
|
228
|
-
File.stub!(:open).with(anything, "a").and_yield(@file)
|
229
|
-
|
230
|
-
size = YMDP::Translator::YRB::LOCALES.size - 1
|
231
|
-
|
232
|
-
@template = mock('template', :to_hash => {"key" => "value"})
|
233
|
-
YMDP::Compiler::Template::YRB.stub!(:new).and_return(@template)
|
234
|
-
|
235
|
-
YMDP::Translator::YRB::LOCALES.each do |lang, code|
|
236
|
-
unless lang == "en-US"
|
237
|
-
Dir.should_receive(:[]).with(/app\/assets\/yrb\/#{lang}\/\*\.pres/).and_return(["keys_#{lang}.pres"])
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
Translate.stub!(:t).with("value [0]", "ENGLISH", anything).exactly(size).and_return("translated value [0]")
|
242
|
-
|
243
|
-
@yrb.copy
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe "Base" do
|
249
|
-
describe "class methods" do
|
250
|
-
it "should raise error on original_translations" do
|
251
|
-
lambda {
|
252
|
-
YMDP::Translator::Base.original_translations
|
253
|
-
}.should raise_error("Define in child")
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should raise error on all_source_files" do
|
257
|
-
lambda {
|
258
|
-
YMDP::Translator::Base.all_source_files
|
259
|
-
}.should raise_error("Define in child")
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should raise error on template" do
|
263
|
-
lambda {
|
264
|
-
YMDP::Translator::Base.template
|
265
|
-
}.should raise_error("Define in child")
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should raise error on translate" do
|
269
|
-
lambda {
|
270
|
-
YMDP::Translator::Base.translate
|
271
|
-
}.should raise_error("Define in child")
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
describe "instance methods" do
|
276
|
-
it "should raise an error on instantiation" do
|
277
|
-
lambda {
|
278
|
-
@base = YMDP::Translator::Base.new("path")
|
279
|
-
}.should raise_error("Define in child")
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
describe "raise in child" do
|
284
|
-
before(:each) do
|
285
|
-
class YMDPTranslatorBase < YMDP::Translator::Base
|
286
|
-
def language(path)
|
287
|
-
"en-US"
|
288
|
-
end
|
289
|
-
|
290
|
-
def base_filename(path)
|
291
|
-
path
|
292
|
-
end
|
293
|
-
end
|
294
|
-
@thing = YMDPTranslatorBase.new("path")
|
295
|
-
end
|
296
|
-
|
297
|
-
it "should raise an error calling parse_template" do
|
298
|
-
lambda {
|
299
|
-
@thing.parse_template("path")
|
300
|
-
}.should raise_error("Define in child")
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should raise an error calling format" do
|
304
|
-
lambda {
|
305
|
-
@thing.format("a", "b")
|
306
|
-
}.should raise_error("Define in child")
|
307
|
-
end
|
308
|
-
|
309
|
-
it "should raise an error calling key_and_value_from_line" do
|
310
|
-
lambda {
|
311
|
-
@thing.key_and_value_from_line("line")
|
312
|
-
}.should raise_error("Define in child")
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should raise an error calling comment?" do
|
316
|
-
lambda {
|
317
|
-
@thing.comment?("line")
|
318
|
-
}.should raise_error("Define in child")
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|