multilang-hstore 1.0.0.rc1 → 1.0.0.rc2
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/.gitignore +15 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +45 -0
- data/LICENSE +21 -0
- data/README.md +134 -0
- data/Rakefile +21 -0
- data/lib/multilang-hstore/exceptions.rb +5 -0
- data/lib/multilang-hstore/version.rb +1 -1
- data/multilang-hstore.gemspec +25 -0
- metadata +9 -1
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (4.0.0)
|
5
|
+
activesupport (= 4.0.0)
|
6
|
+
builder (~> 3.1.0)
|
7
|
+
activerecord (4.0.0)
|
8
|
+
activemodel (= 4.0.0)
|
9
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
10
|
+
activesupport (= 4.0.0)
|
11
|
+
arel (~> 4.0.0)
|
12
|
+
activerecord-deprecated_finders (1.0.3)
|
13
|
+
activesupport (4.0.0)
|
14
|
+
i18n (~> 0.6, >= 0.6.4)
|
15
|
+
minitest (~> 4.2)
|
16
|
+
multi_json (~> 1.3)
|
17
|
+
thread_safe (~> 0.1)
|
18
|
+
tzinfo (~> 0.3.37)
|
19
|
+
arel (4.0.0)
|
20
|
+
atomic (1.1.9)
|
21
|
+
builder (3.1.4)
|
22
|
+
diff-lcs (1.1.3)
|
23
|
+
i18n (0.6.4)
|
24
|
+
minitest (4.7.5)
|
25
|
+
multi_json (1.7.7)
|
26
|
+
pg (0.14.1)
|
27
|
+
rspec (2.12.0)
|
28
|
+
rspec-core (~> 2.12.0)
|
29
|
+
rspec-expectations (~> 2.12.0)
|
30
|
+
rspec-mocks (~> 2.12.0)
|
31
|
+
rspec-core (2.12.2)
|
32
|
+
rspec-expectations (2.12.1)
|
33
|
+
diff-lcs (~> 1.1.3)
|
34
|
+
rspec-mocks (2.12.2)
|
35
|
+
thread_safe (0.1.0)
|
36
|
+
atomic
|
37
|
+
tzinfo (0.3.37)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
activerecord (>= 4.0.0)
|
44
|
+
pg (>= 0.0.1)
|
45
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010 Arthur Meinart
|
2
|
+
Copyright (c) 2012-2013 Heapsource.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# Multilang-hstore
|
2
|
+
|
3
|
+
Multilang is a small translation library for translating database values for Rails 3 using the [Hstore datatype](http://www.postgresql.org/docs/9.0/static/hstore.html).
|
4
|
+
|
5
|
+
This project is a fork of [artworklv/multilang](https://github.com/artworklv/multilang) with some remarkable differences:
|
6
|
+
|
7
|
+
* Replaced YAML text fields in favor of Hstore fields.
|
8
|
+
* The translation hash is no longer limited to locales in `I18n.available_locales`.
|
9
|
+
|
10
|
+
It uses [engageis/activerecord-postgres-hstore](https://github.com/engageis/activerecord-postgres-hstore)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
You need configure the multilang gem inside your gemfile:
|
15
|
+
|
16
|
+
gem 'multilang-hstore'
|
17
|
+
|
18
|
+
Do not forget to run
|
19
|
+
|
20
|
+
bundle install
|
21
|
+
|
22
|
+
## Basic Usage
|
23
|
+
|
24
|
+
This is a walkthrough with all steps you need to setup multilang translated attributes, including model and migration.
|
25
|
+
|
26
|
+
We're assuming here you want a Post model with some multilang attributes, as outlined below:
|
27
|
+
|
28
|
+
class Post < ActiveRecord::Base
|
29
|
+
multilang :title, :accessible => true
|
30
|
+
end
|
31
|
+
|
32
|
+
or
|
33
|
+
|
34
|
+
class Post < ActiveRecord::Base
|
35
|
+
multilang :title, :description, :required => true, :length => 100, :accessible => true
|
36
|
+
end
|
37
|
+
|
38
|
+
The multilang translations are stored in the same model attributes (eg. title):
|
39
|
+
|
40
|
+
You may need to create migration for Post as usual, but multilang attributes should be in hstore type:
|
41
|
+
|
42
|
+
create_table(:posts) do |t|
|
43
|
+
t.hstore :title
|
44
|
+
t.timestamps
|
45
|
+
end
|
46
|
+
|
47
|
+
Thats it!
|
48
|
+
|
49
|
+
Now you are able to translate values for the attributes :title and :description per locale:
|
50
|
+
|
51
|
+
I18n.locale = :en
|
52
|
+
post.title = 'Multilang rocks!'
|
53
|
+
I18n.locale = :lv
|
54
|
+
post.title = 'Multilang rulle!'
|
55
|
+
|
56
|
+
I18n.locale = :en
|
57
|
+
post.title #=> Multilang rocks!
|
58
|
+
I18n.locale = :lv
|
59
|
+
post.title #=> Multilang rulle!
|
60
|
+
|
61
|
+
|
62
|
+
You may assign attributes through auto generated methods (this methods depend from I18n.available_locales):
|
63
|
+
|
64
|
+
I18n.available_locales #=> [:en. :lv]
|
65
|
+
|
66
|
+
post.title_en = 'Multilang rocks!'
|
67
|
+
post.title_lv = 'Multilang rulle!'
|
68
|
+
|
69
|
+
post.title_en #=> 'Multilang rocks!'
|
70
|
+
post.title_lv #=> 'Multilang rulle!'
|
71
|
+
|
72
|
+
You may use mass assignment on model creation (if :accessible param is defined):
|
73
|
+
|
74
|
+
Post.new(:title => {:en => 'Multilang rocks!', :lv => 'Multilang rulle!'})
|
75
|
+
|
76
|
+
or
|
77
|
+
|
78
|
+
Post.new(:title_en => 'Multilang rocks!', :title_lv => 'Multilang rulle!')
|
79
|
+
|
80
|
+
Also, you may ise same hashes with setters:
|
81
|
+
|
82
|
+
post.title = {:en => 'Multilang rocks!', :lv => 'Multilang rulle!'}
|
83
|
+
|
84
|
+
## Attribute methods
|
85
|
+
|
86
|
+
You may get other translations via attribute translation method:
|
87
|
+
|
88
|
+
post.title.translation[:lv] #=> 'Multilang rocks!'
|
89
|
+
post.title.translation[:en] #=> 'Multilang rulle!'
|
90
|
+
post.title.translation.locales #=> [:en, :lv]
|
91
|
+
|
92
|
+
If you have incomplete translations, you can get translation from other locale:
|
93
|
+
|
94
|
+
post.title = {:en => 'Multilang rocks!', :lv => ''}
|
95
|
+
I18n.locale = :lv
|
96
|
+
post.title.any #=> 'Multilang rocks!'
|
97
|
+
|
98
|
+
The value from "any" method returns value for I18n.current_locale or, if value is empty, it searches through all locales. It takes searching order from I18n.available_locales array.
|
99
|
+
|
100
|
+
## Validations
|
101
|
+
Multilang has some validation features:
|
102
|
+
|
103
|
+
multilang :title, :length => 100 #define maximal length validator
|
104
|
+
multilang :title, :required => true #define requirement validator
|
105
|
+
multilang :title, :format => /regexp/ #define validates_format_of validator
|
106
|
+
|
107
|
+
## Tests
|
108
|
+
|
109
|
+
Test runs using a temporary database in your local PostgreSQL server:
|
110
|
+
|
111
|
+
Create a test database:
|
112
|
+
|
113
|
+
$ createdb multilang-hstore-test
|
114
|
+
|
115
|
+
Create the [hstore extension](http://www.postgresql.org/docs/9.1/static/sql-createextension.html):
|
116
|
+
|
117
|
+
psql -d multilang-hstore-test -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
118
|
+
|
119
|
+
Create the role *postgres* if necessary:
|
120
|
+
|
121
|
+
$ createuser -s -r postgres
|
122
|
+
|
123
|
+
Finally, you can run your tests:
|
124
|
+
|
125
|
+
rspec
|
126
|
+
|
127
|
+
## Bugs and Feedback
|
128
|
+
|
129
|
+
Use [http://github.com/heapsource/multilang-hstore/issues](http://github.com/heapsource/multilang-hstore/issues)
|
130
|
+
|
131
|
+
## License(MIT)
|
132
|
+
|
133
|
+
* Copyright (c) 2012-2013 Heapsource.com
|
134
|
+
* Copyright (c) 2010 Arthur Meinart
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
desc 'Default: run specs.'
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
desc "Run specs"
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.pattern = "spec/**/*_spec.rb"
|
11
|
+
t.rspec_opts = ["-c"]
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Generate documentation for the multilang plugin.'
|
15
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Multilang'
|
18
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "multilang-hstore/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{multilang-hstore}
|
7
|
+
s.version = Multilang::VERSION
|
8
|
+
|
9
|
+
s.authors = ["Arthur Meinart", "Heapsource"]
|
10
|
+
s.date = %q{2013-07-25}
|
11
|
+
s.description = %q{Model translations for Rails 3 backed by PostgreSQL and Hstore}
|
12
|
+
s.email = %q{hello@heapsource.com}
|
13
|
+
s.files = `git ls-files`.split($/)
|
14
|
+
s.homepage = %q{http://github.com/heapsource/multilang-hstore}
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.summary = %q{Model translations for Rails 3 backed by PostgreSQL and Hstore}
|
17
|
+
s.test_files = [
|
18
|
+
"spec/multilang_spec.rb",
|
19
|
+
"spec/schema.rb",
|
20
|
+
"spec/spec_helper.rb"
|
21
|
+
]
|
22
|
+
s.add_dependency 'pg', '>= 0.0.1'
|
23
|
+
s.add_dependency 'activerecord', '>= 4.0.0'
|
24
|
+
end
|
25
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multilang-hstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,11 +50,19 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
53
59
|
- lib/multilang-hstore.rb
|
54
60
|
- lib/multilang-hstore/active_record_extensions.rb
|
61
|
+
- lib/multilang-hstore/exceptions.rb
|
55
62
|
- lib/multilang-hstore/translation_keeper.rb
|
56
63
|
- lib/multilang-hstore/translation_proxy.rb
|
57
64
|
- lib/multilang-hstore/version.rb
|
65
|
+
- multilang-hstore.gemspec
|
58
66
|
- spec/multilang_spec.rb
|
59
67
|
- spec/schema.rb
|
60
68
|
- spec/spec_helper.rb
|