diff --git a/lib/locales/cs.yml b/lib/locales/cs.yml index f7593ea24..5b040bc38 100644 --- a/lib/locales/cs.yml +++ b/lib/locales/cs.yml @@ -1,4 +1,4 @@ -# :czech pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb) +# :west_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb) cs: pagy: diff --git a/lib/locales/sw.yml b/lib/locales/sw.yml index 49bf1f58c..ba7de4ae8 100644 --- a/lib/locales/sw.yml +++ b/lib/locales/sw.yml @@ -1,4 +1,4 @@ -# :one_other pluralization +# :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb) sw: pagy: diff --git a/lib/locales/vi.yml b/lib/locales/vi.yml index 4c1a288fb..840847752 100644 --- a/lib/locales/vi.yml +++ b/lib/locales/vi.yml @@ -1,4 +1,4 @@ -# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) +# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb) vi: pagy: diff --git a/test/pagy/i18n_locales_test.rb b/test/pagy/i18n_locales_test.rb new file mode 100644 index 000000000..faa6cff48 --- /dev/null +++ b/test/pagy/i18n_locales_test.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require_relative '../test_helper' + +describe 'pagy/locales' do + let(:rules) { Pagy::I18n::P11n::RULE.keys } + let(:counts) do + { + arabic: %w[zero one two few many other], + east_slavic: %w[one few many other], + one_other: %w[one other], + one_two_other: %w[one two other], + one_upto_two_other: %w[one other], + other: %w[other], + polish: %w[one few many other], + west_slavic: %w[one few other] + } + end + + # locale files loop + 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..-1].to_s.to_sym + + it 'includes a comment with the pluralization rule and the i18n.rb reference' do + _(rules).must_include rule, message + _(comment).must_match 'https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb', message + end + it 'defines and matches the locale pluralization rule' do + _(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'] + case item_name + when String + _(rule).must_equal :other + when Hash + _(item_name.keys - counts[rule]).must_be_empty + else + raise StandardError, "item_name must be Hash or String" + end + end + end +end