armot 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +24 -11
- data/lib/armot/active_record_extensions.rb +1 -1
- data/lib/armot/version.rb +1 -1
- data/test/puret_migration_test.rb +15 -4
- metadata +6 -6
data/README.md
CHANGED
|
@@ -3,31 +3,31 @@ Armot
|
|
|
3
3
|
|
|
4
4
|
Armot is a minimal rails 3 library for handle your model translations. It's
|
|
5
5
|
heavily based on [puret](https://github.com/jo/puret), by Johannes Jörg
|
|
6
|
-
Schmidt,
|
|
6
|
+
Schmidt, as it does basically the same but relying on the i18n ActiveRecord
|
|
7
7
|
backend to store and fetch translations instead of custom tables.
|
|
8
8
|
|
|
9
9
|
Choosing between puret or armot is as always a decision based on your custom
|
|
10
10
|
requirements:
|
|
11
11
|
|
|
12
|
-
1. If your application is multilingual
|
|
12
|
+
1. If your application is multilingual and it's translated with default yaml
|
|
13
13
|
files with i18n Simple backend, you should definitely go with Puret. In this
|
|
14
14
|
scenario your application contents are multilingual but doesn't dynamically
|
|
15
15
|
change, they're always the same.
|
|
16
16
|
|
|
17
|
-
2. If your application is multilingual
|
|
18
|
-
change it's contents, you might have
|
|
19
|
-
activerecord to be able to edit the translations in live.
|
|
20
|
-
|
|
17
|
+
2. If your application is multilingual and also you want to give access to
|
|
18
|
+
change it's contents, you might have chosen another i18n backend like
|
|
19
|
+
activerecord to be able to edit the translations in live. In this case
|
|
20
|
+
armot gives you some advantages:
|
|
21
21
|
|
|
22
22
|
- Your translations are centralized. If you're giving your users (maybe the
|
|
23
23
|
admins of the site) the ability to change it's multilingual contents, it
|
|
24
24
|
means that you already have an interface to edit I18n translations. Use it
|
|
25
25
|
to edit your model translations too.
|
|
26
|
-
- Use
|
|
26
|
+
- Use all i18n advantages for free, like fallbacks or being able to speed up model
|
|
27
27
|
translations with Flatten and Memoize.
|
|
28
|
-
-
|
|
28
|
+
- Don't worry about eager loading translations every time you load translated
|
|
29
29
|
models.
|
|
30
|
-
- Easy
|
|
30
|
+
- Easy to set up, no external tables.
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
Installing armot
|
|
@@ -71,8 +71,21 @@ Your translated model will have different contents for each locale transparently
|
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
Be aware that armot doesn't take care of any cache expiration. If you're using
|
|
74
|
-
Memoize with I18n ActiveRecord backend you must
|
|
75
|
-
|
|
74
|
+
Memoize with I18n ActiveRecord backend you must remember to reload the backend
|
|
75
|
+
with an observer, for example.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Development with armot
|
|
79
|
+
----------------------
|
|
80
|
+
|
|
81
|
+
Since armot stores model translations in an I18n ActiveRecord backend, in
|
|
82
|
+
development you also need to use that backend in order to see model
|
|
83
|
+
translations.
|
|
84
|
+
|
|
85
|
+
If you're using Simple backend in development I recomend you to chain it with
|
|
86
|
+
the ActiveRecord backend, this way you can see both of them.
|
|
87
|
+
|
|
88
|
+
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend)
|
|
76
89
|
|
|
77
90
|
|
|
78
91
|
|
|
@@ -18,7 +18,7 @@ module Armot
|
|
|
18
18
|
begin
|
|
19
19
|
I18n.t "#{attribute}_#{id}", :scope => "armot.#{self.class.to_s.underscore.pluralize}.#{attribute}", :raise => true
|
|
20
20
|
rescue I18n::MissingTranslationData
|
|
21
|
-
self[attribute]
|
|
21
|
+
self[attribute]
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
data/lib/armot/version.rb
CHANGED
|
@@ -10,6 +10,7 @@ class PuretMigrationTest < ActiveSupport::TestCase
|
|
|
10
10
|
I18n::Backend::ActiveRecord::Translation.delete_all
|
|
11
11
|
|
|
12
12
|
PostTranslation.create(:post_id => Post.first.id, :locale => "en", :title => 'English title', :text => "Some text")
|
|
13
|
+
PostTranslation.create(:post_id => Post.first.id, :locale => "es", :title => 'Titulo español')
|
|
13
14
|
PostTranslation.create(:post_id => Post.last.id, :locale => "en", :title => 'Second english title')
|
|
14
15
|
end
|
|
15
16
|
|
|
@@ -20,17 +21,17 @@ class PuretMigrationTest < ActiveSupport::TestCase
|
|
|
20
21
|
test "db setup" do
|
|
21
22
|
assert_equal 0, I18n::Backend::ActiveRecord::Translation.count
|
|
22
23
|
assert_equal 2, Post.count
|
|
23
|
-
assert_equal
|
|
24
|
+
assert_equal 3, PostTranslation.count
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
test "armot should not work" do
|
|
27
|
-
assert_equal
|
|
28
|
+
assert_equal nil, Post.first.title
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
test "should create i18n records for exiting puret translations" do
|
|
31
32
|
Armot::PuretIntegration.migrate
|
|
32
33
|
|
|
33
|
-
assert_equal
|
|
34
|
+
assert_equal 4, I18n::Backend::ActiveRecord::Translation.count
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
test "translations with armot should work after migrate" do
|
|
@@ -43,7 +44,17 @@ class PuretMigrationTest < ActiveSupport::TestCase
|
|
|
43
44
|
test "non existing translations reamain the same" do
|
|
44
45
|
Armot::PuretIntegration.migrate
|
|
45
46
|
|
|
46
|
-
assert_equal
|
|
47
|
+
assert_equal nil, Post.last.text
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test "should preserve translations" do
|
|
51
|
+
Armot::PuretIntegration.migrate
|
|
52
|
+
|
|
53
|
+
post = Post.first
|
|
54
|
+
I18n.locale = :es
|
|
55
|
+
assert_equal "Titulo español", post.title
|
|
56
|
+
I18n.locale = :en
|
|
57
|
+
assert_equal "English title", post.title
|
|
47
58
|
end
|
|
48
59
|
|
|
49
60
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: armot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
5
|
-
prerelease:
|
|
4
|
+
hash: 25
|
|
5
|
+
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.1.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Roger Campos
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-03-
|
|
18
|
+
date: 2011-03-14 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
149
|
requirements: []
|
|
150
150
|
|
|
151
151
|
rubyforge_project: armot
|
|
152
|
-
rubygems_version: 1.
|
|
152
|
+
rubygems_version: 1.4.2
|
|
153
153
|
signing_key:
|
|
154
154
|
specification_version: 3
|
|
155
155
|
summary: translation support for your models with an I18n active-record backend
|