same_table_translation 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -17
- data/Gemfile +4 -4
- data/README.md +59 -29
- data/lib/same_table_translation/version.rb +3 -3
- data/lib/same_table_translation.rb +42 -42
- data/same_table_translation.gemspec +19 -19
- metadata +8 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 278bac69cf3caa55fa02ffcd3d71f820c862f55c
|
4
|
+
data.tar.gz: 2dcab8bfa4daa87fefe455834dbaaf27e586402e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d958e9006668978d9e247887c84fa26769a77b37466afb1e5d2d528c4e9c5fda943b298774b5c9a13e6614aab1ed9ea2435cd4f400d1a747c4c3628491253575
|
7
|
+
data.tar.gz: 2f705392acb0a3a5b16e08930b0cf06f3398361cc4b648008c9963f77b27387b05ebf9bca5c572af034ce9d1f65dadfedb04643e1c4fec35807fa849fdeed6c7
|
data/.gitignore
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in same_table_translation.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in same_table_translation.gemspec
|
4
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,29 +1,59 @@
|
|
1
|
-
# SameTableTranslation
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
# SameTableTranslation
|
2
|
+
|
3
|
+
This gem is usefull when you whant to translate attributes from active record model in rails.
|
4
|
+
Most of translations gems use a different table in order to save a lot of translations but if you know exactly which locales you want (for exemple en and fr) it is very time consuming to store it in another table so this gem will store values on the same table and will replace the attribute column by many columns suffixed by the locale.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'same_table_translation'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install same_table_translation
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
First you need to generate migrations for your model
|
23
|
+
|
24
|
+
$ rails g same_table_translation:translate [Model] [attributes]
|
25
|
+
|
26
|
+
This will create a migration with new column for each attributes on each locale you have available in your project and remove (and migrate data) the attribute if exsists.
|
27
|
+
|
28
|
+
Then you have to add the instructions on your model to have access to some functionnalities
|
29
|
+
|
30
|
+
class MyModel < ActiveRecord::Base
|
31
|
+
translatable my_attributes
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
Now you can have access to your attribute directly and this will assign or get the value for the current locale
|
36
|
+
|
37
|
+
exemple with current locale set as en:
|
38
|
+
|
39
|
+
comment = Comment.new
|
40
|
+
comment.message = "This is a message" # this will update message_en attribute
|
41
|
+
I18n.locale = :fr # set the locale to french
|
42
|
+
puts comment.message # nil because it will return message_fr
|
43
|
+
comment.message = "Ceci est un message" # update value for message_fr attribute
|
44
|
+
I18n.locale = :en
|
45
|
+
puts comment.message # This is a message
|
46
|
+
|
47
|
+
|
48
|
+
You also have some scope to simplify things like translated(attribute) or untranslated(attribute) to list all value with attribute translated or untranslated
|
49
|
+
|
50
|
+
Comment.translated(:message) # will return all comments with message translated in the locale used
|
51
|
+
Comment.untranslated(:message) # will return all comments with message not translated in the locale used
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create new Pull Request
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module SameTableTranslation
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
1
|
+
module SameTableTranslation
|
2
|
+
VERSION = "0.1.0"
|
3
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
require "same_table_translation/version"
|
2
|
-
|
3
|
-
module SameTableTranslation
|
4
|
-
def translatable(*attributes)
|
5
|
-
locales = I18n.available_locales
|
6
|
-
attributes.each do |attribute|
|
7
|
-
locales.each do |locale|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
begin
|
19
|
-
self.attributes["#{attribute.to_s}_#{I18n.locale.to_s}"]
|
20
|
-
rescue
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
begin
|
26
|
-
self.attributes = { "#{attribute}_#{I18n.locale.to_s}" => value }
|
27
|
-
rescue
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
scope :translated, lambda { |attribute|
|
33
|
-
where(arel_table["#{attribute.to_s}_#{I18n.locale.to_s}".to_sym].not_eq(nil))
|
34
|
-
}
|
35
|
-
|
36
|
-
scope :untranslated, lambda { |attribute|
|
37
|
-
where(arel_table["#{attribute.to_s}_#{I18n.locale.to_s}".to_sym].eq(nil))
|
38
|
-
}
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
ActiveRecord::Base.extend SameTableTranslation
|
1
|
+
require "same_table_translation/version"
|
2
|
+
|
3
|
+
module SameTableTranslation
|
4
|
+
def translatable(*attributes)
|
5
|
+
locales = I18n.available_locales
|
6
|
+
attributes.each do |attribute|
|
7
|
+
locales.each do |locale|
|
8
|
+
begin
|
9
|
+
name = "#{attribute.to_s}_#{locale.to_s}"
|
10
|
+
attr_accessible name.to_sym if self.attribute_names.include?(name)
|
11
|
+
rescue
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attributes.each do |attribute|
|
17
|
+
define_method attribute.to_s do
|
18
|
+
begin
|
19
|
+
self.attributes["#{attribute.to_s}_#{I18n.locale.to_s}"]
|
20
|
+
rescue
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method "#{attribute.to_s}=" do |value|
|
25
|
+
begin
|
26
|
+
self.attributes = { "#{attribute}_#{I18n.locale.to_s}" => value }
|
27
|
+
rescue
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
scope :translated, lambda { |attribute|
|
33
|
+
where(arel_table["#{attribute.to_s}_#{I18n.locale.to_s}".to_sym].not_eq(nil))
|
34
|
+
}
|
35
|
+
|
36
|
+
scope :untranslated, lambda { |attribute|
|
37
|
+
where(arel_table["#{attribute.to_s}_#{I18n.locale.to_s}".to_sym].eq(nil))
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
ActiveRecord::Base.extend SameTableTranslation
|
@@ -1,19 +1,19 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'same_table_translation/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "same_table_translation"
|
8
|
-
gem.version = SameTableTranslation::VERSION
|
9
|
-
gem.authors = ["antho1404"]
|
10
|
-
gem.email = ["anthony.estebe@gmail.com"]
|
11
|
-
gem.description = %q{Translate a simple attribute in all your locales }
|
12
|
-
gem.summary = %q{This is similar to most of other translation plugin in rails but usefull if you want to translate in few language because we don't need any join like others plugins. }
|
13
|
-
gem.homepage = "https://github.com/antho1404/same_table_translation"
|
14
|
-
|
15
|
-
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = ["lib"]
|
19
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'same_table_translation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "same_table_translation"
|
8
|
+
gem.version = SameTableTranslation::VERSION
|
9
|
+
gem.authors = ["antho1404"]
|
10
|
+
gem.email = ["anthony.estebe@gmail.com"]
|
11
|
+
gem.description = %q{Translate a simple attribute in all your locales }
|
12
|
+
gem.summary = %q{This is similar to most of other translation plugin in rails but usefull if you want to translate in few language because we don't need any join like others plugins. }
|
13
|
+
gem.homepage = "https://github.com/antho1404/same_table_translation"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: same_table_translation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- antho1404
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
13
|
+
description: 'Translate a simple attribute in all your locales '
|
15
14
|
email:
|
16
15
|
- anthony.estebe@gmail.com
|
17
16
|
executables: []
|
@@ -31,27 +30,26 @@ files:
|
|
31
30
|
- same_table_translation.gemspec
|
32
31
|
homepage: https://github.com/antho1404/same_table_translation
|
33
32
|
licenses: []
|
33
|
+
metadata: {}
|
34
34
|
post_install_message:
|
35
35
|
rdoc_options: []
|
36
36
|
require_paths:
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
39
|
requirements:
|
41
|
-
- -
|
40
|
+
- - '>='
|
42
41
|
- !ruby/object:Gem::Version
|
43
42
|
version: '0'
|
44
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
44
|
requirements:
|
47
|
-
- -
|
45
|
+
- - '>='
|
48
46
|
- !ruby/object:Gem::Version
|
49
47
|
version: '0'
|
50
48
|
requirements: []
|
51
49
|
rubyforge_project:
|
52
|
-
rubygems_version:
|
50
|
+
rubygems_version: 2.0.3
|
53
51
|
signing_key:
|
54
|
-
specification_version:
|
52
|
+
specification_version: 4
|
55
53
|
summary: This is similar to most of other translation plugin in rails but usefull
|
56
54
|
if you want to translate in few language because we don't need any join like others
|
57
55
|
plugins.
|