File tree Expand file tree Collapse file tree 4 files changed +14
-3
lines changed
lib/awesome_jsonb_translate Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ This gem uses PostgreSQL's JSONB datatype and ActiveRecord models to translate m
10
10
11
11
## Features
12
12
13
- - [x] ` v0.1.2 ` It works
13
+ - [x] ` v0.1.3 ` Fix redundant fallbacks when translation is nil
14
14
15
15
## Requirements
16
16
@@ -71,10 +71,12 @@ It always falls back to default locale
71
71
# Behavior with fallbacks enabled
72
72
p = Page .new (title_en: ' English title' )
73
73
I18n .with_locale(:de ) { p .title } # => 'English title' (falls back to English)
74
+ p .title_de # => nil
74
75
75
76
# Behavior with empty string
76
77
p = Page .new (title_en: ' English title' , title_de: ' ' )
77
78
I18n .with_locale(:de ) { p .title } # => 'English title' (falls back since German is empty)
79
+ p .title_de # => ''
78
80
```
79
81
80
82
### Assigning a Hash Directly
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def define_translation_accessors(attr_name)
33
33
34
34
def define_translation_reader_for_locale ( attr_name , locale )
35
35
define_method ( "#{ attr_name } _#{ locale } " ) do
36
- read_translation ( attr_name , locale )
36
+ read_translation_without_fallback ( attr_name , locale )
37
37
end
38
38
end
39
39
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module AwesomeJsonbTranslate
4
- VERSION = '0.1.2 '
4
+ VERSION = '0.1.3 '
5
5
end
Original file line number Diff line number Diff line change @@ -80,6 +80,15 @@ class Page < ActiveRecord::Base
80
80
expect ( page . title ) . to eq ( 'English title' )
81
81
end
82
82
end
83
+
84
+ it 'does not fall back when translation is accessed directly' do
85
+ page = Page . new ( title_en : 'English title' , title_de : nil )
86
+
87
+ I18n . with_locale ( :de ) do
88
+ expect ( page . title_en ) . to eq ( 'English title' )
89
+ expect ( page . title_de ) . to be_nil
90
+ end
91
+ end
83
92
end
84
93
85
94
describe 'querying' do
You can’t perform that action at this time.
0 commit comments