idiom 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +31 -0
- data/Rakefile +0 -26
- data/VERSION +1 -1
- data/idiom.gemspec +10 -15
- data/lib/idiom.rb +1 -1
- data/lib/idiom/base.rb +51 -8
- data/lib/idiom/yaml.rb +7 -7
- metadata +33 -35
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm ree-1.8.7-2011.03@idiom
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.1)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
i18n (0.6.0)
|
9
|
+
json (1.6.5)
|
10
|
+
multi_json (1.0.4)
|
11
|
+
rspec (2.8.0)
|
12
|
+
rspec-core (~> 2.8.0)
|
13
|
+
rspec-expectations (~> 2.8.0)
|
14
|
+
rspec-mocks (~> 2.8.0)
|
15
|
+
rspec-core (2.8.0)
|
16
|
+
rspec-expectations (2.8.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.8.0)
|
19
|
+
sishen-rtranslate (1.5)
|
20
|
+
activesupport (>= 2.2.0)
|
21
|
+
json (>= 1.1.3)
|
22
|
+
yrb (0.0.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
activesupport
|
29
|
+
rspec
|
30
|
+
sishen-rtranslate
|
31
|
+
yrb
|
data/Rakefile
CHANGED
@@ -24,35 +24,9 @@ rescue LoadError
|
|
24
24
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
25
|
end
|
26
26
|
|
27
|
-
require 'spec/rake/spectask'
|
28
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
29
|
-
spec.libs << 'lib' << 'spec'
|
30
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
-
spec.spec_opts = ['-c']
|
32
|
-
end
|
33
|
-
|
34
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
35
|
-
spec.libs << 'lib' << 'spec'
|
36
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
-
spec.rcov_opts = ['--exclude', '.gem,Library,spec', '--sort', 'coverage']
|
38
|
-
spec.rcov = true
|
39
|
-
end
|
40
27
|
|
41
28
|
task :bundle do
|
42
29
|
require 'vendor/gems/environment'
|
43
30
|
Bundler.require_env
|
44
31
|
end
|
45
32
|
|
46
|
-
task :spec => [:bundle, :check_dependencies]
|
47
|
-
|
48
|
-
task :default => :spec
|
49
|
-
|
50
|
-
require 'rake/rdoctask'
|
51
|
-
Rake::RDocTask.new do |rdoc|
|
52
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "idiom #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/idiom.gemspec
CHANGED
@@ -4,15 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "idiom"
|
8
|
+
s.version = "0.5.0"
|
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 =
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.email = %q{progressions@gmail.com}
|
12
|
+
s.date = "2012-02-20"
|
13
|
+
s.description = "Takes a set of keys in Yaml format and translates them through Google Translate."
|
14
|
+
s.email = "progressions@gmail.com"
|
16
15
|
s.executables = ["idiom"]
|
17
16
|
s.extra_rdoc_files = [
|
18
17
|
"LICENSE",
|
@@ -20,7 +19,9 @@ Gem::Specification.new do |s|
|
|
20
19
|
]
|
21
20
|
s.files = [
|
22
21
|
".document",
|
22
|
+
".rvmrc",
|
23
23
|
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
24
25
|
"History.txt",
|
25
26
|
"LICENSE",
|
26
27
|
"README.rdoc",
|
@@ -39,18 +40,12 @@ Gem::Specification.new do |s|
|
|
39
40
|
"spec/spec_helper.rb",
|
40
41
|
"spec/stubs.rb"
|
41
42
|
]
|
42
|
-
s.homepage =
|
43
|
+
s.homepage = "http://github.com/progressions/idiom"
|
43
44
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version =
|
45
|
-
s.summary =
|
46
|
-
s.test_files = [
|
47
|
-
"spec/idiom_spec.rb",
|
48
|
-
"spec/spec_helper.rb",
|
49
|
-
"spec/stubs.rb"
|
50
|
-
]
|
45
|
+
s.rubygems_version = "1.8.12"
|
46
|
+
s.summary = "Translate all your application's international keys in Google Translate"
|
51
47
|
|
52
48
|
if s.respond_to? :specification_version then
|
53
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
49
|
s.specification_version = 3
|
55
50
|
|
56
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/idiom.rb
CHANGED
data/lib/idiom/base.rb
CHANGED
@@ -59,6 +59,27 @@ module Idiom #:nodoc:
|
|
59
59
|
|
60
60
|
module Processing #:nodoc:
|
61
61
|
def pre_process(value, lang)
|
62
|
+
# extract %{substitution_var} => @substitution_vars = ['substitution_var']
|
63
|
+
#
|
64
|
+
# This prevents the translator from seeing the substitution_var, in case it
|
65
|
+
# tries to e.g. downcase it or whatever.
|
66
|
+
@substitution_vars = []
|
67
|
+
while value =~ /%\{([^\}]*)\}/
|
68
|
+
value.sub! /%\{([^\}]*)\}/, "|#{@substitution_vars.count}|"
|
69
|
+
@substitution_vars << $1
|
70
|
+
end
|
71
|
+
|
72
|
+
# extract '''pass through''' / ===pass through=== => @pass_through_vars = ['pass through']
|
73
|
+
#
|
74
|
+
# This allows string to be passed through without being translated
|
75
|
+
# differs from @substitution_vars in that the underscore markup
|
76
|
+
# will be stripped from the final result
|
77
|
+
@pass_through_vars = []
|
78
|
+
while value =~ /(?:(?:===)|(?:'''))(.*?)(?:(?:===)|(?:'''))/
|
79
|
+
value.sub! /(?:(?:===)|(?:'''))(.*?)(?:(?:===)|(?:'''))/, "__#{@pass_through_vars.count}__"
|
80
|
+
@pass_through_vars << $1
|
81
|
+
end
|
82
|
+
|
62
83
|
vars = []
|
63
84
|
index = 0
|
64
85
|
while value =~ /(\{\d+\})/
|
@@ -73,10 +94,10 @@ module Idiom #:nodoc:
|
|
73
94
|
|
74
95
|
value.gsub!("{{", "{{_")
|
75
96
|
value.gsub!("}}", "_}}")
|
76
|
-
|
97
|
+
|
77
98
|
value
|
78
99
|
end
|
79
|
-
|
100
|
+
|
80
101
|
def post_process(value, lang)
|
81
102
|
value.gsub!('"。', '。"')
|
82
103
|
value.gsub!(/^[''"「«]+/, "")
|
@@ -91,15 +112,25 @@ module Idiom #:nodoc:
|
|
91
112
|
value.gsub!("{{_", "{{")
|
92
113
|
value.gsub!("_}}", "}}")
|
93
114
|
value.gsub!(/\\$/, "")
|
94
|
-
|
115
|
+
|
95
116
|
value.strip!
|
96
117
|
value.capitalize!
|
97
118
|
value = "\"#{value}\"" if value.present?
|
98
|
-
|
119
|
+
|
120
|
+
# Replace substitution vars
|
121
|
+
while value =~ /\|([^\|]+)\|/
|
122
|
+
value.sub! /\|([^\|]+)\|/, "%{#{@substitution_vars[$1.to_i]}}"
|
123
|
+
end
|
124
|
+
|
125
|
+
# Replace pass-through content
|
126
|
+
while value =~ /__(.*?)__/
|
127
|
+
value.sub! /__(.*?)__/, @pass_through_vars[$1.to_i]
|
128
|
+
end
|
129
|
+
|
99
130
|
value
|
100
131
|
end
|
101
132
|
end
|
102
|
-
|
133
|
+
|
103
134
|
module ClassMethods #:nodoc:
|
104
135
|
def translate(options={})
|
105
136
|
options.stringify_keys!
|
@@ -165,12 +196,22 @@ module Idiom #:nodoc:
|
|
165
196
|
#
|
166
197
|
attr_accessor :languages
|
167
198
|
|
199
|
+
# Cached array of subsitution variables
|
200
|
+
#
|
201
|
+
attr_accessor :substitution_vars
|
202
|
+
|
203
|
+
# Cached array of pass-through content
|
204
|
+
#
|
205
|
+
attr_accessor :pass_through_vars
|
206
|
+
|
168
207
|
def initialize(options={})
|
169
208
|
options.stringify_keys!
|
170
209
|
|
171
210
|
@source = File.expand_path(options["source"])
|
172
211
|
@overwrite = options["overwrite"]
|
173
212
|
@languages = options["languages"]
|
213
|
+
@substitution_vars = []
|
214
|
+
@pass_through_vars = []
|
174
215
|
|
175
216
|
@base_source = @source.gsub(/_en-US/, "")
|
176
217
|
|
@@ -195,9 +236,11 @@ module Idiom #:nodoc:
|
|
195
236
|
|
196
237
|
def generate
|
197
238
|
before_translation
|
239
|
+
# RM NOTE: Async concurrent by language?
|
198
240
|
non_us_locales.each do |lang|
|
199
241
|
code = LOCALES[lang]
|
200
242
|
destination = ensure_destination_path_exists(lang)
|
243
|
+
# RM NOTE: this breaks on multi-line strings
|
201
244
|
new_content = each_line do |line|
|
202
245
|
copy_and_translate_line(line, lang)
|
203
246
|
end
|
@@ -306,14 +349,14 @@ module Idiom #:nodoc:
|
|
306
349
|
end
|
307
350
|
|
308
351
|
def translate(value, lang)
|
352
|
+
return '' if value == ''
|
309
353
|
$stdout.puts("Translating #{value} into #{lang}...")
|
310
354
|
code = LOCALES[lang]
|
311
355
|
value = pre_process(value, lang)
|
312
|
-
|
356
|
+
|
313
357
|
translation = do_translate(value, code)
|
314
|
-
|
358
|
+
|
315
359
|
value = post_process(translation, lang)
|
316
|
-
$stdout.puts("value: #{value}")
|
317
360
|
value
|
318
361
|
end
|
319
362
|
|
data/lib/idiom/yaml.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'idiom/base'
|
2
|
-
|
2
|
+
|
3
3
|
module Idiom #:nodoc:
|
4
4
|
# Usage:
|
5
5
|
# Translator::Yaml.new().copy
|
@@ -11,20 +11,20 @@ module Idiom #:nodoc:
|
|
11
11
|
|
12
12
|
def after_translation
|
13
13
|
system "cat #{destination_path} >> #{source} && rm #{destination_path}"
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
16
|
def extension
|
17
17
|
"yml"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def parse(path)
|
21
21
|
YAML.load_file(path) || {}
|
22
|
-
|
23
|
-
|
22
|
+
end
|
23
|
+
|
24
24
|
def format(key, value)
|
25
25
|
"#{key}: #{value}"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def key_and_value_from_line(line)
|
29
29
|
if line =~ /^([^\:]+):(.*)/
|
30
30
|
return $1, $2.strip
|
@@ -33,4 +33,4 @@ module Idiom #:nodoc:
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idiom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 11
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeff Coleman
|
@@ -15,10 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable: idiom
|
18
|
+
date: 2012-02-20 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
@@ -28,11 +28,11 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
|
-
|
31
|
+
version_requirements: *id001
|
32
32
|
name: rspec
|
33
33
|
prerelease: false
|
34
|
-
version_requirements: *id001
|
35
34
|
- !ruby/object:Gem::Dependency
|
35
|
+
type: :runtime
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
38
38
|
requirements:
|
@@ -42,11 +42,11 @@ dependencies:
|
|
42
42
|
segments:
|
43
43
|
- 0
|
44
44
|
version: "0"
|
45
|
-
|
45
|
+
version_requirements: *id002
|
46
46
|
name: activesupport
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *id002
|
49
48
|
- !ruby/object:Gem::Dependency
|
49
|
+
type: :runtime
|
50
50
|
requirement: &id003 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
@@ -56,11 +56,11 @@ dependencies:
|
|
56
56
|
segments:
|
57
57
|
- 0
|
58
58
|
version: "0"
|
59
|
-
|
59
|
+
version_requirements: *id003
|
60
60
|
name: sishen-rtranslate
|
61
61
|
prerelease: false
|
62
|
-
version_requirements: *id003
|
63
62
|
- !ruby/object:Gem::Dependency
|
63
|
+
type: :runtime
|
64
64
|
requirement: &id004 !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -70,11 +70,11 @@ dependencies:
|
|
70
70
|
segments:
|
71
71
|
- 0
|
72
72
|
version: "0"
|
73
|
-
|
73
|
+
version_requirements: *id004
|
74
74
|
name: yrb
|
75
75
|
prerelease: false
|
76
|
-
version_requirements: *id004
|
77
76
|
- !ruby/object:Gem::Dependency
|
77
|
+
type: :development
|
78
78
|
requirement: &id005 !ruby/object:Gem::Requirement
|
79
79
|
none: false
|
80
80
|
requirements:
|
@@ -86,11 +86,11 @@ dependencies:
|
|
86
86
|
- 2
|
87
87
|
- 9
|
88
88
|
version: 1.2.9
|
89
|
-
|
89
|
+
version_requirements: *id005
|
90
90
|
name: rspec
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *id005
|
93
92
|
- !ruby/object:Gem::Dependency
|
93
|
+
type: :runtime
|
94
94
|
requirement: &id006 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
@@ -102,11 +102,11 @@ dependencies:
|
|
102
102
|
- 2
|
103
103
|
- 2
|
104
104
|
version: 2.2.2
|
105
|
-
|
105
|
+
version_requirements: *id006
|
106
106
|
name: activesupport
|
107
107
|
prerelease: false
|
108
|
-
version_requirements: *id006
|
109
108
|
- !ruby/object:Gem::Dependency
|
109
|
+
type: :runtime
|
110
110
|
requirement: &id007 !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
112
112
|
requirements:
|
@@ -118,11 +118,11 @@ dependencies:
|
|
118
118
|
- 2
|
119
119
|
- 9
|
120
120
|
version: 1.2.9
|
121
|
-
|
121
|
+
version_requirements: *id007
|
122
122
|
name: sishen-rtranslate
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *id007
|
125
124
|
- !ruby/object:Gem::Dependency
|
125
|
+
type: :runtime
|
126
126
|
requirement: &id008 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
@@ -132,11 +132,11 @@ dependencies:
|
|
132
132
|
segments:
|
133
133
|
- 0
|
134
134
|
version: "0"
|
135
|
-
|
135
|
+
version_requirements: *id008
|
136
136
|
name: timer
|
137
137
|
prerelease: false
|
138
|
-
version_requirements: *id008
|
139
138
|
- !ruby/object:Gem::Dependency
|
139
|
+
type: :runtime
|
140
140
|
requirement: &id009 !ruby/object:Gem::Requirement
|
141
141
|
none: false
|
142
142
|
requirements:
|
@@ -146,11 +146,11 @@ dependencies:
|
|
146
146
|
segments:
|
147
147
|
- 0
|
148
148
|
version: "0"
|
149
|
-
|
149
|
+
version_requirements: *id009
|
150
150
|
name: natural_time
|
151
151
|
prerelease: false
|
152
|
-
version_requirements: *id009
|
153
152
|
- !ruby/object:Gem::Dependency
|
153
|
+
type: :runtime
|
154
154
|
requirement: &id010 !ruby/object:Gem::Requirement
|
155
155
|
none: false
|
156
156
|
requirements:
|
@@ -160,11 +160,11 @@ dependencies:
|
|
160
160
|
segments:
|
161
161
|
- 0
|
162
162
|
version: "0"
|
163
|
-
|
163
|
+
version_requirements: *id010
|
164
164
|
name: g
|
165
165
|
prerelease: false
|
166
|
-
version_requirements: *id010
|
167
166
|
- !ruby/object:Gem::Dependency
|
167
|
+
type: :runtime
|
168
168
|
requirement: &id011 !ruby/object:Gem::Requirement
|
169
169
|
none: false
|
170
170
|
requirements:
|
@@ -174,10 +174,9 @@ dependencies:
|
|
174
174
|
segments:
|
175
175
|
- 0
|
176
176
|
version: "0"
|
177
|
-
|
177
|
+
version_requirements: *id011
|
178
178
|
name: yrb
|
179
179
|
prerelease: false
|
180
|
-
version_requirements: *id011
|
181
180
|
description: Takes a set of keys in Yaml format and translates them through Google Translate.
|
182
181
|
email: progressions@gmail.com
|
183
182
|
executables:
|
@@ -189,7 +188,9 @@ extra_rdoc_files:
|
|
189
188
|
- README.rdoc
|
190
189
|
files:
|
191
190
|
- .document
|
191
|
+
- .rvmrc
|
192
192
|
- Gemfile
|
193
|
+
- Gemfile.lock
|
193
194
|
- History.txt
|
194
195
|
- LICENSE
|
195
196
|
- README.rdoc
|
@@ -207,7 +208,6 @@ files:
|
|
207
208
|
- spec/spec.opts
|
208
209
|
- spec/spec_helper.rb
|
209
210
|
- spec/stubs.rb
|
210
|
-
has_rdoc: true
|
211
211
|
homepage: http://github.com/progressions/idiom
|
212
212
|
licenses: []
|
213
213
|
|
@@ -237,11 +237,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
requirements: []
|
238
238
|
|
239
239
|
rubyforge_project:
|
240
|
-
rubygems_version: 1.
|
240
|
+
rubygems_version: 1.8.12
|
241
241
|
signing_key:
|
242
242
|
specification_version: 3
|
243
243
|
summary: Translate all your application's international keys in Google Translate
|
244
|
-
test_files:
|
245
|
-
|
246
|
-
- spec/spec_helper.rb
|
247
|
-
- spec/stubs.rb
|
244
|
+
test_files: []
|
245
|
+
|