acts_as_simple_translatable 0.1.1 → 0.2.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 +5 -5
- data/README.md +24 -15
- data/acts_as_simple_translatable.gemspec +10 -11
- data/lib/acts_as_simple_translatable/class_methods.rb +3 -3
- data/lib/acts_as_simple_translatable/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 24dd027cefed20ed03d6ef4ba55f81cc02badf71b879af51d14bc1cf63d691e2
|
4
|
+
data.tar.gz: 6986095069f2fee0d5703a1725f5850469ef2c7f599189d2e0be9c7d8ed9d448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2656e18382f315a1f8f16cfec24400207c14dfaf035aa8e602e31394ce0e02b6987192cd6364fba1e91fc25cdc83b9f41d9b5ea7675f99ff92b8d89a89b7c6a6
|
7
|
+
data.tar.gz: a3ef7d1b4dbb2f7107af078a793c41db6b6285686957f6bb148d30ec9224b047216d4e19a4b3384feafbc0bde87aaad2051f631ef11f9d6b031c4d69635dc466
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ActsAsSimpleTranslatable
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/acts_as_simple_translatable)
|
4
|
+
|
5
|
+
Adds translation table, and helpers to work with model translations.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,7 +20,7 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Configuration
|
20
22
|
|
21
|
-
This will create a translations table
|
23
|
+
This will create a translations table:
|
22
24
|
|
23
25
|
$ rails generate acts_as_simple_translatable:install
|
24
26
|
|
@@ -26,38 +28,45 @@ To add translation to your model just add to your model:
|
|
26
28
|
|
27
29
|
acts_as_simple_translatable_on :name, :description
|
28
30
|
|
29
|
-
Add to application
|
31
|
+
Add to `application.rb`:
|
30
32
|
|
31
33
|
I18n.avaliable_locales = ['en', 'de']
|
32
34
|
|
33
35
|
## Usage
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
```ruby
|
38
|
+
m = Model.create(name: 'name', descritpion: 'description' )
|
39
|
+
m.translations.create(locale: 'de', tanslatable_field: 'name', content: 'name_in_de')
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
I18n.locale = 'de'
|
42
|
+
m.name #=> 'name_in_de'
|
43
|
+
m.description #=> 'description'
|
44
|
+
```
|
41
45
|
|
42
46
|
Default locale content will be saved in original field in table (e.g. in table `Model`, attribute `name`) while for other locales content will be saved in `translations` table.
|
43
47
|
|
44
48
|
You also have the access to list of translatable fields:
|
45
|
-
|
46
|
-
|
49
|
+
```ruby
|
50
|
+
Model.locale_fields #=> [:name, :description]
|
51
|
+
```
|
47
52
|
|
48
53
|
You can access to original field by prepending `_original` to attribute name:
|
49
54
|
|
50
|
-
|
55
|
+
```ruby
|
56
|
+
description_original
|
57
|
+
```
|
51
58
|
|
52
|
-
Also, when you accessing to attribute and there is no translation for it, you can define custom message or default
|
59
|
+
Also, when you accessing to attribute and there is no translation for it, you can define custom message or default will be returned.
|
53
60
|
|
54
|
-
|
61
|
+
```ruby
|
62
|
+
my_model.name # => 'name' <-- default message
|
55
63
|
|
56
|
-
|
64
|
+
my_model.name('You need translate this') # => 'You need translate this' <-- custom message
|
65
|
+
```
|
57
66
|
|
58
67
|
## Contributing
|
59
68
|
|
60
|
-
1. Fork it ( http://github.com/
|
69
|
+
1. Fork it ( http://github.com/infinum/acts_as_simple_translatable/fork )
|
61
70
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
71
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
72
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -1,23 +1,22 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'acts_as_simple_translatable/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'acts_as_simple_translatable'
|
8
7
|
spec.version = ActsAsSimpleTranslatable::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
8
|
+
spec.authors = ['Stjepan Hadjic']
|
9
|
+
spec.email = ['d4be4st@gmail.com']
|
10
|
+
spec.summary = 'acts as simple translatable'
|
11
|
+
spec.description = 'Took acts_as_translatable and stripped it down'
|
12
|
+
spec.homepage = 'https://github.com/infinum/acts_as_simple_translatable'
|
13
|
+
spec.license = 'MIT'
|
15
14
|
|
16
15
|
spec.files = `git ls-files -z`.split("\x0")
|
17
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
21
|
+
spec.add_development_dependency 'rake'
|
23
22
|
end
|
@@ -13,13 +13,13 @@ module ActsAsSimpleTranslatable
|
|
13
13
|
|
14
14
|
# Loop through fields to define methods such as "name" and "description"
|
15
15
|
fields.each do |field|
|
16
|
-
define_method "#{field}" do
|
16
|
+
define_method "#{field}" do
|
17
17
|
content = (I18n.locale == I18n.default_locale) ? super() : locale_translations[field]
|
18
|
-
content.present?
|
18
|
+
content.present? ? content : super
|
19
19
|
end
|
20
20
|
|
21
21
|
define_method "#{field}_original" do
|
22
|
-
|
22
|
+
self[field]
|
23
23
|
end
|
24
24
|
|
25
25
|
define_method "#{field}?" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_simple_translatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stjepan Hadjic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description: Took acts_as_translatable and stripped it down
|
42
42
|
email:
|
43
43
|
- d4be4st@gmail.com
|
44
44
|
executables: []
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- lib/generators/acts_as_simple_translatable/USAGE
|
59
59
|
- lib/generators/acts_as_simple_translatable/install_generator.rb
|
60
60
|
- lib/generators/acts_as_simple_translatable/templates/migration.rb
|
61
|
-
homepage:
|
61
|
+
homepage: https://github.com/infinum/acts_as_simple_translatable
|
62
62
|
licenses:
|
63
63
|
- MIT
|
64
64
|
metadata: {}
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.7.6
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: acts as simple translatable
|