er18ern 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/Gemfile.lock +43 -0
- data/lib/er18ern.rb +4 -239
- data/lib/er18ern/improved_ermahgerd.rb +178 -0
- data/lib/er18ern/middleware.rb +26 -0
- data/lib/er18ern/rails_app_helper.rb +44 -0
- data/lib/er18ern/version.rb +1 -1
- data/script/ci +3 -0
- data/spec/improved_ermahgerd_spec.rb +7 -0
- data/spec/middleware_spec.rb +45 -0
- data/spec/rails_app_helper_spec.rb +30 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/my_app.rb +12 -0
- metadata +50 -50
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.8)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
ermahgerd (0.0.1)
|
7
|
+
i18n (0.6.1)
|
8
|
+
method_source (0.8.1)
|
9
|
+
pry (0.9.10)
|
10
|
+
coderay (~> 1.0.5)
|
11
|
+
method_source (~> 0.8)
|
12
|
+
slop (~> 3.3.1)
|
13
|
+
rack (1.4.3)
|
14
|
+
rack-protection (1.2.0)
|
15
|
+
rack
|
16
|
+
rack-test (0.6.2)
|
17
|
+
rack (>= 1.0)
|
18
|
+
rspec (2.12.0)
|
19
|
+
rspec-core (~> 2.12.0)
|
20
|
+
rspec-expectations (~> 2.12.0)
|
21
|
+
rspec-mocks (~> 2.12.0)
|
22
|
+
rspec-core (2.12.2)
|
23
|
+
rspec-expectations (2.12.1)
|
24
|
+
diff-lcs (~> 1.1.3)
|
25
|
+
rspec-mocks (2.12.1)
|
26
|
+
sinatra (1.3.3)
|
27
|
+
rack (~> 1.3, >= 1.3.6)
|
28
|
+
rack-protection (~> 1.2)
|
29
|
+
tilt (~> 1.3, >= 1.3.3)
|
30
|
+
slop (3.3.3)
|
31
|
+
tilt (1.3.3)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
ermahgerd
|
38
|
+
i18n
|
39
|
+
pry
|
40
|
+
rack
|
41
|
+
rack-test
|
42
|
+
rspec
|
43
|
+
sinatra
|
data/lib/er18ern.rb
CHANGED
@@ -1,241 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(app)
|
5
|
-
@app = app
|
6
|
-
end
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
request = Rack::Request.new(env)
|
10
|
-
request_locale = request.params["locale"] || request.cookies["eylocale"]
|
11
|
-
if request_locale && I18n.available_locales.include?(request_locale.to_sym)
|
12
|
-
I18n.locale = request_locale
|
13
|
-
else
|
14
|
-
I18n.locale = I18n.default_locale
|
15
|
-
end
|
16
|
-
status, headers, body = @app.call(env)
|
17
|
-
cookie = {:value => I18n.locale, :expires => Time.now + 10.days, :domain => request.host.gsub(/^[^\.]*/,""), :path => "/"}
|
18
|
-
Rack::Utils.set_cookie_header!(headers, "eylocale", cookie)
|
19
|
-
[status, headers, body]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class JustRaise
|
24
|
-
def call(exception, locale, key, options)
|
25
|
-
raise "Missing Translation: #{exception}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class RailsApp
|
30
|
-
def self.setup!
|
31
|
-
if ["test", "development"].include?(Rails.env)
|
32
|
-
I18n.exception_handler = JustRaise.new
|
33
|
-
end
|
34
|
-
Array.class_eval do
|
35
|
-
def to_br_sentence
|
36
|
-
case length
|
37
|
-
when 0
|
38
|
-
""
|
39
|
-
when 1
|
40
|
-
self[0].to_s.dup
|
41
|
-
when 2
|
42
|
-
two_words_connector = I18n.translate(:'support.array.br_two_words_connector')
|
43
|
-
"#{self[0]}#{two_words_connector}#{self[1]}".html_safe
|
44
|
-
else
|
45
|
-
words_connector = I18n.translate(:'support.array.br_words_connector')
|
46
|
-
last_word_connector = I18n.translate(:'support.array.br_last_word_connector')
|
47
|
-
"#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}".html_safe
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
ActiveModel::Errors.class_eval do
|
52
|
-
def full_message(attribute, message)
|
53
|
-
return message if attribute == :base
|
54
|
-
attr_name = attribute.to_s.tr('.', '_').humanize
|
55
|
-
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
|
56
|
-
I18n.t(:"errors.formats.attributes.#{attribute}", {
|
57
|
-
:default => [:"errors.format","%{attribute} %{message}"],
|
58
|
-
:attribute => attr_name,
|
59
|
-
:message => message
|
60
|
-
})
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
require 'ermahgerd'
|
67
|
-
module ImprovedErmahgerd
|
68
|
-
|
69
|
-
def self.translate(words)
|
70
|
-
words.gsub(/([{]?)([&]?)\w+/) do |word|
|
71
|
-
if $1 == "{" || $2 == "&"
|
72
|
-
word
|
73
|
-
else
|
74
|
-
translate_word(word.upcase)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.translate_word(word)
|
80
|
-
case word
|
81
|
-
when "ENGINE"
|
82
|
-
"ERNGIN"
|
83
|
-
when "YARD"
|
84
|
-
"YERD"
|
85
|
-
else
|
86
|
-
Ermahgerd.translate_word(word)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
class Translator
|
93
|
-
attr_accessor :locales_dir, :google_translator_hax_locale_dirs
|
94
|
-
|
95
|
-
def en_source_yaml
|
96
|
-
@en_source_yaml ||= YAML::load_file(File.expand_path('en.yml', self.locales_dir))
|
97
|
-
end
|
98
|
-
|
99
|
-
def generate_ermahgerd!
|
100
|
-
traverse = Proc.new do |x, translator|
|
101
|
-
if x.is_a?(Hash)
|
102
|
-
result = {}
|
103
|
-
x.each do |k, v|
|
104
|
-
result[k] = traverse.call(v, translator)
|
105
|
-
end
|
106
|
-
result
|
107
|
-
else
|
108
|
-
translator.call(x)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
errm = {}
|
113
|
-
errm['ermahgerd'] = en_source_yaml["en"]
|
114
|
-
|
115
|
-
#save ermahgerd
|
116
|
-
File.open(File.expand_path('ermahgerd.yml', self.locales_dir), "w") do |fp|
|
117
|
-
fp.write(traverse.call(errm, lambda{|x| ImprovedErmahgerd.translate(x)}).to_yaml)
|
118
|
-
end
|
119
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/er18ern/middleware'
|
2
|
+
require File.dirname(__FILE__) + '/er18ern/rails_app_helper'
|
3
|
+
require File.dirname(__FILE__) + '/er18ern/improved_ermahgerd'
|
120
4
|
|
121
|
-
|
122
|
-
#re-save EN
|
123
|
-
File.open(File.expand_path('en.yml', self.locales_dir), "w") do |fp|
|
124
|
-
fp.write(en_source_yaml.to_yaml)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def found_keys
|
129
|
-
@found_keys ||= begin
|
130
|
-
found_keys = {}
|
131
|
-
key_collector = Proc.new do |x, key_prefix|
|
132
|
-
if x.is_a?(Hash)
|
133
|
-
result = {}
|
134
|
-
x.each do |k, v|
|
135
|
-
result[k] = key_collector.call(v, "#{key_prefix}.#{k}")
|
136
|
-
end
|
137
|
-
result
|
138
|
-
else
|
139
|
-
found_keys[key_prefix] = x
|
140
|
-
end
|
141
|
-
end
|
142
|
-
key_collector.call(en_source_yaml["en"], "")
|
143
|
-
found_keys
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def generate_google_translations!
|
148
|
-
vals = found_keys.values.uniq.map do |val|
|
149
|
-
strip_string(val)
|
150
|
-
end
|
151
|
-
|
152
|
-
File.open(File.expand_path('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs), "w") do |fp|
|
153
|
-
fp.write(vals.join("\n---\n"))
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def save_engrish!
|
158
|
-
enstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
159
|
-
engrishstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_AGAIN', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
160
|
-
engrish = doitstuff(enstuff, found_keys, "engrish", engrishstuff)
|
161
|
-
|
162
|
-
File.open(File.expand_path('engrish.yml', self.locales_dir), "w") do |fp|
|
163
|
-
fp.write(engrish.to_yaml)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def save_jp!
|
168
|
-
enstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
169
|
-
jpstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_OUTPUT', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
170
|
-
jp = doitstuff(enstuff, found_keys, "jp", jpstuff)
|
171
|
-
|
172
|
-
File.open(File.expand_path('jp.yml', self.locales_dir), "w") do |fp|
|
173
|
-
fp.write(jp.to_yaml)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def copy_missing_into!(place)
|
178
|
-
en_source_yaml["en"]
|
179
|
-
output = YAML::load_file(File.expand_path("#{place}.yml", self.locales_dir))
|
180
|
-
traverse = Proc.new do |x, y|
|
181
|
-
if x.is_a?(Hash)
|
182
|
-
x.each do |k, v|
|
183
|
-
y[k] ||= v
|
184
|
-
traverse.call(v, y[k])
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
traverse.call(en_source_yaml["en"], output[place])
|
189
|
-
File.open(File.expand_path("#{place}.yml", self.locales_dir), "w") do |fp|
|
190
|
-
fp.write(output.to_yaml)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
private
|
195
|
-
|
196
|
-
def doitstuff(enstuff, found_keys, locale, stuff)
|
197
|
-
lookup = {}
|
198
|
-
found_keys.each do |k, v|
|
199
|
-
if index = enstuff.index(strip_string(v))
|
200
|
-
lookup[k] = stuff && stuff[index]
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
jp = {locale => {}}
|
205
|
-
lookup.each do |k, v|
|
206
|
-
hash = jp[locale]
|
207
|
-
last = nil
|
208
|
-
k.split(".").each do |key_part|
|
209
|
-
unless key_part.empty?
|
210
|
-
last_hash = hash
|
211
|
-
last = Proc.new do |str|
|
212
|
-
en_string = found_keys[k]
|
213
|
-
en_string_parts = strip_string(en_string).split("***")
|
214
|
-
jp_string_parts = str.split("***")
|
215
|
-
en_string_parts.each_with_index do |part, index|
|
216
|
-
jp_corresponding = jp_string_parts[index] || "" # "MISSING TRANSLATION"
|
217
|
-
en_string = en_string.gsub(part.to_s, jp_corresponding)
|
218
|
-
end
|
219
|
-
last_hash[key_part] = en_string
|
220
|
-
end
|
221
|
-
hash[key_part] ||= {}
|
222
|
-
hash = hash[key_part]
|
223
|
-
end
|
224
|
-
end
|
225
|
-
last.call(v)
|
226
|
-
end
|
227
|
-
jp
|
228
|
-
end
|
229
|
-
|
230
|
-
def strip_string(str)
|
231
|
-
str.gsub(/([%]?)([&]?)([{]?)\w+([;]?)([}]?)/) do |word|
|
232
|
-
if $1 == "%" || $2 == "&"
|
233
|
-
"***"
|
234
|
-
else
|
235
|
-
word
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
end
|
5
|
+
module Er18Ern
|
241
6
|
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'ermahgerd'
|
2
|
+
|
3
|
+
module Er18Ern
|
4
|
+
module ImprovedErmahgerd
|
5
|
+
|
6
|
+
def self.translate(words)
|
7
|
+
words.gsub(/([{]?)([&]?)\w+/) do |word|
|
8
|
+
if $1 == "{" || $2 == "&"
|
9
|
+
word
|
10
|
+
else
|
11
|
+
translate_word(word.upcase)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.translate_word(word)
|
17
|
+
case word
|
18
|
+
when "ENGINE"
|
19
|
+
"ERNGIN"
|
20
|
+
when "YARD"
|
21
|
+
"YERD"
|
22
|
+
else
|
23
|
+
Ermahgerd.translate_word(word)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class Translator
|
30
|
+
attr_accessor :locales_dir, :google_translator_hax_locale_dirs
|
31
|
+
|
32
|
+
def en_source_yaml
|
33
|
+
@en_source_yaml ||= YAML::load_file(File.expand_path('en.yml', self.locales_dir))
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_ermahgerd!
|
37
|
+
traverse = Proc.new do |x, translator|
|
38
|
+
if x.is_a?(Hash)
|
39
|
+
result = {}
|
40
|
+
x.each do |k, v|
|
41
|
+
result[k] = traverse.call(v, translator)
|
42
|
+
end
|
43
|
+
result
|
44
|
+
else
|
45
|
+
translator.call(x)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
errm = {}
|
50
|
+
errm['ermahgerd'] = en_source_yaml["en"]
|
51
|
+
|
52
|
+
#save ermahgerd
|
53
|
+
File.open(File.expand_path('ermahgerd.yml', self.locales_dir), "w") do |fp|
|
54
|
+
fp.write(traverse.call(errm, lambda{|x| ImprovedErmahgerd.translate(x)}).to_yaml)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def resave_en!
|
59
|
+
#re-save EN
|
60
|
+
File.open(File.expand_path('en.yml', self.locales_dir), "w") do |fp|
|
61
|
+
fp.write(en_source_yaml.to_yaml)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def found_keys
|
66
|
+
@found_keys ||= begin
|
67
|
+
found_keys = {}
|
68
|
+
key_collector = Proc.new do |x, key_prefix|
|
69
|
+
if x.is_a?(Hash)
|
70
|
+
result = {}
|
71
|
+
x.each do |k, v|
|
72
|
+
result[k] = key_collector.call(v, "#{key_prefix}.#{k}")
|
73
|
+
end
|
74
|
+
result
|
75
|
+
else
|
76
|
+
found_keys[key_prefix] = x
|
77
|
+
end
|
78
|
+
end
|
79
|
+
key_collector.call(en_source_yaml["en"], "")
|
80
|
+
found_keys
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_google_translations!
|
85
|
+
vals = found_keys.values.uniq.map do |val|
|
86
|
+
strip_string(val)
|
87
|
+
end
|
88
|
+
|
89
|
+
File.open(File.expand_path('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs), "w") do |fp|
|
90
|
+
fp.write(vals.join("\n---\n"))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def save_engrish!
|
95
|
+
enstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
96
|
+
engrishstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_AGAIN', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
97
|
+
engrish = doitstuff(enstuff, found_keys, "engrish", engrishstuff)
|
98
|
+
|
99
|
+
File.open(File.expand_path('engrish.yml', self.locales_dir), "w") do |fp|
|
100
|
+
fp.write(engrish.to_yaml)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def save_jp!
|
105
|
+
enstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
106
|
+
jpstuff = File.read(File.expand_path('GOOGLE_TRANSLATE_OUTPUT', self.google_translator_hax_locale_dirs)).split("\n---\n")
|
107
|
+
jp = doitstuff(enstuff, found_keys, "jp", jpstuff)
|
108
|
+
|
109
|
+
File.open(File.expand_path('jp.yml', self.locales_dir), "w") do |fp|
|
110
|
+
fp.write(jp.to_yaml)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def copy_missing_into!(place)
|
115
|
+
en_source_yaml["en"]
|
116
|
+
output = YAML::load_file(File.expand_path("#{place}.yml", self.locales_dir))
|
117
|
+
traverse = Proc.new do |x, y|
|
118
|
+
if x.is_a?(Hash)
|
119
|
+
x.each do |k, v|
|
120
|
+
y[k] ||= v
|
121
|
+
traverse.call(v, y[k])
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
traverse.call(en_source_yaml["en"], output[place])
|
126
|
+
File.open(File.expand_path("#{place}.yml", self.locales_dir), "w") do |fp|
|
127
|
+
fp.write(output.to_yaml)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def doitstuff(enstuff, found_keys, locale, stuff)
|
134
|
+
lookup = {}
|
135
|
+
found_keys.each do |k, v|
|
136
|
+
if index = enstuff.index(strip_string(v))
|
137
|
+
lookup[k] = stuff && stuff[index]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
jp = {locale => {}}
|
142
|
+
lookup.each do |k, v|
|
143
|
+
hash = jp[locale]
|
144
|
+
last = nil
|
145
|
+
k.split(".").each do |key_part|
|
146
|
+
unless key_part.empty?
|
147
|
+
last_hash = hash
|
148
|
+
last = Proc.new do |str|
|
149
|
+
en_string = found_keys[k]
|
150
|
+
en_string_parts = strip_string(en_string).split("***")
|
151
|
+
jp_string_parts = str.split("***")
|
152
|
+
en_string_parts.each_with_index do |part, index|
|
153
|
+
jp_corresponding = jp_string_parts[index] || "" # "MISSING TRANSLATION"
|
154
|
+
en_string = en_string.gsub(part.to_s, jp_corresponding)
|
155
|
+
end
|
156
|
+
last_hash[key_part] = en_string
|
157
|
+
end
|
158
|
+
hash[key_part] ||= {}
|
159
|
+
hash = hash[key_part]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
last.call(v)
|
163
|
+
end
|
164
|
+
jp
|
165
|
+
end
|
166
|
+
|
167
|
+
def strip_string(str)
|
168
|
+
str.gsub(/([%]?)([&]?)([{]?)\w+([;]?)([}]?)/) do |word|
|
169
|
+
if $1 == "%" || $2 == "&"
|
170
|
+
"***"
|
171
|
+
else
|
172
|
+
word
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module Er18Ern
|
4
|
+
class LocaleCookie
|
5
|
+
|
6
|
+
DAYS = 24 * 60 * 60
|
7
|
+
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
request = Rack::Request.new(env)
|
14
|
+
request_locale = request.params["locale"] || request.cookies["eylocale"]
|
15
|
+
if request_locale && I18n.available_locales.include?(request_locale.to_sym)
|
16
|
+
I18n.locale = request_locale
|
17
|
+
else
|
18
|
+
I18n.locale = I18n.default_locale
|
19
|
+
end
|
20
|
+
status, headers, body = @app.call(env)
|
21
|
+
cookie = {:value => I18n.locale, :expires => Time.now + (10 * DAYS), :domain => request.host.gsub(/^[^\.]*/,""), :path => "/"}
|
22
|
+
Rack::Utils.set_cookie_header!(headers, "eylocale", cookie)
|
23
|
+
[status, headers, body]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Er18Ern
|
2
|
+
class JustRaise
|
3
|
+
def call(exception, locale, key, options)
|
4
|
+
raise "Missing Translation: #{exception}"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class RailsApp
|
9
|
+
def self.setup!
|
10
|
+
if ["test", "development"].include?(Rails.env)
|
11
|
+
I18n.exception_handler = JustRaise.new
|
12
|
+
end
|
13
|
+
Array.class_eval do
|
14
|
+
def to_br_sentence
|
15
|
+
case length
|
16
|
+
when 0
|
17
|
+
""
|
18
|
+
when 1
|
19
|
+
self[0].to_s.dup
|
20
|
+
when 2
|
21
|
+
two_words_connector = I18n.translate(:'support.array.br_two_words_connector')
|
22
|
+
"#{self[0]}#{two_words_connector}#{self[1]}".html_safe
|
23
|
+
else
|
24
|
+
words_connector = I18n.translate(:'support.array.br_words_connector')
|
25
|
+
last_word_connector = I18n.translate(:'support.array.br_last_word_connector')
|
26
|
+
"#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}".html_safe
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
ActiveModel::Errors.class_eval do
|
31
|
+
def full_message(attribute, message)
|
32
|
+
return message if attribute == :base
|
33
|
+
attr_name = attribute.to_s.tr('.', '_').humanize
|
34
|
+
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
|
35
|
+
I18n.t(:"errors.formats.attributes.#{attribute}", {
|
36
|
+
:default => [:"errors.format","%{attribute} %{message}"],
|
37
|
+
:attribute => attr_name,
|
38
|
+
:message => message
|
39
|
+
})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/er18ern/version.rb
CHANGED
data/script/ci
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/my_app'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
MyApp
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Er18Ern::LocaleCookie do
|
12
|
+
describe 'setting a cookie' do
|
13
|
+
|
14
|
+
before do
|
15
|
+
I18n.available_locales = [:en, :jp]
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'will set a default locale cookie of :en if no locale is passed' do
|
19
|
+
rack_mock_session.cookie_jar["eylocale"].should == nil
|
20
|
+
get "/"
|
21
|
+
rack_mock_session.cookie_jar["eylocale"].should == "en"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'will set the locale cookie of locale passed' do
|
25
|
+
rack_mock_session.cookie_jar["eylocale"].should == nil
|
26
|
+
get "/?locale=jp"
|
27
|
+
rack_mock_session.cookie_jar["eylocale"].should == "jp"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'will keep the locale cookie if exist, when no locale is passed' do
|
31
|
+
get "/?locale=jp"
|
32
|
+
rack_mock_session.cookie_jar["eylocale"].should == "jp"
|
33
|
+
get "/"
|
34
|
+
rack_mock_session.cookie_jar["eylocale"].should == "jp"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'will reset the cookie if a locale is passed' do
|
38
|
+
get "/"
|
39
|
+
rack_mock_session.cookie_jar["eylocale"].should == "en"
|
40
|
+
get "/?locale=jp"
|
41
|
+
rack_mock_session.cookie_jar["eylocale"].should == "jp"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Er18Ern::RailsApp do
|
4
|
+
|
5
|
+
# hax
|
6
|
+
class Rails
|
7
|
+
def self.env
|
8
|
+
"test"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
class ActiveModel
|
12
|
+
class Errors
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'has a setup method which does things that depend on the Rails environment' do
|
17
|
+
before do
|
18
|
+
Er18Ern::RailsApp.setup!
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets exception handler' do
|
22
|
+
I18n.exception_handler.class.should == Er18Ern::JustRaise
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'monkey patches Array' do
|
26
|
+
Array.new.methods.map(&:to_s).include?("to_br_sentence").should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: er18ern
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jacob & Others too ashamed to admit it
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: ermahgerd
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
34
30
|
description: i18n helpers (with ermahgerd)
|
35
|
-
email:
|
31
|
+
email:
|
36
32
|
- jacob@engineyard.com
|
37
33
|
executables: []
|
38
|
-
|
39
34
|
extensions: []
|
40
|
-
|
41
35
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
|
36
|
+
files:
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
44
39
|
- README.md
|
45
40
|
- er18ern.gemspec
|
46
41
|
- lib/er18ern.rb
|
42
|
+
- lib/er18ern/improved_ermahgerd.rb
|
43
|
+
- lib/er18ern/middleware.rb
|
44
|
+
- lib/er18ern/rails_app_helper.rb
|
47
45
|
- lib/er18ern/version.rb
|
46
|
+
- script/ci
|
47
|
+
- spec/improved_ermahgerd_spec.rb
|
48
|
+
- spec/middleware_spec.rb
|
49
|
+
- spec/rails_app_helper_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
- spec/support/my_app.rb
|
48
52
|
homepage: https://github.com/engineyard/er18ern
|
49
53
|
licenses: []
|
50
|
-
|
51
54
|
post_install_message:
|
52
55
|
rdoc_options: []
|
53
|
-
|
54
|
-
require_paths:
|
56
|
+
require_paths:
|
55
57
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
59
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
- 0
|
64
|
-
version: "0"
|
65
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
65
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
74
70
|
requirements: []
|
75
|
-
|
76
71
|
rubyforge_project:
|
77
72
|
rubygems_version: 1.8.24
|
78
73
|
signing_key:
|
79
74
|
specification_version: 3
|
80
75
|
summary: i18n helpers
|
81
|
-
test_files:
|
82
|
-
|
76
|
+
test_files:
|
77
|
+
- spec/improved_ermahgerd_spec.rb
|
78
|
+
- spec/middleware_spec.rb
|
79
|
+
- spec/rails_app_helper_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/support/my_app.rb
|
82
|
+
has_rdoc:
|