agilibox 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1e2ec00d9a41c00749d3cb21f37eba75ed8d295deba5a6734b793a579c5a7be
4
- data.tar.gz: 457451658386f627c225d89d2060b6cc69a63ff3421ff039ae184722cbac9d78
3
+ metadata.gz: 3d0a7833192d2c2cdd413fcd91fbeea277099a5eed266af261f42c3b64584b65
4
+ data.tar.gz: be55f55b5c5bc7a7158db2a35742e946b823df0d1080d7f88572cf445d45a9b5
5
5
  SHA512:
6
- metadata.gz: 3a4d2774be4df2daf2434d7caee2191d220dae84d4b9db20e856ba1a8155ea62d50ff8ac121b9bd97439cc7636d9f72af815af2980c98af76a61094a2bd6a172
7
- data.tar.gz: 42ba2148fd0ff7b5d4e533fe45cac01524e11e889323cdb63526f623a54ef6d139021ce89206aca1a4c4eb51856d98567e11c6f00be79e2dce1284cd517fb512
6
+ metadata.gz: 9c7162d24df15b7c2e64ab4c15426c17f0ef39f8fc87ec9a41faa90febcd96b105cecc13662cbaf720b320b59a685897dc7d45555c650bd9034645151b3607c5
7
+ data.tar.gz: af43c646d359fefa89e3d9cd9212fe61e6cc33ed555a133150ffa138551347944fd1fdb4ef1bb255eda1b35d95c507f10822b1900bb0f4fee6a37c50823f7d72
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 1.5.5
6
+ - Add ModelI18n::raise_on_missing_translations option
7
+
5
8
  ## 1.5.4
6
9
  - Cucumber "click on" steps improvement
7
10
 
@@ -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(*args)
19
- if args.any?
20
- human_attribute_name(*args)
21
- else
22
- model_name.human
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
- model_name.human(count: 2)
53
+ t(nil, count: 2)
28
54
  end
29
55
  end # class_methods
30
56
  end # Agilibox::ModelI18n
@@ -1,3 +1,3 @@
1
1
  module Agilibox
2
- VERSION = "1.5.4"
2
+ VERSION = "1.5.5"
3
3
  end
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
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-03 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails-i18n