|
| 1 | +# frozen_string_literal: true |
1 | 2 | require "test_helper" |
2 | 3 |
|
3 | 4 | class I18nTest < ActiveSupport::TestCase |
4 | 5 | I18n.available_locales.each do |locale| |
5 | | - test locale.to_s do |
6 | | - without_i18n_exceptions do |
7 | | - # plural_keys = plural_keys(locale) |
| 6 | + # OHM variant: upstream does not use the 'qqq' dummy language for documenting messages |
| 7 | + unless locale.to_s == 'qqq' |
| 8 | + test locale.to_s do |
| 9 | + without_i18n_exceptions do |
| 10 | + # plural_keys = plural_keys(locale) |
8 | 11 |
|
9 | | - translation_keys.each do |key| |
10 | | - variables = [] |
| 12 | + translation_keys.each do |key| |
| 13 | + variables = [] |
11 | 14 |
|
12 | | - default_value = I18n.t(key, :locale => I18n.default_locale) |
| 15 | + default_value = I18n.t(key, :locale => I18n.default_locale) |
13 | 16 |
|
14 | | - if default_value.is_a?(Hash) |
15 | | - variables.push("count") |
| 17 | + if default_value.is_a?(Hash) |
| 18 | + variables.push("count") |
16 | 19 |
|
17 | | - default_value.each_value do |subvalue| |
18 | | - subvalue.scan(/%\{(\w+)\}/) do |
| 20 | + default_value.each_value do |subvalue| |
| 21 | + subvalue.scan(/%\{(\w+)\}/) do |
| 22 | + variables.push(Regexp.last_match(1)) |
| 23 | + end |
| 24 | + end |
| 25 | + else |
| 26 | + default_value.scan(/%\{(\w+)\}/) do |
19 | 27 | variables.push(Regexp.last_match(1)) |
20 | 28 | end |
21 | 29 | end |
22 | | - else |
23 | | - default_value.scan(/%\{(\w+)\}/) do |
24 | | - variables.push(Regexp.last_match(1)) |
25 | | - end |
26 | | - end |
27 | 30 |
|
28 | | - variables.push("attribute") if key =~ /^(active(model|record)\.)?errors\./ |
| 31 | + variables.push("attribute") if key =~ /^(active(model|record)\.)?errors\./ |
29 | 32 |
|
30 | | - value = I18n.t(key, :locale => locale, :fallback => true) |
| 33 | + value = I18n.t(key, :locale => locale, :fallback => true) |
31 | 34 |
|
32 | | - if value.is_a?(Hash) |
33 | | - value.each do |subkey, subvalue| |
34 | | - # assert plural_keys.include?(subkey), "#{key}.#{subkey} is not a valid plural key" |
| 35 | + if value.is_a?(Hash) |
| 36 | + value.each do |subkey, subvalue| |
| 37 | + # assert plural_keys.include?(subkey), "#{key}.#{subkey} is not a valid plural key" |
35 | 38 |
|
36 | | - next if subvalue.nil? |
| 39 | + next if subvalue.nil? |
37 | 40 |
|
38 | | - subvalue.scan(/%\{(\w+)\}/) do |
39 | | - assert_includes variables, Regexp.last_match(1), "#{key}.#{subkey} uses unknown interpolation variable #{Regexp.last_match(1)}" |
| 41 | + subvalue.scan(/%\{(\w+)\}/) do |
| 42 | + assert_includes variables, Regexp.last_match(1), "#{key}.#{subkey} uses unknown interpolation variable #{Regexp.last_match(1)}" |
| 43 | + end |
40 | 44 | end |
41 | | - end |
42 | 45 |
|
43 | | - assert_includes value, :other, "#{key}.other plural key missing" |
44 | | - else |
45 | | - assert_kind_of String, value, "#{key} is not a string" |
| 46 | + assert_includes value, :other, "#{key}.other plural key missing" |
| 47 | + else |
| 48 | + assert_kind_of String, value, "#{key} is not a string" |
46 | 49 |
|
47 | | - value.scan(/%\{(\w+)\}/) do |
48 | | - assert_includes variables, Regexp.last_match(1), "#{key} uses unknown interpolation variable #{Regexp.last_match(1)}" |
| 50 | + value.scan(/%\{(\w+)\}/) do |
| 51 | + assert_includes variables, Regexp.last_match(1), "#{key} uses unknown interpolation variable #{Regexp.last_match(1)}" |
| 52 | + end |
49 | 53 | end |
50 | 54 | end |
51 | | - end |
52 | 55 |
|
53 | | - assert_includes %w[ltr rtl], I18n.t("html.dir", :locale => locale), "html.dir must be ltr or rtl" |
| 56 | + assert_includes %w[ltr rtl], I18n.t("html.dir", :locale => locale), "html.dir must be ltr or rtl" |
| 57 | + end |
54 | 58 | end |
55 | 59 | end |
56 | 60 | end |
|
0 commit comments