Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Mar 23, 2020
2 parents 133da16 + d3fa52b commit 915c7e1
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 52 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 30 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,20 +22,20 @@ 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)
ethon (0.12.0)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -290,7 +290,6 @@ DEPENDENCIES
rake
rubocop (~> 0.75.0)
rubocop-performance (~> 1.5.0)
rubyzip (>= 1.3.0)
simplecov

BUNDLED WITH
Expand Down
2 changes: 1 addition & 1 deletion lib/config/pagy.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/javascripts/pagy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/locales/pt-br.yml → lib/locales/pt-BR.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
23 changes: 23 additions & 0 deletions lib/locales/sv-SE.yml
Original file line number Diff line number Diff line change
@@ -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: "&lsaquo;&nbsp;Föregående"
next: "Nästa&nbsp;&rsaquo;"
gap: "&hellip;"

info:
no_items: "Inga %{item_name} hittade"
single_page: "Visar <b>%{count}</b> %{item_name}"
multiple_pages: "Visar %{item_name} <b>%{from}-%{to}</b> av <b>%{count}</b> totalt"

combo_nav_js: "Sida %{page_input} av %{pages}"

items_selector_js: "Visa %{items_input} %{item_name} per sida"
2 changes: 1 addition & 1 deletion lib/locales/se.yml → lib/locales/sv.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 12 additions & 5 deletions lib/locales/utils/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/locales/utils/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions lib/locales/utils/p11n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions test/pagy/frontend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"<nav class=\"pagy-nav pagination\" role=\"navigation\" aria-label=\"pager\"><span class=\"page prev\"><a href=\"/foo?page=2\" rel=\"prev\" aria-label=\"previous\">&lsaquo;&nbsp;Prev</a></span> <span class=\"page\"><a href=\"/foo?page=1\" >1</a></span> <span class=\"page\"><a href=\"/foo?page=2\" rel=\"prev\" >2</a></span> <span class=\"page active\">3</span> <span class=\"page\"><a href=\"/foo?page=4\" rel=\"next\" >4</a></span> <span class=\"page\"><a href=\"/foo?page=5\" >5</a></span> <span class=\"page\"><a href=\"/foo?page=6\" >6</a></span> <span class=\"page next\"><a href=\"/foo?page=4\" rel=\"next\" aria-label=\"next\">Next&nbsp;&rsaquo;</a></span></nav>"
end


it 'renders page 6' do
pagy = Pagy.new count: 103, page: 6
_(view.pagy_nav(pagy)).must_equal \
Expand Down Expand Up @@ -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

Expand All @@ -125,6 +141,7 @@
_(view.pagy_info(Pagy.new count: 100, i18n_key: 'pagy.info.product', page: 3)).must_equal "Displaying Products <b>41-60</b> of <b>100</b> in total"
Pagy::I18n.load(locale: 'en') # reset for other tests
end

end

describe '#pagy_url_for' do
Expand Down

0 comments on commit 915c7e1

Please sign in to comment.