traco 1.3.0 → 2.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.
- data/CHANGELOG.md +9 -0
- data/{README.markdown → README.md} +51 -37
- data/lib/traco.rb +7 -0
- data/lib/traco/attribute_setup.rb +78 -0
- data/lib/traco/class_methods.rb +8 -5
- data/lib/traco/localized_reader.rb +3 -3
- data/lib/traco/translates.rb +2 -81
- data/lib/traco/version.rb +1 -1
- data/spec/spec_helper.rb +6 -6
- data/spec/traco_spec.rb +45 -24
- data/traco.gemspec +0 -2
- metadata +7 -38
- data/Guardfile +0 -6
data/CHANGELOG.md
ADDED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/barsoom/traco)
|
4
4
|
|
5
|
-
Translatable attributes for Rails 3, stored in the model table itself.
|
5
|
+
Translatable attributes for Rails 3 and 4 (Ruby 1.9+), stored in the model table itself.
|
6
6
|
|
7
7
|
Inspired by Iain Hecker's [translatable_columns](https://github.com/iain/translatable_columns/).
|
8
8
|
|
@@ -15,26 +15,30 @@ Say you want `Post#title` and `Post#body` to support both English and Swedish va
|
|
15
15
|
|
16
16
|
Write a migration to get database columns with locale suffixes, e.g. `title_sv` and `title_en`, like:
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
```ruby
|
19
|
+
class CreatePosts < ActiveRecord::Migration
|
20
|
+
def change
|
21
|
+
create_table :posts do |t|
|
22
|
+
t.string :title_sv, :title_en
|
23
|
+
t.text :body_sv, :body_en
|
23
24
|
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
25
|
+
t.timestamps
|
27
26
|
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
28
30
|
|
29
31
|
Don't create a database column named `title` without a suffix, since Traco will define a method with that name.
|
30
32
|
|
31
|
-
|
33
|
+
If you use a locale format like `pt-BR`, the column name would be `title_pt_br`.
|
32
34
|
|
33
35
|
Declare the attributes in the model:
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
```ruby
|
38
|
+
class Post < ActiveRecord::Base
|
39
|
+
translates :title, :body
|
40
|
+
end
|
41
|
+
```
|
38
42
|
|
39
43
|
You can still use your accessors like `title_sv` and `title_sv=` in forms, validations and other code, but you also get:
|
40
44
|
|
@@ -48,23 +52,28 @@ You can still use your accessors like `title_sv` and `title_sv=` in forms, valid
|
|
48
52
|
|
49
53
|
`.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with default locale first and then alphabetically. Suitable for looping in forms:
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
```erb
|
56
|
+
<% Post.locale_columns(:title).each do |column| %>
|
57
|
+
<p>
|
58
|
+
<%= form.label column %>
|
59
|
+
<%= form.text_field column %>
|
60
|
+
</p>
|
61
|
+
<% end %>
|
62
|
+
```
|
57
63
|
|
58
64
|
Or perhaps for things like:
|
59
65
|
|
60
|
-
|
66
|
+
```ruby
|
67
|
+
attr_accessible *locale_columns(:title)
|
61
68
|
|
62
|
-
|
63
|
-
|
69
|
+
validates *locale_columns(:title), :uniqueness => true
|
70
|
+
```
|
64
71
|
|
65
72
|
You can also pass multiple attributes if you like:
|
66
73
|
|
67
|
-
|
74
|
+
```ruby
|
75
|
+
attr_accessible *locale_columns(:title, :body)
|
76
|
+
```
|
68
77
|
|
69
78
|
The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]`.
|
70
79
|
|
@@ -79,10 +88,12 @@ Please note that your `translates :title, :body` declaration must be called befo
|
|
79
88
|
|
80
89
|
if you specify
|
81
90
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
91
|
+
```ruby
|
92
|
+
class Post < ActiveRecord::Base
|
93
|
+
translates :title, :body,
|
94
|
+
fallback: false
|
95
|
+
end
|
96
|
+
```
|
86
97
|
|
87
98
|
then `#title` will return `nil` if there is no translation in the current locale, instead of falling back to the default locale.
|
88
99
|
|
@@ -91,20 +102,23 @@ then `#title` will return `nil` if there is no translation in the current locale
|
|
91
102
|
|
92
103
|
Methods are defined in an included module, so you can just override them and call Traco's implementation with `super`:
|
93
104
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
def title
|
98
|
-
super.reverse
|
99
|
-
end
|
100
|
-
end
|
105
|
+
```ruby
|
106
|
+
class Post < ActiveRecord::Base
|
107
|
+
translates :title
|
101
108
|
|
109
|
+
def title
|
110
|
+
super.reverse
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
102
114
|
|
103
115
|
## Installation
|
104
116
|
|
105
|
-
Add this to your `Gemfile
|
117
|
+
Add this to your `Gemfile`:
|
106
118
|
|
107
|
-
|
119
|
+
```ruby
|
120
|
+
gem 'traco'
|
121
|
+
```
|
108
122
|
|
109
123
|
Then run
|
110
124
|
|
@@ -116,7 +130,7 @@ to install it.
|
|
116
130
|
## Running the tests
|
117
131
|
|
118
132
|
bundle
|
119
|
-
rake
|
133
|
+
rake
|
120
134
|
|
121
135
|
|
122
136
|
<!-- Keeping this a hidden brain dump for now.
|
data/lib/traco.rb
CHANGED
@@ -2,3 +2,10 @@ require "traco/version"
|
|
2
2
|
require "traco/translates"
|
3
3
|
require "traco/class_methods"
|
4
4
|
require "traco/localized_reader"
|
5
|
+
|
6
|
+
module Traco
|
7
|
+
# E.g. :sv -> :sv, :"pt-BR" -> :pt_br
|
8
|
+
def self.locale_suffix(locale)
|
9
|
+
locale.to_s.downcase.sub("-", "_").to_sym
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Traco
|
2
|
+
class AttributeSetup
|
3
|
+
INSTANCE_METHODS_MODULE_NAME = "TracoInstanceMethods"
|
4
|
+
|
5
|
+
def initialize(klass)
|
6
|
+
@klass = klass
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_up(attributes, options)
|
10
|
+
ensure_class_methods
|
11
|
+
ensure_attribute_list
|
12
|
+
ensure_instance_methods_module
|
13
|
+
add_attributes attributes, options
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def ensure_class_methods
|
19
|
+
klass.extend Traco::ClassMethods
|
20
|
+
end
|
21
|
+
|
22
|
+
# Only called once per class or inheritance chain (e.g. once
|
23
|
+
# for the superclass, not at all for subclasses). The separation
|
24
|
+
# is important if we don't want to overwrite values if running
|
25
|
+
# multiple times in the same class or in different classes of
|
26
|
+
# an inheritance chain.
|
27
|
+
def ensure_attribute_list
|
28
|
+
return if klass.respond_to?(:translatable_attributes)
|
29
|
+
klass.class_attribute :translatable_attributes
|
30
|
+
klass.translatable_attributes = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def ensure_instance_methods_module
|
34
|
+
# Instance methods are defined on an included module, so your class
|
35
|
+
# can just redefine them and call `super`, if you need to.
|
36
|
+
# http://thepugautomatic.com/2013/07/dsom/
|
37
|
+
unless klass.const_defined?(INSTANCE_METHODS_MODULE_NAME, _search_ancestors = false)
|
38
|
+
klass.send :include, klass.const_set(INSTANCE_METHODS_MODULE_NAME, Module.new)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_attributes(attributes, options)
|
43
|
+
klass.translatable_attributes |= attributes
|
44
|
+
|
45
|
+
attributes.each do |attribute|
|
46
|
+
define_localized_reader attribute, options
|
47
|
+
define_localized_writer attribute, options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def define_localized_reader(attribute, options)
|
52
|
+
fallback = options.fetch(:fallback, true)
|
53
|
+
|
54
|
+
custom_define_method(attribute) do
|
55
|
+
@localized_readers ||= {}
|
56
|
+
@localized_readers[attribute] ||= Traco::LocalizedReader.new(self, attribute, fallback: fallback)
|
57
|
+
@localized_readers[attribute].value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def define_localized_writer(attribute, options)
|
62
|
+
custom_define_method("#{attribute}=") do |value|
|
63
|
+
suffix = Traco.locale_suffix(I18n.locale)
|
64
|
+
send("#{attribute}_#{suffix}=", value)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def custom_define_method(name, &block)
|
69
|
+
klass.const_get(INSTANCE_METHODS_MODULE_NAME).module_eval do
|
70
|
+
define_method(name, &block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def klass
|
75
|
+
@klass
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/traco/class_methods.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Traco
|
2
2
|
module ClassMethods
|
3
|
-
LOCALE_RE = /[a-zA-Z]{2}(
|
3
|
+
LOCALE_RE = /[a-zA-Z]{2}(?:_[a-zA-Z]{2})?/
|
4
4
|
|
5
5
|
def locales_for_attribute(attribute)
|
6
6
|
re = /\A#{attribute}_(#{LOCALE_RE})\z/
|
@@ -19,13 +19,15 @@ module Traco
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def human_attribute_name(attribute, options = {})
|
22
|
-
default = super(attribute, options.merge(:
|
23
|
-
|
22
|
+
default = super(attribute, options.merge(default: ""))
|
23
|
+
|
24
|
+
if default.blank? && attribute.to_s.match(/\A(\w+?)_(#{LOCALE_RE})\z/)
|
24
25
|
column, locale = $1, $2.to_sym
|
25
26
|
if translates?(column)
|
26
27
|
return "#{super(column, options)} (#{locale_name(locale)})"
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
29
31
|
super
|
30
32
|
end
|
31
33
|
|
@@ -33,7 +35,7 @@ module Traco
|
|
33
35
|
|
34
36
|
def locale_sort_value
|
35
37
|
lambda { |locale|
|
36
|
-
if locale == I18n.default_locale
|
38
|
+
if locale == Traco.locale_suffix(I18n.default_locale)
|
37
39
|
# Sort the default locale first.
|
38
40
|
"0"
|
39
41
|
else
|
@@ -48,7 +50,8 @@ module Traco
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def locale_name(locale)
|
51
|
-
|
53
|
+
default = locale.to_s.upcase.sub("_", "-")
|
54
|
+
I18n.t(locale, scope: :"i18n.languages", default: default)
|
52
55
|
end
|
53
56
|
end
|
54
57
|
end
|
@@ -8,7 +8,7 @@ module Traco
|
|
8
8
|
|
9
9
|
def value
|
10
10
|
locales_to_try.each do |locale|
|
11
|
-
value = @record.send("#{@attribute}_#{locale}")
|
11
|
+
value = @record.send("#{@attribute}_#{Traco.locale_suffix(locale)}")
|
12
12
|
return value if value.present?
|
13
13
|
end
|
14
14
|
|
@@ -18,14 +18,14 @@ module Traco
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def locales_to_try
|
21
|
-
|
21
|
+
locale_chain & locales_for_attribute
|
22
22
|
end
|
23
23
|
|
24
24
|
def locale_chain
|
25
25
|
chain = []
|
26
26
|
chain << I18n.locale
|
27
27
|
chain << I18n.default_locale if @fallback
|
28
|
-
chain
|
28
|
+
chain.map { |locale| Traco.locale_suffix(locale) }
|
29
29
|
end
|
30
30
|
|
31
31
|
def locales_for_attribute
|
data/lib/traco/translates.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "traco/attribute_setup"
|
2
|
+
|
1
3
|
module Traco
|
2
4
|
module Translates
|
3
5
|
def translates(*attributes)
|
@@ -9,84 +11,3 @@ module Traco
|
|
9
11
|
end
|
10
12
|
|
11
13
|
ActiveRecord::Base.send :extend, Traco::Translates
|
12
|
-
|
13
|
-
|
14
|
-
module Traco
|
15
|
-
class AttributeSetup
|
16
|
-
INSTANCE_METHODS_MODULE_NAME = "TracoInstanceMethods"
|
17
|
-
|
18
|
-
def initialize(klass)
|
19
|
-
@klass = klass
|
20
|
-
end
|
21
|
-
|
22
|
-
def set_up(attributes, options)
|
23
|
-
ensure_class_methods
|
24
|
-
ensure_attribute_list
|
25
|
-
ensure_instance_methods_module
|
26
|
-
add_attributes attributes, options
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def ensure_class_methods
|
32
|
-
klass.extend Traco::ClassMethods
|
33
|
-
end
|
34
|
-
|
35
|
-
# Only called once per class or inheritance chain (e.g. once
|
36
|
-
# for the superclass, not at all for subclasses). The separation
|
37
|
-
# is important if we don't want to overwrite values if running
|
38
|
-
# multiple times in the same class or in different classes of
|
39
|
-
# an inheritance chain.
|
40
|
-
def ensure_attribute_list
|
41
|
-
return if klass.respond_to?(:translatable_attributes)
|
42
|
-
klass.class_attribute :translatable_attributes
|
43
|
-
klass.translatable_attributes = []
|
44
|
-
end
|
45
|
-
|
46
|
-
def ensure_instance_methods_module
|
47
|
-
# Instance methods are defined on an included module, so your class
|
48
|
-
# can just redefine them and call `super`, if you need to.
|
49
|
-
# http://thepugautomatic.com/2013/07/dsom/
|
50
|
-
unless klass.const_defined?(INSTANCE_METHODS_MODULE_NAME, _search_ancestors = false)
|
51
|
-
klass.send :include, klass.const_set(INSTANCE_METHODS_MODULE_NAME, Module.new)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def add_attributes(attributes, options)
|
56
|
-
fallback = options.fetch(:fallback, true)
|
57
|
-
|
58
|
-
klass.translatable_attributes |= attributes
|
59
|
-
|
60
|
-
attributes.each do |attribute|
|
61
|
-
define_localized_reader attribute, :fallback => fallback
|
62
|
-
define_localized_writer attribute
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def define_localized_reader(attribute, options)
|
67
|
-
fallback = options[:fallback]
|
68
|
-
|
69
|
-
custom_define_method(attribute) do
|
70
|
-
@localized_readers ||= {}
|
71
|
-
@localized_readers[attribute] ||= Traco::LocalizedReader.new(self, attribute, :fallback => fallback)
|
72
|
-
@localized_readers[attribute].value
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def define_localized_writer(attribute)
|
77
|
-
custom_define_method("#{attribute}=") do |value|
|
78
|
-
send("#{attribute}_#{I18n.locale}=", value)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def custom_define_method(name, &block)
|
83
|
-
klass.const_get(INSTANCE_METHODS_MODULE_NAME).module_eval do
|
84
|
-
define_method(name, &block)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def klass
|
89
|
-
@klass
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/lib/traco/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
2
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
3
|
-
config.filter_run :
|
3
|
+
config.filter_run focus: true
|
4
4
|
config.run_all_when_everything_filtered = true
|
5
5
|
|
6
6
|
# Clear class state before each spec.
|
@@ -18,13 +18,13 @@ end
|
|
18
18
|
require "active_record"
|
19
19
|
require "app/post.rb"
|
20
20
|
|
21
|
-
ActiveRecord::Base.establish_connection :
|
21
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
22
22
|
|
23
23
|
silence_stream(STDOUT) do
|
24
|
-
ActiveRecord::Schema.define(:
|
25
|
-
create_table :posts, :
|
26
|
-
t.string :title_sv, :title_en, :
|
27
|
-
t.string :body_sv, :body_en, :
|
24
|
+
ActiveRecord::Schema.define(version: 0) do
|
25
|
+
create_table :posts, force: true do |t|
|
26
|
+
t.string :title_sv, :title_en, :title_pt_br
|
27
|
+
t.string :body_sv, :body_en, :body_pt_br
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/spec/traco_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "traco"
|
3
5
|
|
@@ -44,9 +46,9 @@ describe Post, ".locales_for_attribute" do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
it "lists the locales, default first and then alphabetically" do
|
47
|
-
I18n.default_locale = :
|
49
|
+
I18n.default_locale = :"pt-BR"
|
48
50
|
Post.locales_for_attribute(:title).should == [
|
49
|
-
:
|
51
|
+
:pt_br, :en, :sv
|
50
52
|
]
|
51
53
|
end
|
52
54
|
end
|
@@ -54,27 +56,27 @@ end
|
|
54
56
|
describe Post, ".locale_columns" do
|
55
57
|
before do
|
56
58
|
Post.translates :title
|
57
|
-
I18n.default_locale = :
|
59
|
+
I18n.default_locale = :"pt-BR"
|
58
60
|
end
|
59
61
|
|
60
62
|
it "lists the columns-with-locale for that attribute, default locale first and then alphabetically" do
|
61
63
|
Post.locale_columns(:title).should == [
|
62
|
-
:
|
64
|
+
:title_pt_br, :title_en, :title_sv
|
63
65
|
]
|
64
66
|
end
|
65
67
|
|
66
68
|
it "supports multiple attributes" do
|
67
69
|
Post.translates :body
|
68
70
|
Post.locale_columns(:body, :title).should == [
|
69
|
-
:
|
70
|
-
:
|
71
|
+
:body_pt_br, :body_en, :body_sv,
|
72
|
+
:title_pt_br, :title_en, :title_sv
|
71
73
|
]
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
75
77
|
describe Post, "#title" do
|
76
78
|
let(:post) {
|
77
|
-
Post.new(:
|
79
|
+
Post.new(title_sv: "Hej", title_en: "Halloa", title_pt_br: "Olá")
|
78
80
|
}
|
79
81
|
|
80
82
|
before do
|
@@ -87,6 +89,12 @@ describe Post, "#title" do
|
|
87
89
|
post.title.should == "Hej"
|
88
90
|
end
|
89
91
|
|
92
|
+
it "handles dashed locales" do
|
93
|
+
I18n.locale = :"pt-BR"
|
94
|
+
post.title_pt_br.should == "Olá"
|
95
|
+
post.title.should == "Olá"
|
96
|
+
end
|
97
|
+
|
90
98
|
it "falls back to the default locale if locale has no column" do
|
91
99
|
I18n.locale = :ru
|
92
100
|
post.title.should == "Halloa"
|
@@ -106,7 +114,7 @@ describe Post, "#title" do
|
|
106
114
|
it "returns nil if all are blank" do
|
107
115
|
post.title_sv = " "
|
108
116
|
post.title_en = ""
|
109
|
-
post.
|
117
|
+
post.title_pt_br = nil
|
110
118
|
post.title.should be_nil
|
111
119
|
end
|
112
120
|
|
@@ -128,14 +136,22 @@ describe Post, "#title" do
|
|
128
136
|
post.title.should == "title"
|
129
137
|
post.body.should == "body"
|
130
138
|
end
|
139
|
+
|
140
|
+
it "reflects locale change" do
|
141
|
+
post.title.should == "Hej"
|
142
|
+
I18n.locale = :en
|
143
|
+
post.title.should == "Halloa"
|
144
|
+
I18n.locale = :sv
|
145
|
+
post.title.should == "Hej"
|
146
|
+
end
|
131
147
|
|
132
|
-
context "with :
|
148
|
+
context "with fallback: false" do
|
133
149
|
let(:post) {
|
134
|
-
Post.new(:
|
150
|
+
Post.new(title_sv: "Hej", title_en: "Halloa")
|
135
151
|
}
|
136
152
|
|
137
153
|
before do
|
138
|
-
Post.translates :title, :
|
154
|
+
Post.translates :title, fallback: false
|
139
155
|
I18n.default_locale = :en
|
140
156
|
end
|
141
157
|
|
@@ -155,17 +171,22 @@ end
|
|
155
171
|
describe Post, "#title=" do
|
156
172
|
before do
|
157
173
|
Post.translates :title
|
158
|
-
I18n.locale = :sv
|
159
174
|
end
|
160
175
|
|
161
176
|
let(:post) { Post.new }
|
162
177
|
|
163
178
|
it "assigns in the current locale" do
|
179
|
+
I18n.locale = :sv
|
164
180
|
post.title = "Hej"
|
165
|
-
post.title.should == "Hej"
|
166
181
|
post.title_sv.should == "Hej"
|
167
182
|
end
|
168
183
|
|
184
|
+
it "handles dashed locales" do
|
185
|
+
I18n.locale = :"pt-BR"
|
186
|
+
post.title = "Olá"
|
187
|
+
post.title_pt_br.should == "Olá"
|
188
|
+
end
|
189
|
+
|
169
190
|
it "raises if locale has no column" do
|
170
191
|
I18n.locale = :ru
|
171
192
|
lambda {
|
@@ -180,33 +201,33 @@ describe Post, ".human_attribute_name" do
|
|
180
201
|
I18n.locale = :sv
|
181
202
|
end
|
182
203
|
|
183
|
-
it "
|
184
|
-
Post.human_attribute_name(:
|
204
|
+
it "uses explicit translations if present" do
|
205
|
+
Post.human_attribute_name(:title_sv).should == "Svensk titel"
|
185
206
|
end
|
186
207
|
|
187
|
-
it "
|
188
|
-
Post.human_attribute_name(:
|
208
|
+
it "appends translated language name if present" do
|
209
|
+
Post.human_attribute_name(:title_en).should == "Titel (engelska)"
|
189
210
|
end
|
190
211
|
|
191
|
-
it "
|
192
|
-
Post.human_attribute_name(:
|
212
|
+
it "appends an abbreviation when language name is not translated" do
|
213
|
+
Post.human_attribute_name(:title_pt_br).should == "Titel (PT-BR)"
|
193
214
|
end
|
194
215
|
|
195
|
-
it "passes through the default behavior" do
|
216
|
+
it "passes through the default behavior for untranslated attributes" do
|
196
217
|
Post.human_attribute_name(:title).should == "Titel"
|
197
218
|
end
|
198
219
|
|
199
|
-
it "passes through untranslated
|
220
|
+
it "passes through untranslated attributes even if the name suggests it's translated" do
|
200
221
|
Post.human_attribute_name(:body_sv).should == "Body sv"
|
201
222
|
end
|
202
223
|
|
203
224
|
# ActiveModel::Errors#full_messages passes in an ugly default.
|
204
225
|
|
205
|
-
it "does not
|
206
|
-
Post.human_attribute_name(:title_en, :
|
226
|
+
it "does not honor passed-in defaults for locale columns" do
|
227
|
+
Post.human_attribute_name(:title_en, default: "Title en").should == "Titel (engelska)"
|
207
228
|
end
|
208
229
|
|
209
230
|
it "passes through defaults" do
|
210
|
-
Post.human_attribute_name(:body_sv, :
|
231
|
+
Post.human_attribute_name(:body_sv, default: "Boday").should == "Boday"
|
211
232
|
end
|
212
233
|
end
|
data/traco.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -75,38 +75,6 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: guard
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: guard-rspec
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
78
|
description:
|
111
79
|
email:
|
112
80
|
- henrik@barsoom.se
|
@@ -117,11 +85,12 @@ files:
|
|
117
85
|
- .gitignore
|
118
86
|
- .rvmrc
|
119
87
|
- .travis.yml
|
88
|
+
- CHANGELOG.md
|
120
89
|
- Gemfile
|
121
|
-
-
|
122
|
-
- README.markdown
|
90
|
+
- README.md
|
123
91
|
- Rakefile
|
124
92
|
- lib/traco.rb
|
93
|
+
- lib/traco/attribute_setup.rb
|
125
94
|
- lib/traco/class_methods.rb
|
126
95
|
- lib/traco/localized_reader.rb
|
127
96
|
- lib/traco/translates.rb
|
@@ -145,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
114
|
version: '0'
|
146
115
|
segments:
|
147
116
|
- 0
|
148
|
-
hash: -
|
117
|
+
hash: -4140218999015648570
|
149
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
119
|
none: false
|
151
120
|
requirements:
|
@@ -154,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
123
|
version: '0'
|
155
124
|
segments:
|
156
125
|
- 0
|
157
|
-
hash: -
|
126
|
+
hash: -4140218999015648570
|
158
127
|
requirements: []
|
159
128
|
rubyforge_project:
|
160
129
|
rubygems_version: 1.8.24
|