virtus-localized 0.1.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +57 -6
- data/lib/virtus/localized/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299fc7e7428bc14c45bc23a528540be2049a624f
|
4
|
+
data.tar.gz: eb43371c5408514c52e9dfd764e33367ea222468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49b183a67d0c95b759a7aedb4c83ad0bb8c3ecc9bc91e1ff37ab95d01e3845a17c8ac82b713bd32e7f043d18ebb8eb519ac42895b3b5ce3023a7ae7f57bd904e
|
7
|
+
data.tar.gz: 0b9a371b3c15e7978bbba76821c94b3555dcbfd6b5b138b8f7be25d82dfaab67568a9c9fc02ed80cd54d6056c31c7d1805f7c2f7904ac22e50ec996ca42f9311
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Virtus::Localized
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status][travis-image]][travis-url]
|
4
4
|
|
5
|
-
|
5
|
+
Virtus::Localized is an extension for [virtus][travis-url] that adds the `localized` feature. It's based on the `localized` feature of [MongoID][mongoID-url] and was requested via this [issue][issue-url]
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,13 +22,53 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
You need to require it first:
|
26
26
|
|
27
|
-
|
27
|
+
```ruby
|
28
|
+
require 'virtus/localized'
|
29
|
+
```
|
30
|
+
|
31
|
+
Then it gives you the following flag when definig the `attribute`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Post
|
35
|
+
include Virtus.model
|
36
|
+
|
37
|
+
attribute :title, String, localized: true
|
38
|
+
attribute :body, String, localized: true
|
39
|
+
end
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
It uses the [i18n](https://github.com/svenfuchs/i18n) to detect the `locale` and creates an internal hash for the attribute:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
post = Post.new(title: 'Hello', body: 'English')
|
47
|
+
|
48
|
+
p post.title
|
49
|
+
# => 'Hello'
|
28
50
|
|
29
|
-
|
51
|
+
p post.body
|
52
|
+
# => 'English'
|
30
53
|
|
31
|
-
|
54
|
+
I18n.locale = :es
|
55
|
+
|
56
|
+
post.title = 'Hola'
|
57
|
+
post.body = 'Español'
|
58
|
+
|
59
|
+
p post.title
|
60
|
+
# => 'Hola'
|
61
|
+
|
62
|
+
p post.body
|
63
|
+
# => 'Español'
|
64
|
+
|
65
|
+
p post.instance_variable_get('@title')
|
66
|
+
# { "en" => "Hello", "es" => "Hola" }
|
67
|
+
|
68
|
+
p post.instance_variable_get('@body')
|
69
|
+
# { "en" => "English", "es" => "Español" }
|
70
|
+
|
71
|
+
```
|
32
72
|
|
33
73
|
## Contributing
|
34
74
|
|
@@ -37,3 +77,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
37
77
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
78
|
4. Push to the branch (`git push origin my-new-feature`)
|
39
79
|
5. Create a new Pull Request
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
[MIT](LICENSE)
|
84
|
+
|
85
|
+
[travis-image]: https://travis-ci.org/XescuGC/virtus-localized.svg?branch=maste
|
86
|
+
[travis-url]: https://travis-ci.org/XescuGC/virtus-localized
|
87
|
+
[virtus-url]: https://github.com/solnic/virtus
|
88
|
+
[mongoID-url]: https://travis-ci.org/XescuGC/virtus-localized
|
89
|
+
[issue-url]: https://travis-ci.org/XescuGC/virtus-localized
|
90
|
+
|