validation_hints 8.1.56 → 8.1.57

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9130f003f73cf1353979306ee5b8f691c39556db3cd3fc07132006320bbb5ab7
4
- data.tar.gz: c495d03625d531fefe0de1c45dfd4dc70bbfbdfeb8ece9e57c6fe02d57832ffc
3
+ metadata.gz: 64dcc61de84085cc1b5d5e13e9fdfbdac7b02b482608ee47f5c6ce3db52245c5
4
+ data.tar.gz: e4bf9918525ed479b863827fa9499a4fc0691d6c25e2b9ef225686b68ecba6f3
5
5
  SHA512:
6
- metadata.gz: 1043e8935871135a27af28ca8b35f3525bb105d6b18048c277457faff15aa1ef72ac1d6af2e50e1f4a7001a8667bb54ea2170f8bc1635e19e84c22df81c7a9d7
7
- data.tar.gz: 2121095b4511eed8c0ba0e49b989d6d4226a56904627422c1f5e529d910b2706169ac42ec54ae5160be1bda214d8c58b1465f84d509bd46206c689d22bf0f9e9
6
+ metadata.gz: c77ee68dc7eb5e216d60dacba2683994d5004df3a5ab7fb60326d4b412709fe52bf6a2bacc49ada6bad8c6930d2dbadbb78a32729347819f74f56ef824fbab25
7
+ data.tar.gz: f98d5e7fa38b3afbeabd7f8411fde3254094d6fbbb2e875d128ee41d47f2246bad47a9a231ca8697cc87a1e4146e144c87503a14cd92b80ad34b2faf69ea086c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project are documented here.
4
4
 
5
+ ## 8.1.57
6
+
7
+ ### Added
8
+
9
+ - **Dutch locale.** `lib/validation_hints/locale/nl.yml` has the same keys as `en.yml`, with the translations from StProject's `config/locales/validation_hints.nl.yml`. Every shipped locale file is loaded (`ValidationHints::LOCALE_PATHS`; `LOCALE_PATH` still names the en file), and a host's own locale files still win.
10
+
11
+ ### Fixed
12
+
13
+ - **`message: :required` hints were "Translation missing", even in en.** Every `belongs_to` (Rails adds `validates_presence_of …, message: :required`) is hinted as `presence.required`. The en file had `presence` only as a plain string, so that key could never exist. Like Rails' `errors.messages.required`, the lookup now falls back to `hints.messages.required` (and the `activerecord` / `activemodel` scopes) after the `presence.required` keys. en gets "must be chosen", nl "moet gekozen zijn". `presence` itself stays a plain string, so a host's `hints.messages.presence` override keeps working, and a host's `presence.required` key (StProject's nl file) still wins.
14
+
15
+ ### Tests
16
+
17
+ - `test/active_model/i18n_test.rb`:
18
+ - a `message: :required` presence hint resolves in en, and a `presence.required` key wins over the fallback;
19
+ - nl hints and full messages render;
20
+ - every shipped locale has exactly the keys of en.
21
+
22
+ ### Changed
23
+
24
+ - **Version numbering:** aligned with **inline_forms** / **inline_forms_installer** / **inline_forms_schema_edit** **8.1.57**. The companion release has security fixes and translations in inline_forms.
25
+
5
26
  ## 8.1.56
6
27
 
7
28
  ### Changed
@@ -218,6 +218,11 @@ module ActiveModel
218
218
  message_key = "#{key}.#{options[:message]}"
219
219
  generate_options = options.dup
220
220
  generate_options.delete(:message)
221
+ # Like Rails' errors.messages.required: `message: :required` (every
222
+ # belongs_to) also finds hints.messages.required when no
223
+ # "presence.required" key exists. `presence` itself stays a plain
224
+ # string, so overriding hints.messages.presence keeps working.
225
+ generate_options[:fallback_type] = options[:message]
221
226
  result << generate_message(attribute, message_key, generate_options)
222
227
  return result
223
228
  end
