agilibox 1.5.4 → 1.5.5
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/app/models/concerns/agilibox/model_i18n.rb +32 -6
- data/lib/agilibox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0a7833192d2c2cdd413fcd91fbeea277099a5eed266af261f42c3b64584b65
|
4
|
+
data.tar.gz: be55f55b5c5bc7a7158db2a35742e946b823df0d1080d7f88572cf445d45a9b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c7162d24df15b7c2e64ab4c15426c17f0ef39f8fc87ec9a41faa90febcd96b105cecc13662cbaf720b320b59a685897dc7d45555c650bd9034645151b3607c5
|
7
|
+
data.tar.gz: af43c646d359fefa89e3d9cd9212fe61e6cc33ed555a133150ffa138551347944fd1fdb4ef1bb255eda1b35d95c507f10822b1900bb0f4fee6a37c50823f7d72
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Agilibox::ModelI18n
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
+
MissingTranslationError = Class.new(StandardError)
|
5
|
+
class << self
|
6
|
+
attr_accessor :raise_on_missing_translations
|
7
|
+
end
|
8
|
+
self.raise_on_missing_translations = false
|
9
|
+
|
4
10
|
def t(*args)
|
5
11
|
self.class.t(*args)
|
6
12
|
end
|
@@ -15,16 +21,36 @@ module Agilibox::ModelI18n
|
|
15
21
|
end
|
16
22
|
|
17
23
|
class_methods do
|
18
|
-
def t(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
def t(attribute = nil, options = {})
|
25
|
+
should_raise = Agilibox::ModelI18n.raise_on_missing_translations
|
26
|
+
exception_class = Agilibox::ModelI18n::MissingTranslationError
|
27
|
+
|
28
|
+
if should_raise
|
29
|
+
options = options.merge(default: "")
|
30
|
+
end
|
31
|
+
|
32
|
+
if should_raise && attribute.nil?
|
33
|
+
human = model_name.human(options)
|
34
|
+
type = options[:count].to_i > 1 ? "plural" : "singular"
|
35
|
+
raise exception_class, "translation missing: #{self} #{type} model name" if human.blank?
|
36
|
+
return human
|
23
37
|
end
|
38
|
+
|
39
|
+
if should_raise && attribute
|
40
|
+
human = human_attribute_name(attribute, options)
|
41
|
+
raise exception_class, "translation missing: #{self}##{attribute}" if human.blank?
|
42
|
+
return human
|
43
|
+
end
|
44
|
+
|
45
|
+
if attribute.nil?
|
46
|
+
return model_name.human(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
human_attribute_name(attribute, options) if attribute
|
24
50
|
end
|
25
51
|
|
26
52
|
def ts
|
27
|
-
|
53
|
+
t(nil, count: 2)
|
28
54
|
end
|
29
55
|
end # class_methods
|
30
56
|
end # Agilibox::ModelI18n
|
data/lib/agilibox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agilibox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agilidée
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails-i18n
|