diff --git a/gem/locales/sw.yml b/gem/locales/sw.yml index 8d5135e45..6c2d90822 100644 --- a/gem/locales/sw.yml +++ b/gem/locales/sw.yml @@ -3,6 +3,8 @@ sw: pagy: # please add a comment in the https://github.com/ddnexus/pagy/issues/603 # posting the translation of the following "Page"/"Pages" with the plurals for this locale + # Please change the final test in 18n_loacles_test.rb to remove the sw.yml exclusion + # after you make these changes. aria_label: nav: "Pages" # one: "" diff --git a/gem/locales/ta.yml b/gem/locales/ta.yml index 7992c183f..bf65648ed 100644 --- a/gem/locales/ta.yml +++ b/gem/locales/ta.yml @@ -4,6 +4,8 @@ ta: aria_label: # please add a comment in the https://github.com/ddnexus/pagy/issues/604 # posting the translation of the following "Page"/"Pages" with the plurals for this locale + # Please change the final test in 18n_loacles_test.rb to remove the ta.yml exclusion + # after you make these changes. nav: "Pages" # one: "" # other: "" diff --git a/test/pagy/i18n_locales_test.rb b/test/pagy/i18n_locales_test.rb index 26b10128d..a1cd5dd02 100644 --- a/test/pagy/i18n_locales_test.rb +++ b/test/pagy/i18n_locales_test.rb @@ -21,10 +21,11 @@ Pagy.root.join('locales').each_child do |f| next unless f.extname == '.yml' - message = "locale file #{f}" - locale = f.basename.to_s[0..-5] - comment = f.readlines.first.to_s.strip - rule = comment.to_s.split[1][1..].to_s.to_sym + message = "locale file #{f}" + locale = f.basename.to_s[0..-5] # e.g. de + comment = f.readlines.first.to_s.strip # e.g. :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb) + rule = comment.to_s.split[1][1..].to_s.to_sym # e.g. one_other + language_yml = YAML.safe_load(f.read) it 'includes a comment with the pluralization rule and the i18n.rb reference' do _(rules).must_include rule, message @@ -34,8 +35,7 @@ _(Pagy::I18n::P11n::LOCALE[locale]).must_equal Pagy::I18n::P11n::RULE[rule], message end it 'pluralizes item_name according to the rule' do - hash = YAML.safe_load(f.read) - item_name = hash[locale]['pagy']['item_name'] + item_name = language_yml[locale]['pagy']['item_name'] case item_name when String _(rule).must_equal :other @@ -45,5 +45,21 @@ raise StandardError, "item_name must be Hash or String" end end + it "ensures #{locale}.yml has the correct aria_label,nav and item_name keys per the declared (#{rule}) rule" do + skip if %w[ta sw].include?(locale) # ta.yml and sw.yml do not have the requisite keys yet + + pluralizations = counts[rule] + + if rule == :other + # For the :other rules, we should not have any keys under the + # ['pagy']['item_name'] and ['pagy']['aria_label']['nav'] hierarchies. + # We should just have a String. + _(language_yml[locale]['pagy']['item_name']).must_be_instance_of(String) + _(language_yml[locale]['pagy']['aria_label']['nav']).must_be_instance_of(String) + else + _(language_yml[locale]['pagy']['item_name'].keys.sort).must_equal pluralizations.sort, "In #{message} - check that ['pagy']['item_name'] does not have keys inconsistent with #{rule}" + _(language_yml[locale]['pagy']['aria_label']['nav'].keys.sort).must_equal pluralizations.sort, "In #{message} - check that ['pagy']['aria_label']['nav'] does not have keys inconsistent with #{rule}" + end + end end end