@@ -309,6 +314,11 @@ module ActiveModel
309
314
  defaults << :"activemodel.hints.messages.#{type}"
310
315
  defaults << :"hints.attributes.#{attribute_name}.#{type}"
311
316
  defaults << :"hints.messages.#{type}"
317
+ if (fallback = options[:fallback_type])
318
+ defaults << :"#{@base.class.i18n_scope}.hints.messages.#{fallback}" if @base.class.respond_to?(:i18n_scope)
319
+ defaults << :"activemodel.hints.messages.#{fallback}"
320
+ defaults << :"hints.messages.#{fallback}"
321
+ end
312
322
  defaults.compact.flatten
313
323
  end
314
324
 
@@ -26,6 +26,9 @@ en:
26
26
  confirmation: "doesn't match confirmation"
27
27
  acceptance: "must be accepted"
28
28
  presence: "can't be blank"
29
+ # `message: :required` (belongs_to): looked up as presence.required,
30
+ # then as required (see ActiveModel::Hints#i18n_defaults).
31
+ required: "must be chosen"
29
32
  money: "must be a valid amount"
30
33
  length:
31
34
  maximum: "must not be longer than %{count} characters"
@@ -0,0 +1,50 @@
1
+ ---
2
+ # Dutch, key for key the same as en.yml. Translations from StProject's
3
+ # config/locales/validation_hints.nl.yml (which keeps working next to this
4
+ # file; a host's own locale files load later and win).
5
+ nl:
6
+ activemodel:
7
+ hints:
8
+ format: "%{attribute} %{message}"
9
+
10
+ activerecord:
11
+ hints:
12
+ format: "%{attribute} %{message}"
13
+
14
+ hints:
15
+ format: "%{attribute} %{message}"
16
+
17
+ messages:
18
+ invalid: "is ongeldig"
19
+ blank: "moet ingevuld zijn"
20
+ empty: "moet ingevuld zijn"
21
+ inclusion:
22
+ in: "moet een van %{count} zijn"
23
+ exclusion:
24
+ in: "mag niet een van %{count} zijn"
25
+ format: "moet het vereiste formaat hebben"
26
+ email_format: "moet een geldig e-mailadres zijn"
27
+ associated: "is ongeldig"
28
+ uniqueness: "moet uniek zijn"
29
+ confirmation: "moet overeenkomen met de bevestiging"
30
+ acceptance: "moet geaccepteerd worden"
31
+ presence: "moet ingevuld zijn"
32
+ # `message: :required` (belongs_to): looked up as presence.required,
33
+ # then as required (see ActiveModel::Hints#i18n_defaults).
34
+ required: "moet gekozen zijn"
35
+ money: "moet een geldig bedrag zijn"
36
+ length:
37
+ maximum: "mag niet langer zijn dan %{count} tekens"
38
+ minimum: "mag niet korter zijn dan %{count} tekens"
39
+ is: "moet precies %{count} tekens lang zijn"
40
+ within: "moet tussen %{minimum} en %{maximum} tekens lang zijn"
41
+ numericality:
42
+ must_be_a_number: "moet een getal zijn"
43
+ only_integer: "moet een geheel getal zijn"
44
+ greater_than: "moet groter zijn dan %{count}"
45
+ greater_than_or_equal_to: "moet groter dan of gelijk aan %{count} zijn"
46
+ equal_to: "moet gelijk zijn aan %{count}"
47
+ less_than: "moet kleiner zijn dan %{count}"
48
+ less_than_or_equal_to: "moet kleiner dan of gelijk aan %{count} zijn"
49
+ odd: "moet oneven zijn"
50
+ even: "moet even zijn"
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module ValidationHints
4
- VERSION = "8.1.56"
4
+ VERSION = "8.1.57"
5
5
  end
@@ -5,12 +5,14 @@ require "active_model/hints"
5
5
 
6
6
  module ValidationHints
7
7
  LOCALE_PATH = File.expand_path("validation_hints/locale/en.yml", __dir__)
