lolita-i18n 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/assets/javascripts/lolita/i18n/i18n.js.coffee +1 -1
- data/app/controllers/lolita/i18n_controller.rb +7 -1
- data/lib/lolita-i18n.rb +2 -1
- data/lib/lolita-i18n/backend.rb +12 -1
- data/lib/lolita-i18n/exceptions.rb +11 -0
- data/lolita-i18n.gemspec +3 -2
- data/spec/lolita-i18n/backend_spec.rb +5 -0
- data/spec/rails_app/config/locales/en.yml +2 -1
- metadata +22 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -11,7 +11,13 @@ class Lolita::I18nController < ApplicationController
|
|
11
11
|
def update
|
12
12
|
respond_to do |format|
|
13
13
|
format.json do
|
14
|
-
|
14
|
+
error = false
|
15
|
+
begin
|
16
|
+
Lolita::I18n::Backend.set(params[:id],params[:translation])
|
17
|
+
rescue Lolita::I18n::Exceptions::MissingInterpolationArgument => e
|
18
|
+
error = e.to_s
|
19
|
+
end
|
20
|
+
render :nothing => true, :json => {error: error}
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/lolita-i18n.rb
CHANGED
data/lib/lolita-i18n/backend.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Lolita
|
2
|
-
module I18n
|
2
|
+
module I18n
|
3
3
|
# Allow to operate with I18n keys and values.
|
4
4
|
class Backend
|
5
5
|
|
@@ -24,6 +24,7 @@ module Lolita
|
|
24
24
|
# * <tt>key</tt> - translation key
|
25
25
|
# * <tt>translation</tt> - String with translation
|
26
26
|
def set(key,translation)
|
27
|
+
validate_translation(key,translation)
|
27
28
|
locale=translate_to(key)
|
28
29
|
translation_key=translation_key(key)
|
29
30
|
value=Yajl::Parser.parse(translation.to_json)
|
@@ -51,6 +52,16 @@ module Lolita
|
|
51
52
|
end
|
52
53
|
|
53
54
|
private
|
55
|
+
|
56
|
+
def validate_translation key,translation
|
57
|
+
validate_interpolation_arguments key,translation
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_interpolation_arguments key,translation
|
61
|
+
in_translation = translation.scan(/(%{\w+})/).map{|m| m.first}.sort
|
62
|
+
in_original = ::I18n.t(translation_key(key), :locale => ::I18n.default_locale).scan(/(%{\w+})/).map{|m| m.first}.sort
|
63
|
+
raise Exceptions::MissingInterpolationArgument.new(in_original) unless in_translation == in_original
|
64
|
+
end
|
54
65
|
|
55
66
|
def keys
|
56
67
|
@keys||=Lolita.i18n.flattened_translations.keys.sort
|
data/lolita-i18n.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "lolita-i18n"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ITHouse (Latvia)", "Arturs Meisters", "Gatis Tomsons"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-27"
|
13
13
|
s.description = "Lolita plugin, that enables .yml files management from administrative interface. Also faster access to translations, that DB store"
|
14
14
|
s.email = "support@ithouse.lv"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
"config/routes.rb",
|
39
39
|
"lib/lolita-i18n.rb",
|
40
40
|
"lib/lolita-i18n/backend.rb",
|
41
|
+
"lib/lolita-i18n/exceptions.rb",
|
41
42
|
"lib/lolita-i18n/module.rb",
|
42
43
|
"lib/lolita-i18n/rails.rb",
|
43
44
|
"lolita-i18n.gemspec",
|
@@ -25,4 +25,9 @@ describe Lolita::I18n::Backend do
|
|
25
25
|
Lolita::I18n::Backend.set("en.test-key","Hello")
|
26
26
|
Lolita::I18n::Backend.get("en.test-key")[:value].should == "Hello"
|
27
27
|
end
|
28
|
+
|
29
|
+
it "should raise Lolita::I18n::Exceptions::MissingInterpolationArgument" do
|
30
|
+
lambda {Lolita::I18n::Backend.set("lv.copyright","Autortiesibas 2010-2012")}.should raise_error(Lolita::I18n::Exceptions::MissingInterpolationArgument)
|
31
|
+
lambda {Lolita::I18n::Backend.set("lv.copyright","Autortiesibas %{year_from}-%{year_till}")}.should_not raise_error(Lolita::I18n::Exceptions::MissingInterpolationArgument)
|
32
|
+
end
|
28
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolita-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-02-
|
14
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: lolita
|
18
|
-
requirement: &
|
18
|
+
requirement: &73099830 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: 3.2.0.rc.6
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *73099830
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hiredis
|
29
|
-
requirement: &
|
29
|
+
requirement: &73099120 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 0.3.1
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *73099120
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: redis
|
40
|
-
requirement: &
|
40
|
+
requirement: &73098170 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: 2.2.2
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *73098170
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: yajl-ruby
|
51
|
-
requirement: &
|
51
|
+
requirement: &73113540 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: 1.0.0
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *73113540
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: easy_translate
|
62
|
-
requirement: &
|
62
|
+
requirement: &73110350 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: 0.2.1
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *73110350
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: shoulda
|
73
|
-
requirement: &
|
73
|
+
requirement: &73122860 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *73122860
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: bundler
|
84
|
-
requirement: &
|
84
|
+
requirement: &73118280 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ~>
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: 1.0.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *73118280
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: jeweler
|
95
|
-
requirement: &
|
95
|
+
requirement: &73133740 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ~>
|
@@ -100,10 +100,10 @@ dependencies:
|
|
100
100
|
version: 1.5.2
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *73133740
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: rcov
|
106
|
-
requirement: &
|
106
|
+
requirement: &73142040 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
109
109
|
- - ! '>='
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
version: '0'
|
112
112
|
type: :development
|
113
113
|
prerelease: false
|
114
|
-
version_requirements: *
|
114
|
+
version_requirements: *73142040
|
115
115
|
description: Lolita plugin, that enables .yml files management from administrative
|
116
116
|
interface. Also faster access to translations, that DB store
|
117
117
|
email: support@ithouse.lv
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- config/routes.rb
|
143
143
|
- lib/lolita-i18n.rb
|
144
144
|
- lib/lolita-i18n/backend.rb
|
145
|
+
- lib/lolita-i18n/exceptions.rb
|
145
146
|
- lib/lolita-i18n/module.rb
|
146
147
|
- lib/lolita-i18n/rails.rb
|
147
148
|
- lolita-i18n.gemspec
|
@@ -170,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
171
|
version: '0'
|
171
172
|
segments:
|
172
173
|
- 0
|
173
|
-
hash:
|
174
|
+
hash: 560858397
|
174
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
176
|
none: false
|
176
177
|
requirements:
|