traco 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/traco/class_methods.rb +4 -4
- data/lib/traco/version.rb +1 -1
- data/spec/spec_helper_models.rb +2 -2
- data/spec/traco_spec.rb +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 995b6c0b60252d02350da1d58e7ea0268a80a80b
|
4
|
+
data.tar.gz: 65c1db0ac8b1036daf10595d5c8745ccf2412aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f8fe7b9b21d2ea1ac651bf85d0eaa642e276533973347e8feb7248616632c764a1368a5670f8ee64d2afb519160cdbdec68a53ccb2c730e23c81330db3f657f
|
7
|
+
data.tar.gz: 448dff9dd08c1e8fb9c3d4dcfa57bf3fd4e66311ec84c66410fbaea44fac667fe7c8c1add591bb11b6a665648582dd6de59ce35aef604fe14d2a7e3d0444690b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 5.0.0
|
4
|
+
|
5
|
+
* Change `locale_columns` and `locales_for_attribute` to sort current locale first, then default locale (previously, it was default locale first). This makes more sense for our own apps, and hopefully other apps as well.
|
6
|
+
|
3
7
|
## 4.0.0
|
4
8
|
|
5
9
|
* Drop support for end-of-lifed Ruby 2.1 and 2.2.
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ You can still use your accessors like `title_sv` and `title_sv=` in forms, valid
|
|
52
52
|
|
53
53
|
`.translatable_attributes`: Returns an array like `[:title, :body]`.
|
54
54
|
|
55
|
-
`.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with
|
55
|
+
`.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with current locale first, then default locale, and then alphabetically. Suitable for looping in forms:
|
56
56
|
|
57
57
|
```erb
|
58
58
|
<% Post.locale_columns(:title).each do |column| %>
|
@@ -81,7 +81,7 @@ The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]
|
|
81
81
|
|
82
82
|
`.current_locale_column(:title)`: Returns `:title_sv` if `:sv` is the current locale. Suitable for some SQL queries, such as sorting.
|
83
83
|
|
84
|
-
`.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with
|
84
|
+
`.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with current locale first, then default locale, and then alphabetically.
|
85
85
|
|
86
86
|
And the equivalent methods for `body`, of course.
|
87
87
|
|
data/lib/traco/class_methods.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Traco
|
2
2
|
module ClassMethods
|
3
3
|
def locales_for_attribute(attribute)
|
4
|
-
traco_cache(attribute, fallback: LocaleFallbacks::
|
4
|
+
traco_cache(attribute, fallback: LocaleFallbacks::ANY_FALLBACK).keys
|
5
5
|
end
|
6
6
|
|
7
7
|
def locale_columns(*attributes)
|
8
|
-
attributes.
|
9
|
-
|
10
|
-
|
8
|
+
attributes.flat_map { |attribute|
|
9
|
+
_locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::ANY_FALLBACK)
|
10
|
+
}
|
11
11
|
end
|
12
12
|
|
13
13
|
# Consider this method internal.
|
data/lib/traco/version.rb
CHANGED
data/spec/spec_helper_models.rb
CHANGED
@@ -21,8 +21,8 @@ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
|
21
21
|
|
22
22
|
ActiveRecord::Schema.define(version: 0) do
|
23
23
|
create_table :posts, force: true do |t|
|
24
|
-
t.string :title_sv, :title_en, :title_pt_br
|
25
|
-
t.string :body_sv, :body_en, :body_pt_br
|
24
|
+
t.string :title_sv, :title_en, :title_pt_br, :title_de
|
25
|
+
t.string :body_sv, :body_en, :body_pt_br, :body_de
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/spec/traco_spec.rb
CHANGED
@@ -84,8 +84,8 @@ describe Post, ".locales_for_attribute" do
|
|
84
84
|
I18n.locale = :en
|
85
85
|
end
|
86
86
|
|
87
|
-
it "lists the locales for that attribute,
|
88
|
-
expect(Post.locales_for_attribute(:title)).to eq [ :"pt-BR", :
|
87
|
+
it "lists the locales for that attribute, current locale first, then default locale, and then alphabetically" do
|
88
|
+
expect(Post.locales_for_attribute(:title)).to eq [ :en, :"pt-BR", :de, :sv ]
|
89
89
|
end
|
90
90
|
|
91
91
|
it "doesn't include a locale if there's no corresponding column for it" do
|
@@ -102,9 +102,9 @@ describe Post, ".locale_columns" do
|
|
102
102
|
I18n.locale = :en
|
103
103
|
end
|
104
104
|
|
105
|
-
it "lists the columns-with-locale for that attribute,
|
105
|
+
it "lists the columns-with-locale for that attribute, current locale first, then default locale, and then alphabetically" do
|
106
106
|
expect(Post.locale_columns(:title)).to eq [
|
107
|
-
:title_pt_br, :
|
107
|
+
:title_en, :title_pt_br, :title_de, :title_sv,
|
108
108
|
]
|
109
109
|
end
|
110
110
|
|
@@ -114,12 +114,12 @@ describe Post, ".locale_columns" do
|
|
114
114
|
expect(Post.locale_columns(:title)).not_to include(:title_ru)
|
115
115
|
end
|
116
116
|
|
117
|
-
|
118
|
-
|
117
|
+
it "supports multiple attributes" do
|
118
|
+
Post.translates :body
|
119
119
|
|
120
120
|
expect(Post.locale_columns(:body, :title)).to eq [
|
121
|
-
:body_pt_br, :
|
122
|
-
:title_pt_br, :
|
121
|
+
:body_en, :body_pt_br, :body_de, :body_sv,
|
122
|
+
:title_en, :title_pt_br, :title_de, :title_sv,
|
123
123
|
]
|
124
124
|
end
|
125
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|