translation_panel 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +11 -3
- data/VERSION +1 -1
- data/lib/translation_panel/redis_backend.rb +13 -5
- data/spec/lib/redis_backend_spec.rb +4 -0
- data/translation_panel.gemspec +2 -2
- metadata +3 -3
data/README.textile
CHANGED
@@ -2,21 +2,25 @@ h1. TranslationPanel
|
|
2
2
|
|
3
3
|
h3. Using with Redis:
|
4
4
|
|
5
|
-
|
5
|
+
* Run redis-server
|
6
6
|
|
7
|
-
|
7
|
+
* Set up redis connection settings and register RedisTranslator::Backend as
|
8
8
|
i18n backend in initializers:
|
9
9
|
|
10
|
+
<pre><code>
|
10
11
|
I18n.backend = TranslationPanel::RedisBackend.new(Redis.new)
|
11
12
|
# or in chain with another backend
|
13
|
+
</code></pre>
|
12
14
|
|
13
|
-
|
15
|
+
* Create predicate method +translation_panel?+ in ApplicationController,
|
14
16
|
define in it, when panel can be shown and when translates can be saved. By
|
15
17
|
default always.
|
16
18
|
|
19
|
+
<pre><code>
|
17
20
|
def translation_panel?
|
18
21
|
params[:translator].present?
|
19
22
|
end
|
23
|
+
</code></pre>
|
20
24
|
|
21
25
|
h3. Dependencies
|
22
26
|
|
@@ -31,14 +35,18 @@ Redis backen
|
|
31
35
|
|
32
36
|
1. You need to use Simple backend with included I18n::Pluralization in chain:
|
33
37
|
|
38
|
+
<pre><code>
|
34
39
|
I18n::Backend::Simple.include I18n::Backend::Pluralization
|
35
40
|
redis_backend = TranslationPanel::RedisBackend.new(Redis.new)
|
36
41
|
I18n.backend = I18n::Backend::Chain.new(redis_backend, I18n::Backend::Simple.new)
|
42
|
+
</code></pre>
|
37
43
|
|
38
44
|
2. You need to add in +config/locales/*.yml+ files rules for pluralization:
|
39
45
|
|
46
|
+
<pre><code>
|
40
47
|
i18n:
|
41
48
|
plural:
|
42
49
|
keys:
|
43
50
|
- one
|
44
51
|
- other
|
52
|
+
</code></pre>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -52,15 +52,23 @@ module TranslationPanel
|
|
52
52
|
# Creates empty translations for absented pluralization keys.
|
53
53
|
# Returns hash with plural keys and their values (even from another backend)
|
54
54
|
def get_count_keys(locale, key)
|
55
|
-
|
55
|
+
empty_translations = {}
|
56
|
+
store_empty_translations = false
|
57
|
+
count_keys = I18n.t!('i18n.plural.keys', :locale => locale).inject({}) do |result, plural_key|
|
56
58
|
full_key = "#{key}.#{plural_key}"
|
57
59
|
value = get_translate(locale, full_key)
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
if value
|
61
|
+
store_empty_translations = true
|
62
|
+
result.merge plural_key.to_s => value
|
63
|
+
else
|
64
|
+
empty_translations.merge! full_key => ""
|
65
|
+
result
|
61
66
|
end
|
62
|
-
result.merge plural_key.to_s => value
|
63
67
|
end
|
68
|
+
if store_empty_translations && empty_translations.present?
|
69
|
+
I18n.backend.store_translations locale, empty_translations, :escape => false
|
70
|
+
end
|
71
|
+
count_keys
|
64
72
|
rescue
|
65
73
|
{}
|
66
74
|
end
|
@@ -82,5 +82,9 @@ describe TranslationPanel::RedisBackend do
|
|
82
82
|
I18n.translate("some.missing", :count => 23).should == "23 пропажи"
|
83
83
|
I18n.translate("some.missing", :count => 11).should == ""
|
84
84
|
end
|
85
|
+
|
86
|
+
it "returns default value for empty translate" do
|
87
|
+
I18n.translate("all.missing", :count => 21, :default => "Abc").should == "Abc"
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|
data/translation_panel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{translation_panel}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mik-die"]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-18}
|
13
13
|
s.description = %q{I18n backend, based on redis, with frontend panel for translations}
|
14
14
|
s.email = %q{MikDiet@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: translation_panel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mik-die
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-18 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
requirements:
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
hash:
|
149
|
+
hash: 760914177
|
150
150
|
segments:
|
151
151
|
- 0
|
152
152
|
version: "0"
|