8
+ # Every shipped locale (en, nl). A host's own files load later and win.
9
+ LOCALE_PATHS = Dir[File.expand_path("validation_hints/locale/*.yml", __dir__)].sort.freeze
8
10
 
9
11
  def self.load_i18n!
10
12
  return if @i18n_loaded
11
13
 
12
14
  require "i18n"
13
- I18n.load_path << LOCALE_PATH unless I18n.load_path.include?(LOCALE_PATH)
15
+ LOCALE_PATHS.each { |path| I18n.load_path << path unless I18n.load_path.include?(path) }
14
16
  @i18n_loaded = true
15
17
  end
16
18
  end
@@ -2,6 +2,14 @@
2
2
 
3
3
  require "test_helper"
4
4
 
5
+ # `message: :required` is what every belongs_to declares (Rails adds
6
+ # validates_presence_of <assoc>, message: :required).
7
+ class RequiredCodePerson < ActiveRecord::Base
8
+ self.table_name = "people"
9
+
10
+ validates :code, presence: { message: :required }
11
+ end
12
+
5
13
  class ActiveModelHintsI18nTest < Minitest::Test
6
14
  def setup
7
15
  @person = Person.new
@@ -51,6 +59,38 @@ class ActiveModelHintsI18nTest < Minitest::Test
51
59
  assert_includes @person.hints[:name], "fill this in"
52
60
  end
53
61
 
62
+ # The en file had only a plain `presence` string, so "presence.required"
63
+ # (every belongs_to hint) rendered "Translation missing" even in en.
64
+ def test_required_message_resolves_in_en
65
+ assert_equal [ "must be chosen" ], RequiredCodePerson.new.hints[:code]
66
+ end
67
+
68
+ def test_required_message_prefers_a_presence_required_key
69
+ @kv.store_translations(:en, hints: { messages: { presence: { required: "pick one" } } })
70
+
71
+ assert_equal [ "pick one" ], RequiredCodePerson.new.hints[:code]
72
+ end
73
+
74
+ def test_nl_ships_with_the_gem
75
+ I18n.with_locale(:nl) do
76
+ assert_includes @person.hints[:name], "moet ingevuld zijn"
77
+ assert_equal [ "moet gekozen zijn" ], RequiredCodePerson.new.hints[:code]
78
+ assert_equal [ "Name moet ingevuld zijn" ], @person.hints.full_messages_for(:name)
79
+ end
80
+ end
81
+
82
+ def test_every_shipped_locale_has_the_keys_of_en
83
+ flatten = lambda do |hash, prefix = nil|
84
+ hash.flat_map { |key, value| value.is_a?(Hash) ? flatten.call(value, [ prefix, key ].compact.join(".")) : [ [ prefix, key ].compact.join(".") ] }
85
+ end
86
+ en_keys = flatten.call(YAML.load_file(ValidationHints::LOCALE_PATH)["en"]).sort
87
+ assert_operator ValidationHints::LOCALE_PATHS.size, :>=, 2
88
+ ValidationHints::LOCALE_PATHS.each do |path|
89
+ locale, translations = YAML.load_file(path).first
90
+ assert_equal en_keys, flatten.call(translations).sort, "#{locale} (#{File.basename(path)})"
91
+ end
92
+ end
93
+
54
94
  def test_full_message_uses_activerecord_human_attribute_name
55
95
  @kv.store_translations(:en, activerecord: { attributes: { person: { name: "Your name" } } })
56
96
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_hints
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.56
4
+ version: 8.1.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares
@@ -161,6 +161,7 @@ files:
161
161
  - lib/validation_hints.rb
162
162
  - lib/validation_hints/gem_build.rb
163
163
  - lib/validation_hints/locale/en.yml
164
+ - lib/validation_hints/locale/nl.yml
164
165
  - lib/validation_hints/railtie.rb
165
166
  - lib/validation_hints/validations_patch.rb
166
167
  - lib/validation_hints/version.rb