acts_as_localized 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.travis.yml +2 -0
- data/Gemfile +7 -0
- data/README.md +35 -0
- data/Rakefile +11 -0
- data/acts_as_localized.gemspec +27 -0
- data/lib/acts_as_localized/railtie.rb +9 -0
- data/lib/acts_as_localized/version.rb +3 -0
- data/lib/acts_as_localized.rb +20 -0
- data/test/acts_as_localized_test.rb +63 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e61f91e7f43ba936ce1197b55e20a86cff2c1c44
|
4
|
+
data.tar.gz: 2dee242adebaef517a527f3ce3a3e8322ef81a04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea47429a00a574b7259298c37edbf3039fd58a1ba0c5299cb7990ba36fcc0f36beea735a0093c3d6e499ef3a23090e8b21a524e967a35b1b0abfd956b159ab37
|
7
|
+
data.tar.gz: ed117e78a096a95290ab3428fc90084984204d2ee836cbcfa272ac7536c0aea7ac1e6630d844176a104c8ae0d24f448d3b6c0718728b9eaf81121acd96b6a36b
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# ActsAsLocalized
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/acts_as_localized.svg?style=flat)](http://rubygems.org/gems/acts_as_localized) [![Gem Downloads](https://img.shields.io/gem/dt/acts_as_localized.svg?style=flat)](http://rubygems.org/gems/acts_as_localized) [![Build Status](https://img.shields.io/travis/GBH/acts_as_localized.svg?style=flat)](https://travis-ci.org/GBH/acts_as_localized)
|
3
|
+
|
4
|
+
ActsAsLocalized extends ActiveRecord to add localization mechanism for model attributes.
|
5
|
+
|
6
|
+
## Example
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
create_table :pictures do |t|
|
10
|
+
t.string :title_en
|
11
|
+
t.string :title_fr
|
12
|
+
t.text :description_en
|
13
|
+
t.text :description_fr
|
14
|
+
end
|
15
|
+
|
16
|
+
class Picture < ActiveRecord::Base
|
17
|
+
acts_as_localized :title, :description
|
18
|
+
end
|
19
|
+
|
20
|
+
picture = Picture.create!(
|
21
|
+
:title_en => 'Title EN',
|
22
|
+
:title_fr => 'Title FR',
|
23
|
+
:description_en => 'Description EN',
|
24
|
+
:description_fr => 'Description FR',
|
25
|
+
)
|
26
|
+
|
27
|
+
I18n.locale = :en
|
28
|
+
picture.title # => Title EN
|
29
|
+
I18n.locale = :fr
|
30
|
+
picture.title # => Title FR
|
31
|
+
```
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
Copyright 2015 Oleg Khabarov
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'acts_as_localized/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "acts_as_localized"
|
8
|
+
s.version = ActsAsLocalized::VERSION
|
9
|
+
s.authors = ["Oleg Khabarov"]
|
10
|
+
s.email = ["oleg@khabarov.ca"]
|
11
|
+
s.homepage = "http://github.com/GBH/acts_as_localized"
|
12
|
+
s.summary = "Simple mechanism to deal with AR model attribute localization"
|
13
|
+
s.description = "A gem that adds simple mechanism to deal with localization of Active Record models"
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.required_ruby_version = '>= 1.9.3'
|
21
|
+
|
22
|
+
s.add_dependency 'activerecord', '>= 3.0.0'
|
23
|
+
s.add_dependency 'i18n'
|
24
|
+
|
25
|
+
s.add_development_dependency 'sqlite3'
|
26
|
+
s.add_development_dependency 'minitest'
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActsAsLocalized
|
2
|
+
|
3
|
+
if defined? Rails::Railtie
|
4
|
+
require 'acts_as_localized/railtie'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def acts_as_localized *attributes
|
13
|
+
attributes.each do |attribute|
|
14
|
+
define_method attribute do
|
15
|
+
read_attribute("#{attribute}_#{I18n.locale}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'active_record'
|
3
|
+
require 'i18n'
|
4
|
+
require 'acts_as_localized'
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
7
|
+
|
8
|
+
class MiniTest::Test
|
9
|
+
def capture_stdout(&block)
|
10
|
+
real_stdout = $stdout
|
11
|
+
$stdout = StringIO.new
|
12
|
+
yield
|
13
|
+
$stdout.string
|
14
|
+
ensure
|
15
|
+
$stdout = real_stdout
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_db
|
19
|
+
capture_stdout do
|
20
|
+
ActiveRecord::Schema.define(:version => 1) do
|
21
|
+
create_table :test_models do |t|
|
22
|
+
t.string :attr_en
|
23
|
+
t.string :attr_fr
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown_db
|
30
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
31
|
+
ActiveRecord::Base.connection.drop_table(table)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestModel < ActiveRecord::Base
|
37
|
+
include ActsAsLocalized
|
38
|
+
acts_as_localized :attr
|
39
|
+
end
|
40
|
+
|
41
|
+
class ActsAsLocalizedTest < MiniTest::Test
|
42
|
+
|
43
|
+
def setup
|
44
|
+
setup_db
|
45
|
+
I18n.enforce_available_locales = false
|
46
|
+
I18n.locale = :en
|
47
|
+
end
|
48
|
+
|
49
|
+
def teardown
|
50
|
+
teardown_db
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_localization
|
54
|
+
model = TestModel.create!(
|
55
|
+
:attr_en => 'content EN',
|
56
|
+
:attr_fr => 'content FR'
|
57
|
+
)
|
58
|
+
assert_equal 'content EN', model.attr
|
59
|
+
I18n.locale = :fr
|
60
|
+
assert_equal 'content FR', model.attr
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_localized
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Khabarov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A gem that adds simple mechanism to deal with localization of Active
|
70
|
+
Record models
|
71
|
+
email:
|
72
|
+
- oleg@khabarov.ca
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- acts_as_localized.gemspec
|
83
|
+
- lib/acts_as_localized.rb
|
84
|
+
- lib/acts_as_localized/railtie.rb
|
85
|
+
- lib/acts_as_localized/version.rb
|
86
|
+
- test/acts_as_localized_test.rb
|
87
|
+
homepage: http://github.com/GBH/acts_as_localized
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.9.3
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Simple mechanism to deal with AR model attribute localization
|
111
|
+
test_files: []
|