localeapp 0.6.9 → 0.6.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/Gemfile.i18n_037 +1 -1
- data/Gemfile.i18n_050 +1 -1
- data/Gemfile.i18n_060 +1 -1
- data/README.md +10 -2
- data/lib/localeapp/configuration.rb +4 -0
- data/lib/localeapp/default_value_handler.rb +3 -2
- data/lib/localeapp/missing_translations.rb +23 -7
- data/lib/localeapp/updater.rb +1 -1
- data/lib/localeapp/version.rb +1 -1
- data/localeapp.gemspec +1 -1
- data/spec/localeapp/default_value_handler_spec.rb +32 -12
- data/spec/localeapp/exception_handler_spec.rb +11 -0
- data/spec/localeapp/missing_translations_spec.rb +24 -0
- data/spec/localeapp/updater_spec.rb +1 -1
- metadata +33 -33
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# master
|
2
|
+
|
3
|
+
# Version 0.6.10
|
4
|
+
|
5
|
+
* Don't send the :default param with a MissingTranslation when not in
|
6
|
+
the default locale.
|
7
|
+
* Cache MissingTranslations so that they're not sent multiple times.
|
8
|
+
|
9
|
+
# Version 0.6.9
|
10
|
+
|
11
|
+
* Make rack a dependency as we actually use it (Thanks @martoche)
|
12
|
+
|
1
13
|
# Version 0.6.8
|
2
14
|
|
3
15
|
* Don't load any yaml that may contain insecure content
|
data/Gemfile
CHANGED
data/Gemfile.i18n_037
CHANGED
data/Gemfile.i18n_050
CHANGED
data/Gemfile.i18n_060
CHANGED
data/README.md
CHANGED
@@ -79,8 +79,9 @@ existing translations do:
|
|
79
79
|
This will queue importing the file. The projects pages on localeapp.com will
|
80
80
|
automatically refresh so you can see the import progress.
|
81
81
|
|
82
|
-
If you've more than one locale to import you can
|
83
|
-
|
82
|
+
If you've more than one locale to import you can import all files in a directory :
|
83
|
+
|
84
|
+
localeapp push config/locales/
|
84
85
|
|
85
86
|
## Default Rails Translations
|
86
87
|
|
@@ -153,6 +154,13 @@ can be disabled in a similar way to polling and sending:
|
|
153
154
|
|
154
155
|
config.reloading_environments = []
|
155
156
|
|
157
|
+
### Caching
|
158
|
+
|
159
|
+
To prevent localeapp from sending translations every time they are missing,
|
160
|
+
add this config setting:
|
161
|
+
|
162
|
+
config.cache_missing_translations = true
|
163
|
+
|
156
164
|
## Inviting other developers and translators
|
157
165
|
|
158
166
|
You can invite other developers and translators via localeapp.com. Developers
|
@@ -74,6 +74,10 @@ module Localeapp
|
|
74
74
|
# default: true
|
75
75
|
attr_accessor :raise_on_insecure_yaml
|
76
76
|
|
77
|
+
# Enable or disable the missing translation cache
|
78
|
+
# default: false
|
79
|
+
attr_accessor :cache_missing_translations
|
80
|
+
|
77
81
|
def initialize
|
78
82
|
defaults.each do |setting, value|
|
79
83
|
send("#{setting}=", value)
|
@@ -4,10 +4,11 @@ module I18n::Backend::Base
|
|
4
4
|
def default(locale, object, subject, options = {})
|
5
5
|
result = default_without_handler(locale, object, subject, options)
|
6
6
|
case subject # case is what i18n gem uses here so doing the same
|
7
|
-
when Array
|
7
|
+
when Array, Symbol
|
8
8
|
# Do nothing, we only send missing translations with text defaults
|
9
9
|
else
|
10
|
-
|
10
|
+
value = locale == I18n.default_locale ? subject : nil
|
11
|
+
Localeapp.missing_translations.add(locale, object, value, options)
|
11
12
|
end
|
12
13
|
return result
|
13
14
|
end
|
@@ -2,6 +2,12 @@ module Localeapp
|
|
2
2
|
MissingTranslationRecord = Struct.new(:key, :locale, :description, :options)
|
3
3
|
|
4
4
|
class MissingTranslations
|
5
|
+
@cached_keys = []
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :cached_keys
|
9
|
+
end
|
10
|
+
|
5
11
|
def initialize
|
6
12
|
@translations = Hash.new { |h, k| h[k] = {} }
|
7
13
|
end
|
@@ -15,23 +21,33 @@ module Localeapp
|
|
15
21
|
@translations[locale]
|
16
22
|
end
|
17
23
|
|
18
|
-
# This method will get cleverer so we don't resend keys we've
|
19
|
-
# already sent, or send multiple times for the same locale etc.
|
20
|
-
# For now it's pretty dumb
|
21
24
|
def to_send
|
22
25
|
data = []
|
23
26
|
# need the sort to make specs work under 1.8
|
24
27
|
@translations.sort { |a, b| a.to_s <=> b.to_s }.each do |locale, records|
|
25
28
|
records.each do |key, record|
|
26
|
-
|
27
|
-
|
28
|
-
missing_data
|
29
|
+
next if cached?(key)
|
30
|
+
cache(key)
|
31
|
+
missing_data = {:key => key, :locale => locale, :options => record.options}
|
29
32
|
missing_data[:description] = record.description if record.description
|
30
|
-
missing_data[:options] = record.options
|
31
33
|
data << missing_data
|
32
34
|
end
|
33
35
|
end
|
34
36
|
data
|
35
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def cached_keys
|
42
|
+
self.class.cached_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
def cached?(key)
|
46
|
+
Localeapp.configuration.cache_missing_translations && cached_keys.include?(key)
|
47
|
+
end
|
48
|
+
|
49
|
+
def cache(key)
|
50
|
+
cached_keys << key if Localeapp.configuration.cache_missing_translations
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
data/lib/localeapp/updater.rb
CHANGED
data/lib/localeapp/version.rb
CHANGED
data/localeapp.gemspec
CHANGED
@@ -22,11 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency('i18n')
|
23
23
|
s.add_dependency('json')
|
24
24
|
s.add_dependency('rest-client')
|
25
|
+
s.add_dependency('rack')
|
25
26
|
s.add_dependency('ya2yaml')
|
26
27
|
s.add_dependency('gli')
|
27
28
|
|
28
29
|
s.add_development_dependency('rake')
|
29
|
-
s.add_development_dependency('rack')
|
30
30
|
s.add_development_dependency('rspec', '2.11.0')
|
31
31
|
s.add_development_dependency('yard', '0.6.7')
|
32
32
|
s.add_development_dependency('RedCloth', '4.2.9')
|
@@ -7,26 +7,46 @@ end
|
|
7
7
|
describe I18n::Backend::Base, '#default' do
|
8
8
|
let(:klass) { Klass.new }
|
9
9
|
|
10
|
-
|
10
|
+
def allow_sending
|
11
11
|
with_configuration(:sending_environments => ['my_env'], :environment_name => 'my_env' ) do
|
12
|
-
|
13
|
-
klass.default(:en, 'foo', 'bar', :baz => 'bam')
|
12
|
+
yield
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
|
-
describe "when subject is
|
18
|
-
it "
|
19
|
-
|
20
|
-
Localeapp.missing_translations.
|
16
|
+
describe "when subject is a String" do
|
17
|
+
it "adds translations to missing translations to send to Locale" do
|
18
|
+
allow_sending do
|
19
|
+
Localeapp.missing_translations.should_receive(:add).with(:en, 'foo', 'bar', :baz => 'bam')
|
20
|
+
klass.default(:en, 'foo', 'bar', :baz => 'bam')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "strips the subject when the translation is not in the default locale" do
|
25
|
+
allow_sending do
|
26
|
+
Localeapp.missing_translations.should_receive(:add).with(:fr, 'foo', nil, :baz => 'bam')
|
27
|
+
klass.default(:fr, 'foo', 'bar', :baz => 'bam')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when subject is an Array" do
|
33
|
+
it "doesn't send anything to Locale" do
|
34
|
+
allow_sending do
|
35
|
+
Localeapp.missing_translations.should_not_receive(:add)
|
21
36
|
I18n.stub!(:translate) do |subject, _|
|
22
|
-
|
23
|
-
"not missing"
|
24
|
-
else
|
25
|
-
nil
|
26
|
-
end
|
37
|
+
subject == :not_missing ? "not missing" : nil
|
27
38
|
end
|
28
39
|
klass.default(:en, 'foo', [:missing, :not_missing], :baz => 'bam')
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
43
|
+
|
44
|
+
describe "when subject is a Symbol" do
|
45
|
+
it "doesn't send anything to Locale" do
|
46
|
+
allow_sending do
|
47
|
+
Localeapp.missing_translations.should_not_receive(:add)
|
48
|
+
klass.default(:en, 'foo', :other_key, :baz => 'bam')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
32
52
|
end
|
@@ -19,6 +19,17 @@ describe Localeapp::ExceptionHandler, '#call(exception, locale, key, options)' d
|
|
19
19
|
I18n.t(['foo', 'bar'])
|
20
20
|
end
|
21
21
|
|
22
|
+
it "handles when the default is a Symbol that can be resolved" do
|
23
|
+
I18n.backend.store_translations(:en, {:default_symbol_test => 'is resolved'})
|
24
|
+
Localeapp.missing_translations.should_not_receive(:add)
|
25
|
+
I18n.t(:foo, :default => :default_symbol_test).should == 'is resolved'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "handles when the default is a Symbol that can't be resolved" do
|
29
|
+
Localeapp.missing_translations.should_receive(:add).with(:en, :foo, nil, {:default => :bar})
|
30
|
+
I18n.t(:foo, :default => :bar)
|
31
|
+
end
|
32
|
+
|
22
33
|
it "handles missing translation exception" do
|
23
34
|
expect {
|
24
35
|
exception = Localeapp::I18nMissingTranslationException.new(:en, 'foo', {})
|
@@ -28,4 +28,28 @@ describe Localeapp::MissingTranslations, "#to_send" do
|
|
28
28
|
to_send[1][:description].should == 'baz'
|
29
29
|
to_send[1][:options].should == {}
|
30
30
|
end
|
31
|
+
|
32
|
+
it "doesn't send the same key twice when cache_missing_translations is true" do
|
33
|
+
with_configuration(:cache_missing_translations => true) do
|
34
|
+
translation_a = Localeapp::MissingTranslations.new
|
35
|
+
translation_a.add(:es, 'foobybar')
|
36
|
+
translation_a.to_send.size.should == 1
|
37
|
+
|
38
|
+
translation_b = Localeapp::MissingTranslations.new
|
39
|
+
translation_b.add(:en, 'foobybar')
|
40
|
+
translation_a.to_send.size.should == 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can send the same key twice when cache_missing_translations is false" do
|
45
|
+
with_configuration(:cache_missing_translations => false) do
|
46
|
+
translation_a = Localeapp::MissingTranslations.new
|
47
|
+
translation_a.add(:es, 'foobybar')
|
48
|
+
translation_a.to_send.size.should == 1
|
49
|
+
|
50
|
+
translation_b = Localeapp::MissingTranslations.new
|
51
|
+
translation_b.add(:en, 'foobybar')
|
52
|
+
translation_a.to_send.size.should == 1
|
53
|
+
end
|
54
|
+
end
|
31
55
|
end
|
@@ -98,7 +98,7 @@ describe Localeapp::Updater, ".update(data)" do
|
|
98
98
|
File.exist?(File.join(@yml_dir, 'ja.yml')).should be_false
|
99
99
|
end
|
100
100
|
|
101
|
-
if defined?(Psych) && Psych::VERSION >= "1.1.0" && !RUBY_PLATFORM == 'jruby'
|
101
|
+
if defined?(Psych) && defined?(Psych::VERSION) && Psych::VERSION >= "1.1.0" && !RUBY_PLATFORM == 'jruby'
|
102
102
|
it "doesn't try to wrap long lines in the output" do
|
103
103
|
do_update({
|
104
104
|
'translations' => {
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localeapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 10
|
10
|
+
version: 0.6.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christopher Dell
|
@@ -16,10 +16,12 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-06-25 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: i18n
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
23
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
26
|
none: false
|
25
27
|
requirements:
|
@@ -29,11 +31,11 @@ dependencies:
|
|
29
31
|
segments:
|
30
32
|
- 0
|
31
33
|
version: "0"
|
32
|
-
type: :runtime
|
33
34
|
requirement: *id001
|
34
|
-
prerelease: false
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: json
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
37
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
40
|
none: false
|
39
41
|
requirements:
|
@@ -43,11 +45,11 @@ dependencies:
|
|
43
45
|
segments:
|
44
46
|
- 0
|
45
47
|
version: "0"
|
46
|
-
type: :runtime
|
47
48
|
requirement: *id002
|
48
|
-
prerelease: false
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rest-client
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
51
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
54
|
none: false
|
53
55
|
requirements:
|
@@ -57,11 +59,11 @@ dependencies:
|
|
57
59
|
segments:
|
58
60
|
- 0
|
59
61
|
version: "0"
|
60
|
-
type: :runtime
|
61
62
|
requirement: *id003
|
62
|
-
prerelease: false
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
64
|
+
name: rack
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
65
67
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
68
|
none: false
|
67
69
|
requirements:
|
@@ -71,11 +73,11 @@ dependencies:
|
|
71
73
|
segments:
|
72
74
|
- 0
|
73
75
|
version: "0"
|
74
|
-
type: :runtime
|
75
76
|
requirement: *id004
|
76
|
-
prerelease: false
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
|
-
name:
|
78
|
+
name: ya2yaml
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
79
81
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
82
|
none: false
|
81
83
|
requirements:
|
@@ -85,11 +87,11 @@ dependencies:
|
|
85
87
|
segments:
|
86
88
|
- 0
|
87
89
|
version: "0"
|
88
|
-
type: :runtime
|
89
90
|
requirement: *id005
|
90
|
-
prerelease: false
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
|
-
name:
|
92
|
+
name: gli
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
93
95
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
94
96
|
none: false
|
95
97
|
requirements:
|
@@ -99,11 +101,11 @@ dependencies:
|
|
99
101
|
segments:
|
100
102
|
- 0
|
101
103
|
version: "0"
|
102
|
-
type: :development
|
103
104
|
requirement: *id006
|
104
|
-
prerelease: false
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
|
-
name:
|
106
|
+
name: rake
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
107
109
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
108
110
|
none: false
|
109
111
|
requirements:
|
@@ -113,11 +115,11 @@ dependencies:
|
|
113
115
|
segments:
|
114
116
|
- 0
|
115
117
|
version: "0"
|
116
|
-
type: :development
|
117
118
|
requirement: *id007
|
118
|
-
prerelease: false
|
119
119
|
- !ruby/object:Gem::Dependency
|
120
120
|
name: rspec
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
121
123
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
122
124
|
none: false
|
123
125
|
requirements:
|
@@ -129,11 +131,11 @@ dependencies:
|
|
129
131
|
- 11
|
130
132
|
- 0
|
131
133
|
version: 2.11.0
|
132
|
-
type: :development
|
133
134
|
requirement: *id008
|
134
|
-
prerelease: false
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: yard
|
137
|
+
type: :development
|
138
|
+
prerelease: false
|
137
139
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
138
140
|
none: false
|
139
141
|
requirements:
|
@@ -145,11 +147,11 @@ dependencies:
|
|
145
147
|
- 6
|
146
148
|
- 7
|
147
149
|
version: 0.6.7
|
148
|
-
type: :development
|
149
150
|
requirement: *id009
|
150
|
-
prerelease: false
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: RedCloth
|
153
|
+
type: :development
|
154
|
+
prerelease: false
|
153
155
|
version_requirements: &id010 !ruby/object:Gem::Requirement
|
154
156
|
none: false
|
155
157
|
requirements:
|
@@ -161,11 +163,11 @@ dependencies:
|
|
161
163
|
- 2
|
162
164
|
- 9
|
163
165
|
version: 4.2.9
|
164
|
-
type: :development
|
165
166
|
requirement: *id010
|
166
|
-
prerelease: false
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: aruba
|
169
|
+
type: :development
|
170
|
+
prerelease: false
|
169
171
|
version_requirements: &id011 !ruby/object:Gem::Requirement
|
170
172
|
none: false
|
171
173
|
requirements:
|
@@ -177,11 +179,11 @@ dependencies:
|
|
177
179
|
- 5
|
178
180
|
- 1
|
179
181
|
version: 0.5.1
|
180
|
-
type: :development
|
181
182
|
requirement: *id011
|
182
|
-
prerelease: false
|
183
183
|
- !ruby/object:Gem::Dependency
|
184
184
|
name: fakeweb
|
185
|
+
type: :development
|
186
|
+
prerelease: false
|
185
187
|
version_requirements: &id012 !ruby/object:Gem::Requirement
|
186
188
|
none: false
|
187
189
|
requirements:
|
@@ -193,9 +195,7 @@ dependencies:
|
|
193
195
|
- 3
|
194
196
|
- 0
|
195
197
|
version: 1.3.0
|
196
|
-
type: :development
|
197
198
|
requirement: *id012
|
198
|
-
prerelease: false
|
199
199
|
description: Synchronizes i18n translation keys and content with localeapp.com so you don't have to manage translations by hand.
|
200
200
|
email:
|
201
201
|
- chris@tigrish.com
|
@@ -320,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
320
|
requirements: []
|
321
321
|
|
322
322
|
rubyforge_project: localeapp
|
323
|
-
rubygems_version: 1.8.
|
323
|
+
rubygems_version: 1.8.6
|
324
324
|
signing_key:
|
325
325
|
specification_version: 3
|
326
326
|
summary: Easy i18n translation management with localeapp.com
|