From 00bd31288ca854d422a741edc1d1ba500958b76e Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Mon, 2 Mar 2020 10:47:43 +0700 Subject: [PATCH 1/7] bundle update (closes #208, closes #223, closes #224) --- Gemfile | 1 - Gemfile.lock | 61 ++++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Gemfile b/Gemfile index 931c21996..315aaf987 100644 --- a/Gemfile +++ b/Gemfile @@ -26,5 +26,4 @@ gem 'codecov', :require => false # gem 'memory_profiler' # docs server -gem "rubyzip", ">= 1.3.0" gem "github-pages", '198', group: :jekyll_plugins diff --git a/Gemfile.lock b/Gemfile.lock index 7221c271a..a880fb7c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,12 +6,12 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) ansi (1.5.0) ast (2.4.0) - builder (3.2.3) - codecov (0.1.14) + builder (3.2.4) + codecov (0.1.16) json simplecov url @@ -22,10 +22,10 @@ GEM colorator (1.1.0) commonmarker (0.17.13) ruby-enum (~> 0.5) - concurrent-ruby (1.1.5) + concurrent-ruby (1.1.6) dnsruby (1.61.3) addressable (~> 2.5) - docile (1.3.1) + docile (1.3.2) em-websocket (0.5.1) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) @@ -33,9 +33,9 @@ GEM ffi (>= 1.3.0) eventmachine (1.2.7) execjs (2.7.0) - faraday (0.15.4) + faraday (1.0.0) multipart-post (>= 1.2, < 3) - ffi (1.11.1) + ffi (1.12.2) forwardable-extended (2.6.0) gemoji (3.0.1) github-pages (198) @@ -89,13 +89,13 @@ GEM octokit (~> 4.0) public_suffix (~> 3.0) typhoeus (~> 1.3) - html-pipeline (2.12.0) + html-pipeline (2.12.3) activesupport (>= 2) nokogiri (>= 1.4) http_parser.rb (0.6.0) i18n (0.9.5) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.3) + jaro_winkler (1.5.4) jekyll (3.8.5) addressable (~> 2.4) colorator (~> 1.0) @@ -200,7 +200,7 @@ GEM gemoji (~> 3.0) html-pipeline (~> 2.2) jekyll (~> 3.0) - json (2.2.0) + json (2.3.0) kramdown (1.17.0) liquid (4.0.0) listen (3.1.5) @@ -213,45 +213,46 @@ GEM jekyll (~> 3.5) jekyll-feed (~> 0.9) jekyll-seo-tag (~> 2.1) - minitest (5.12.2) - minitest-reporters (1.4.0) + minitest (5.14.0) + minitest-reporters (1.4.2) ansi builder minitest (>= 5.0) ruby-progressbar multipart-post (2.1.1) - nokogiri (1.10.4) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) - octokit (4.14.0) + octokit (4.16.0) + faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) - oj (3.7.12) - parallel (1.18.0) - parser (2.6.5.0) + oj (3.10.3) + parallel (1.19.1) + parser (2.7.0.3) ast (~> 2.4.0) pathutil (0.16.2) forwardable-extended (~> 2.6) public_suffix (3.1.1) - rack (2.0.7) + rack (2.2.2) rainbow (3.0.0) - rake (12.3.2) + rake (13.0.1) rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rb-inotify (0.10.1) ffi (~> 1.0) rouge (2.2.1) - rubocop (0.75.0) + rubocop (0.75.1) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.5.0) + rubocop-performance (1.5.2) rubocop (>= 0.71.0) ruby-enum (0.7.2) i18n ruby-progressbar (1.10.1) ruby_dep (1.5.0) - rubyzip (2.0.0) + rubyzip (2.2.0) safe_yaml (1.0.5) sass (3.7.4) sass-listen (~> 4.0.0) @@ -261,19 +262,18 @@ GEM sawyer (0.8.2) addressable (>= 2.3.5) faraday (> 0.8, < 2.0) - simplecov (0.16.1) + simplecov (0.18.5) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov-html (0.12.2) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) thread_safe (0.3.6) typhoeus (1.3.1) ethon (>= 0.9.0) - tzinfo (1.2.5) + tzinfo (1.2.6) thread_safe (~> 0.1) - unicode-display_width (1.6.0) + unicode-display_width (1.6.1) url (0.3.2) PLATFORMS @@ -290,7 +290,6 @@ DEPENDENCIES rake rubocop (~> 0.75.0) rubocop-performance (~> 1.5.0) - rubyzip (>= 1.3.0) simplecov BUNDLED WITH From 6a31db64e979e46c5245d9afd037bffc430dd19d Mon Sep 17 00:00:00 2001 From: David Wessman Date: Fri, 20 Mar 2020 06:35:17 +0100 Subject: [PATCH 2/7] Swedish locale: add sv-SE, rename se -> sv (#226) - The Swedish locale is referred to as sv in the I18n-gem: https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/sv.yml - It can also be referred to as sv-SE. --- lib/locales/sv-SE.yml | 23 +++++++++++++++++++++++ lib/locales/{se.yml => sv.yml} | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/locales/sv-SE.yml rename lib/locales/{se.yml => sv.yml} (99%) diff --git a/lib/locales/sv-SE.yml b/lib/locales/sv-SE.yml new file mode 100644 index 000000000..87d69ea93 --- /dev/null +++ b/lib/locales/sv-SE.yml @@ -0,0 +1,23 @@ +# :one_two_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) + +sv-SE: + pagy: + + item_name: + one: "resultat" + two: "resultat" + other: "resultat" + + nav: + prev: "‹ Föregående" + next: "Nästa ›" + gap: "…" + + info: + no_items: "Inga %{item_name} hittade" + single_page: "Visar %{count} %{item_name}" + multiple_pages: "Visar %{item_name} %{from}-%{to} av %{count} totalt" + + combo_nav_js: "Sida %{page_input} av %{pages}" + + items_selector_js: "Visa %{items_input} %{item_name} per sida" diff --git a/lib/locales/se.yml b/lib/locales/sv.yml similarity index 99% rename from lib/locales/se.yml rename to lib/locales/sv.yml index f6cc749c3..86da347e0 100644 --- a/lib/locales/se.yml +++ b/lib/locales/sv.yml @@ -1,6 +1,6 @@ # :one_two_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) -se: +sv: pagy: item_name: From a77dfcf04f352d4650468f02af34f7326d699ab2 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Fri, 20 Mar 2020 12:39:07 +0700 Subject: [PATCH 3/7] fix for sv and sv-SE pluralization --- lib/locales/utils/p11n.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/locales/utils/p11n.rb b/lib/locales/utils/p11n.rb index e6ad4ccb0..ad5d8c150 100644 --- a/lib/locales/utils/p11n.rb +++ b/lib/locales/utils/p11n.rb @@ -60,14 +60,15 @@ # The default pluralization for locales not explicitly listed here # is the :one_other pluralization proc (used for English) plurals = Hash.new(p11n[:one_other]).tap do |hash| - hash['id'] = p11n[:other] - hash['fr'] = p11n[:one_upto_two_other] - hash['ja'] = p11n[:other] - hash['ko'] = p11n[:other] - hash['pl'] = p11n[:polish] - hash['ru'] = p11n[:east_slavic] - hash['se'] = p11n[:one_two_other] - hash['tr'] = p11n[:other] + hash['id'] = p11n[:other] + hash['fr'] = p11n[:one_upto_two_other] + hash['ja'] = p11n[:other] + hash['ko'] = p11n[:other] + hash['pl'] = p11n[:polish] + hash['ru'] = p11n[:east_slavic] + hash['sv'] = p11n[:one_two_other] + hash['sv-SE'] = p11n[:one_two_other] + hash['tr'] = p11n[:other] hash['zh-CN'] = p11n[:other] hash['zh-HK'] = p11n[:other] hash['zh-TW'] = p11n[:other] From e1bd70c38b8c8d8c7b1e24c1cd459885dc90b3c2 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Fri, 20 Mar 2020 12:41:09 +0700 Subject: [PATCH 4/7] renamed pt-br -> pt-BR --- lib/locales/{pt-br.yml => pt-BR.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename lib/locales/{pt-br.yml => pt-BR.yml} (98%) diff --git a/lib/locales/pt-br.yml b/lib/locales/pt-BR.yml similarity index 98% rename from lib/locales/pt-br.yml rename to lib/locales/pt-BR.yml index e9de41967..0638a22da 100644 --- a/lib/locales/pt-br.yml +++ b/lib/locales/pt-BR.yml @@ -1,6 +1,6 @@ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) -pt-br: +pt-BR: pagy: item_name: From ebd6151e73b3ccd8441d71463b0a0664129b56f1 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Fri, 20 Mar 2020 12:42:10 +0700 Subject: [PATCH 5/7] added deprecation remapping --- lib/locales/utils/i18n.rb | 17 ++++++++++++----- lib/locales/utils/loader.rb | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/locales/utils/i18n.rb b/lib/locales/utils/i18n.rb index 0b5e35ad7..0ebead539 100644 --- a/lib/locales/utils/i18n.rb +++ b/lib/locales/utils/i18n.rb @@ -4,15 +4,22 @@ # this file returns the I18n hash used as default alternative to the i18n gem -Hash.new{|h,_| h.first[1]}.tap do |i18n| # first loaded locale used as default - i18n.define_singleton_method(:load) do |*args| +Pagy::DEPRECATED_LOCALES = {'pt-br' =>'pt-BR', 'se' => 'sv-SE'} + +Hash.new{|h,_| h.first[1]}.tap do |i18n_hash| # first loaded locale used as default + i18n_hash.define_singleton_method(:load) do |*load_args| # eval: we don't need to keep the loader proc in memory - eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(i18n, *args) #rubocop:disable Security/Eval + eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(i18n_hash, *load_args) #rubocop:disable Security/Eval end - i18n.define_singleton_method(:t) do |locale, path, vars={}| + i18n_hash.define_singleton_method(:t) do |locale, path, vars={}| + if Pagy::DEPRECATED_LOCALES.key?(locale) + new_locale = Pagy::DEPRECATED_LOCALES[locale] + $stderr.puts("WARNING: the Pagy locale '#{locale}' is deprecated; use '#{new_locale}' instead") + locale = new_locale + end data, pluralize = self[locale] translate = data[path] || vars[:count] && data[path+=".#{pluralize.call(vars[:count])}"] or return %([translation missing: "#{path}"]) translate.call(vars) end - i18n.load(locale: 'en') + i18n_hash.load(locale: 'en') end diff --git a/lib/locales/utils/loader.rb b/lib/locales/utils/loader.rb index 942dfb827..a74e0f34b 100644 --- a/lib/locales/utils/loader.rb +++ b/lib/locales/utils/loader.rb @@ -20,6 +20,11 @@ lambda do |i18n, *args| i18n.clear args.each do |arg| + if Pagy::DEPRECATED_LOCALES.key?(arg[:locale]) + new_locale = Pagy::DEPRECATED_LOCALES[arg[:locale]] + $stderr.puts("WARNING: the Pagy locale '#{arg[:locale]}' is deprecated; use '#{new_locale}' instead") + arg[:locale] = new_locale + end arg[:filepath] ||= Pagy.root.join('locales', "#{arg[:locale]}.yml") arg[:pluralize] ||= plurals[arg[:locale]] hash = YAML.load(File.read(arg[:filepath], encoding: 'UTF-8')) #rubocop:disable Security/YAMLLoad From 032615ce9f3683376d2b5615185edd7d98744ed4 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sun, 22 Mar 2020 15:41:58 +0700 Subject: [PATCH 6/7] added Pagy::I18n deprecation tests --- test/pagy/frontend_test.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/pagy/frontend_test.rb b/test/pagy/frontend_test.rb index 72af9a9a8..1fd752362 100644 --- a/test/pagy/frontend_test.rb +++ b/test/pagy/frontend_test.rb @@ -21,7 +21,6 @@ "" end - it 'renders page 6' do pagy = Pagy.new count: 103, page: 6 _(view.pagy_nav(pagy)).must_equal \ @@ -101,7 +100,24 @@ _(view.pagy_t('pagy.item_name', count: 1)).must_equal "Eintrag" view.instance_variable_set(:'@pagy_locale', 'unknown') _(view.pagy_t('pagy.item_name', count: 1)).must_equal "Eintrag" # silently serves the first loaded locale - Pagy::I18n.load(locale: 'en') # reset for other tests + Pagy::I18n.load(locale: 'en') # reset for other tests + view.instance_variable_set(:'@pagy_locale', nil) # reset for other tests + end + + end + + describe "Pagy::I18n deprecation" do + + it 'handles deprecated locales' do + _(proc {Pagy::I18n.load({locale: 'se'}, {locale: 'pt-br'})}).must_output '', /^WARNING:/ + + view.instance_variable_set(:'@pagy_locale', 'se') + _(proc {view.pagy_t('pagy.item_name', count: 1).must_equal 'resultat'}).must_output '', /^WARNING:/ + + view.instance_variable_set(:'@pagy_locale', 'pt-br') + _(proc {view.pagy_t('pagy.item_name', count: 1).must_equal 'item'}).must_output '', /^WARNING:/ + + Pagy::I18n.load(locale: 'en') # reset for other tests view.instance_variable_set(:'@pagy_locale', nil) # reset for other tests end @@ -125,6 +141,7 @@ _(view.pagy_info(Pagy.new count: 100, i18n_key: 'pagy.info.product', page: 3)).must_equal "Displaying Products 41-60 of 100 in total" Pagy::I18n.load(locale: 'en') # reset for other tests end + end describe '#pagy_url_for' do From d3fa52bda6ad786b1ebb2dfa2fe050223afa6c5a Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Mon, 23 Mar 2020 08:32:32 +0700 Subject: [PATCH 7/7] version 3.7.4 --- CHANGELOG.md | 18 ++++++++++++++++++ lib/config/pagy.rb | 2 +- lib/javascripts/pagy.js | 2 +- lib/pagy.rb | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6ca1e4a7..35da1d6a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # CHANGELOG +## Version 3.7.4 + +### Changes + +- Locales normalization and deprecations +- Bundle update + +### Commits + +- [c424466](http://github.com/ddnexus/pagy/commit/c424466): Merge branch 'locales-normalization' into dev +- [032615c](http://github.com/ddnexus/pagy/commit/032615c): added Pagy::I18n deprecation tests +- [ebd6151](http://github.com/ddnexus/pagy/commit/ebd6151): added deprecation remapping +- [e1bd70c](http://github.com/ddnexus/pagy/commit/e1bd70c): renamed pt-br -> pt-BR +- [a77dfcf](http://github.com/ddnexus/pagy/commit/a77dfcf): fix for sv and sv-SE pluralization +- [6a31db6](http://github.com/ddnexus/pagy/commit/6a31db6): Swedish locale: add sv-SE, rename se -> sv (#226) +- [00bd312](http://github.com/ddnexus/pagy/commit/00bd312): bundle update (closes #208, closes #223, closes #224) +- [133da16](http://github.com/ddnexus/pagy/commit/133da16): Add tutorial link (#222) [ci skip] + ## Version 3.7.3 ### Commits diff --git a/lib/config/pagy.rb b/lib/config/pagy.rb index 26bd19fbc..9f5b2be9c 100644 --- a/lib/config/pagy.rb +++ b/lib/config/pagy.rb @@ -1,7 +1,7 @@ # encoding: utf-8 # frozen_string_literal: true -# Pagy initializer file (3.7.3) +# Pagy initializer file (3.7.4) # Customize only what you really need and notice that Pagy works also without any of the following lines. # Should you just cherry pick part of this file, please maintain the require-order of the extras diff --git a/lib/javascripts/pagy.js b/lib/javascripts/pagy.js index 658054e66..f2ccbd459 100644 --- a/lib/javascripts/pagy.js +++ b/lib/javascripts/pagy.js @@ -2,7 +2,7 @@ function Pagy(){} -Pagy.version = '3.7.3'; +Pagy.version = '3.7.4'; Pagy.init = function(arg){ var target = arg instanceof Event || arg === undefined ? document : arg, diff --git a/lib/pagy.rb b/lib/pagy.rb index c3cab78aa..ef9a926d2 100644 --- a/lib/pagy.rb +++ b/lib/pagy.rb @@ -4,7 +4,7 @@ require 'pathname' -class Pagy ; VERSION = '3.7.3' +class Pagy ; VERSION = '3.7.4' # Root pathname to get the path of Pagy files like templates or dictionaries def self.root; @root ||= Pathname.new(__FILE__).dirname.freeze end