From 9d8063df7b5bfe124575e5ef2b253f2777e6bf33 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sun, 30 Sep 2018 17:47:30 +0700 Subject: [PATCH 1/8] version 0.20.0 --- lib/pagy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagy.rb b/lib/pagy.rb index 2a7b4029d..8e7fbc25e 100644 --- a/lib/pagy.rb +++ b/lib/pagy.rb @@ -3,7 +3,7 @@ require 'pathname' -class Pagy ; VERSION = '0.19.4' +class Pagy ; VERSION = '0.20.0' class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end From 15e413b8d515fc990889cc9078db8b285659f544 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sun, 30 Sep 2018 16:59:39 +0700 Subject: [PATCH 2/8] refactoring of the composition of i18n strings for compact helpers and items selector --- lib/locales/pagy.yml | 66 ++++++++++++----------------- lib/pagy/extras/bootstrap.rb | 2 +- lib/pagy/extras/bulma.rb | 4 +- lib/pagy/extras/foundation.rb | 4 +- lib/pagy/extras/items.rb | 2 +- lib/pagy/extras/materialize.rb | 2 +- lib/pagy/extras/navs.rb | 2 +- lib/pagy/extras/semantic.rb | 4 +- test/pagy/extras/bulma_test.rb | 6 +-- test/pagy/extras/foundation_test.rb | 6 +-- test/pagy/extras/semantic_test.rb | 6 +-- test/pagy/extras/trim_test.rb | 6 +-- 12 files changed, 48 insertions(+), 62 deletions(-) diff --git a/lib/locales/pagy.yml b/lib/locales/pagy.yml index f2db1b9a4..fa4f2acc9 100644 --- a/lib/locales/pagy.yml +++ b/lib/locales/pagy.yml @@ -17,12 +17,10 @@ en: zero: "items" one: "item" other: "items" - compact: - page: "Page" - of: "of" + compact: "Page %{page_input} of %{pages}" items: - show: "Show" - items: "items per page" + one: "Show %{items_input} item per page" + other: "Show %{items_input} items per page" es: pagy: nav: @@ -40,12 +38,10 @@ es: zero: "ítems" one: "ítem" other: "ítems" - compact: - page: "Página" - of: "de" + compact: "Página %{page_input} de %{pages}" items: - show: "Mostrar" - items: "ítems por página" + one: "Mostrar %{items_input} ítem por página" + other: "Mostrar %{items_input} ítems por página" id: pagy: nav: @@ -63,12 +59,10 @@ id: zero: "item" one: "item" other: "item" - compact: - page: "Halaman" - of: "dari" + compact: "Halaman %{page_input} dari %{pages}" items: - show: "Tampilkan" - items: "item per halaman" + one: "Tampilkan %{items_input} item per halaman" + other: "Tampilkan %{items_input} item per halaman" ja: pagy: nav: @@ -85,12 +79,10 @@ ja: zero: "結果" one: "結果" other: "結果" - compact: - page: "ページ" - of: "/" + compact: "ページ %{page_input} / %{pages}" items: - show: "" - items: "件ずつ表示" + one: "%{items_input} 件ずつ表示" + other: "%{items_input} 件ずつ表示" pt-br: pagy: nav: @@ -108,12 +100,10 @@ pt-br: zero: "itens" one: "item" other: "itens" - compact: - page: "Página" - of: "de" + compact: "Página %{page_input} de %{pages}" items: - show: "Mostrar" - items: "itens por página" + one: "Mostrar %{items_input} iten por página" + other: "Mostrar %{items_input} itens por página" ru: pagy: nav: @@ -134,12 +124,12 @@ ru: few: "записи" many: "записей" other: "записей" - compact: - page: "Страница" - of: "из" + compact: "Страница %{page_input} из %{pages}" items: - show: "Показать" - items: "записей на странице" + one: "Показать %{items_input} записей на странице" + few: "Показать %{items_input} записей на странице" + many: "Показать %{items_input} записей на странице" + other: "Показать %{items_input} записей на странице" tr: pagy: nav: @@ -156,12 +146,10 @@ tr: zero: "kayıt" one: "kayıt" other: "kayıt" - compact: - page: "Sayfa" - of: "/" + compact: "Sayfa %{page_input} / %{pages}" items: - show: "Göster" - items: "sayfa başı" + one: "Göster %{items_input} sayfa başı" + other: "Göster %{items_input} sayfa başı" zh-cn: pagy: nav: @@ -178,11 +166,9 @@ zh-cn: zero: "项目" one: "" other: "" - compact: - page: "页面" - of: "/" + compact: "页面 %{page_input} / %{pages}" items: - show: "每页显示" - items: "条" + one: "每页显示 %{items_input} 条" + other: "每页显示 %{items_input} 条" # PR for other languages are very welcome. Thanks! diff --git a/lib/pagy/extras/bootstrap.rb b/lib/pagy/extras/bootstrap.rb index 562caca75..4e7913f62 100644 --- a/lib/pagy/extras/bootstrap.rb +++ b/lib/pagy/extras/bootstrap.rb @@ -35,7 +35,7 @@ def pagy_nav_compact_bootstrap(pagy, id=caller(1,1)[0].hash) html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"') : %()) input = %() - html << %(
#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}
) + html << %(
#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}
) html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"') : %()) html << %() diff --git a/lib/pagy/extras/bulma.rb b/lib/pagy/extras/bulma.rb index ce764254d..d2731844f 100644 --- a/lib/pagy/extras/bulma.rb +++ b/lib/pagy/extras/bulma.rb @@ -36,8 +36,8 @@ def pagy_nav_compact_bulma(pagy, id=caller(1,1)[0].hash) html << %(
) html << (p_prev ? %(

#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"')}

) : %(

#{pagy_t('pagy.nav.prev')}

)) - input = %() - html << %(
#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}
) + input = %() + html << %(
#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}
) html << (p_next ? %(

#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}

) : %(

#{pagy_t('pagy.nav.next')}

)) html << %(
) diff --git a/lib/pagy/extras/foundation.rb b/lib/pagy/extras/foundation.rb index 5c4cf8ac9..c818ab32f 100644 --- a/lib/pagy/extras/foundation.rb +++ b/lib/pagy/extras/foundation.rb @@ -34,8 +34,8 @@ def pagy_nav_compact_foundation(pagy, id=caller(1,1)[0].hash) html << %(
) html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"') : %()) - input = %() - html << %(#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}) + input = %() + html << %(#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}) html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"') : %()) html << %(
) diff --git a/lib/pagy/extras/items.rb b/lib/pagy/extras/items.rb index ab39bee1e..5ced2c7ad 100644 --- a/lib/pagy/extras/items.rb +++ b/lib/pagy/extras/items.rb @@ -36,7 +36,7 @@ def pagy_items_selector(pagy, id=caller(1,1)[0].hash) html = +%() html << %() input = %() - html << %(#{pagy_t('pagy.items.show')} #{input} #{pagy_t('pagy.items.items')}) + html << %(#{pagy_t('pagy.items', items_input: input, count: p_items)}) html << %() end diff --git a/lib/pagy/extras/materialize.rb b/lib/pagy/extras/materialize.rb index 55768bad3..93fbfb4e7 100644 --- a/lib/pagy/extras/materialize.rb +++ b/lib/pagy/extras/materialize.rb @@ -36,7 +36,7 @@ def pagy_nav_compact_materialize(pagy, id=caller(1,1)[0].hash) html << (p_prev ? %() : %()) input = %() - html << %(
#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}
) + html << %(
#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}
) html << (p_next ? %() : %()) html << %() diff --git a/lib/pagy/extras/navs.rb b/lib/pagy/extras/navs.rb index e6ea60c34..55b145ca3 100644 --- a/lib/pagy/extras/navs.rb +++ b/lib/pagy/extras/navs.rb @@ -17,7 +17,7 @@ def pagy_nav_compact(pagy, id=caller(1,1)[0].hash) html << (p_prev ? %(#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'} ) : %(#{pagy_t('pagy.nav.prev')} )) input = %() - html << %(#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages} ) + html << %(#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)} ) html << (p_next ? %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}) : %(#{pagy_t('pagy.nav.next')})) html << %() diff --git a/lib/pagy/extras/semantic.rb b/lib/pagy/extras/semantic.rb index 033f102e8..b40739f6e 100644 --- a/lib/pagy/extras/semantic.rb +++ b/lib/pagy/extras/semantic.rb @@ -33,8 +33,8 @@ def pagy_nav_compact_semantic(pagy, id=caller(1,1)[0].hash) (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM) html << (p_prev ? %(#{link.call p_prev, '', 'aria-label="previous"'}) : %(
)) - input = %() - html << %(
#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}
) + input = %() + html << %(
#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}
) html << (p_next ? %(#{link.call p_next, '', 'aria-label="next"'}) : %(
)) html << %() diff --git a/test/pagy/extras/bulma_test.rb b/test/pagy/extras/bulma_test.rb index 08e979ec2..1089ae2b8 100644 --- a/test/pagy/extras/bulma_test.rb +++ b/test/pagy/extras/bulma_test.rb @@ -102,21 +102,21 @@ pagy, _ = @array.pagy(1) html, id = frontend.pagy_nav_compact_bulma(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 3 for bulma' do pagy, _ = @array.pagy(3) html, id = frontend.pagy_nav_compact_bulma(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 6 for bulma' do pagy, _ = @array.pagy(6) html, id = frontend.pagy_nav_compact_bulma(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end end diff --git a/test/pagy/extras/foundation_test.rb b/test/pagy/extras/foundation_test.rb index d092f1799..143097031 100644 --- a/test/pagy/extras/foundation_test.rb +++ b/test/pagy/extras/foundation_test.rb @@ -50,21 +50,21 @@ pagy, _ = @array.pagy(1) html, id = frontend.pagy_nav_compact_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 3 for foundation' do pagy, _ = @array.pagy(3) html, id = frontend.pagy_nav_compact_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 6 for foundation' do pagy, _ = @array.pagy(6) html, id = frontend.pagy_nav_compact_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end end diff --git a/test/pagy/extras/semantic_test.rb b/test/pagy/extras/semantic_test.rb index 7d113e1f4..4778b6df0 100644 --- a/test/pagy/extras/semantic_test.rb +++ b/test/pagy/extras/semantic_test.rb @@ -50,21 +50,21 @@ pagy, _ = @array.pagy(1) html, id = frontend.pagy_nav_compact_semantic(pagy), caller(0,1)[0].hash html.must_equal \ - "
Page  of 6
" + "
Page of 6
" end it 'renders page 3' do pagy, _ = @array.pagy(3) html, id = frontend.pagy_nav_compact_semantic(pagy), caller(0,1)[0].hash html.must_equal \ - "
Page  of 6
" + "
Page of 6
" end it 'renders page 6' do pagy, _ = @array.pagy(6) html, id = frontend.pagy_nav_compact_semantic(pagy), caller(0,1)[0].hash html.must_equal \ - "
Page  of 6
" + "
Page of 6
" end end diff --git a/test/pagy/extras/trim_test.rb b/test/pagy/extras/trim_test.rb index 1b15fb815..eb6557981 100644 --- a/test/pagy/extras/trim_test.rb +++ b/test/pagy/extras/trim_test.rb @@ -107,21 +107,21 @@ pagy, _ = @array.pagy(1) html, id = frontend.pagy_nav_compact_bulma(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 3 for bulma' do pagy, _ = @array.pagy(3) html, id = frontend.pagy_nav_compact_bulma(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 6 for bulma' do pagy, _ = @array.pagy(6) html, id = frontend.pagy_nav_compact_bulma(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end end From c1aec4c213a99862ec4e75b9112970db7b64360d Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sun, 30 Sep 2018 17:40:36 +0700 Subject: [PATCH 3/8] removed marginal pagy.nav.current key used only by foundation an fixed consistency in foundation helpers and templates --- lib/locales/pagy.yml | 5 ----- lib/pagy/extras/foundation.rb | 12 ++++++------ lib/templates/nav_foundation.html.erb | 4 ++-- lib/templates/nav_foundation.html.haml | 7 ++----- lib/templates/nav_foundation.html.slim | 5 +---- test/pagy/extras/foundation_test.rb | 16 ++++++++-------- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/locales/pagy.yml b/lib/locales/pagy.yml index fa4f2acc9..91540ae54 100644 --- a/lib/locales/pagy.yml +++ b/lib/locales/pagy.yml @@ -6,7 +6,6 @@ en: prev: "‹ Prev" next: "Next ›" gap: "…" - current: "You're on page" info: single_page: zero: "No %{item_name} found" @@ -27,7 +26,6 @@ es: prev: "‹ Prev" next: "Siguiente ›" gap: "…" - current: "Estás en la página" info: single_page: zero: "Sin resultados" @@ -48,7 +46,6 @@ id: prev: "‹ Balik" next: "Lanjut ›" gap: "…" - current: "Anda di halaman" info: single_page: zero: "Tidak ditemukan %{item_name}" @@ -89,7 +86,6 @@ pt-br: prev: "‹ Anterior" next: "Próximo ›" gap: "…" - current: "Está na página" info: single_page: zero: "Sem resultados" @@ -110,7 +106,6 @@ ru: prev: "‹ Назад" next: "Вперёд ›" gap: "…" - current: "Вы на странице" info: single_page: zero: "Пока %{item_name} нет" diff --git a/lib/pagy/extras/foundation.rb b/lib/pagy/extras/foundation.rb index c818ab32f..dc8dcc545 100644 --- a/lib/pagy/extras/foundation.rb +++ b/lib/pagy/extras/foundation.rb @@ -13,9 +13,9 @@ def pagy_nav_foundation(pagy) html << (p_prev ? %() : %()) pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] - html << if item.is_a?(Integer); %(
  • #{link.call item}
  • ) # page link - elsif item.is_a?(String) ; %(
  • #{pagy_t('pagy.nav.current')} #{item}
  • ) # active page - elsif item == :gap ; %() # page gap + html << if item.is_a?(Integer); %(
  • #{link.call item}
  • ) # page link + elsif item.is_a?(String) ; %(
  • #{item}
  • ) # active page + elsif item == :gap ; %() # page gap end end html << (p_next ? %() @@ -50,9 +50,9 @@ def pagy_nav_responsive_foundation(pagy, id=caller(1,1)[0].hash) tags['before'] << (p_prev ? %() : %()) responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] - tags[item.to_s] = if item.is_a?(Integer); %(
  • #{link.call item}
  • ) # page link - elsif item.is_a?(String) ; %(
  • #{pagy_t('pagy.nav.current')} #{item}
  • ) # active page - elsif item == :gap ; %(
  • #{pagy_t('pagy.nav.gap')}
  • ) # page gap + tags[item.to_s] = if item.is_a?(Integer); %(
  • #{link.call item}
  • ) # page link + elsif item.is_a?(String) ; %(
  • #{item}
  • ) # active page + elsif item == :gap ; %() # page gap end end tags['after'] = +(p_next ? %() diff --git a/lib/templates/nav_foundation.html.erb b/lib/templates/nav_foundation.html.erb index 49f5a6c35..7a17eba00 100644 --- a/lib/templates/nav_foundation.html.erb +++ b/lib/templates/nav_foundation.html.erb @@ -13,8 +13,8 @@ <% end -%> <% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%> <% if item.is_a?(Integer) -%>
  • <%== link.call(item) %>
  • -<% elsif item.is_a?(String) -%>
  • <%== pagy_t('pagy.nav.current')%> <%= item %>
  • -<% elsif item == :gap -%>
  • <%== pagy_t('pagy.nav.gap') %>
  • +<% elsif item.is_a?(String) -%>
  • <%= item %>
  • +<% elsif item == :gap -%> <% end -%> <% end -%> <% if pagy.next -%> diff --git a/lib/templates/nav_foundation.html.haml b/lib/templates/nav_foundation.html.haml index 511012265..bf59778b1 100644 --- a/lib/templates/nav_foundation.html.haml +++ b/lib/templates/nav_foundation.html.haml @@ -22,13 +22,10 @@ - elsif item.is_a?(String) # current page %li.current - %span.show-for-sr - != pagy_t('pagy.nav.current') - != item + = item - elsif item == :gap # page gap - %li.disabled.gap - != pagy_t('pagy.nav.gap') + %li.ellipsis.gap{"aria-hidden" => true} - if pagy.next %li.next!= link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') diff --git a/lib/templates/nav_foundation.html.slim b/lib/templates/nav_foundation.html.slim index 8a846ef22..b03615e8d 100644 --- a/lib/templates/nav_foundation.html.slim +++ b/lib/templates/nav_foundation.html.slim @@ -22,13 +22,10 @@ nav.pagy-nav-foundation role="navigation" aria-label="Pagination" - elsif item.is_a?(String) # current page li.current - span.show-for-sr - == pagy_t('pagy.nav.current') = item - elsif item == :gap # page gap - li.disabled.gap - == pagy_t('pagy.nav.gap') + li.ellipsis.gap aria-hidden="true" - if pagy.next li.next == link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') diff --git a/test/pagy/extras/foundation_test.rb b/test/pagy/extras/foundation_test.rb index 143097031..44f3ad8a6 100644 --- a/test/pagy/extras/foundation_test.rb +++ b/test/pagy/extras/foundation_test.rb @@ -16,26 +16,26 @@ it 'renders page 1' do pagy, _ = @array.pagy(1) frontend.pagy_nav_foundation(pagy).must_equal \ - "" + "" end it 'renders page 3' do pagy, _ = @array.pagy(3) frontend.pagy_nav_foundation(pagy).must_equal \ - "" + "" end it 'renders page 6' do pagy, _ = @array.pagy(6) frontend.pagy_nav_foundation(pagy).must_equal \ - "" + "" end it 'renders page 10' do @array = (1..1000).to_a.extend(Pagy::Array::PageMethod) pagy, _ = @array.pagy(10) frontend.pagy_nav_foundation(pagy).must_equal \ - "" + "" end end @@ -79,21 +79,21 @@ pagy, _ = @array.pagy(1) html, id = frontend.pagy_nav_responsive_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 3 for foundation' do pagy, _ = @array.pagy(3) html, id = frontend.pagy_nav_responsive_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 6 for foundation' do pagy, _ = @array.pagy(6) html, id = frontend.pagy_nav_responsive_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end it 'renders page 10 for foundation' do @@ -101,7 +101,7 @@ pagy, _ = @array.pagy(10) html, id = frontend.pagy_nav_responsive_foundation(pagy), caller(0,1)[0].hash html.must_equal \ - "" + "" end end From e3048f2c1bea77a13b7490048181de268aa736c3 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Mon, 1 Oct 2018 11:21:45 +0700 Subject: [PATCH 4/8] improvements for ja tr and zh-cn --- lib/locales/pagy.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/locales/pagy.yml b/lib/locales/pagy.yml index 91540ae54..52984ae31 100644 --- a/lib/locales/pagy.yml +++ b/lib/locales/pagy.yml @@ -76,7 +76,7 @@ ja: zero: "結果" one: "結果" other: "結果" - compact: "ページ %{page_input} / %{pages}" + compact: "%{page_input} / %{pages} ページ" items: one: "%{items_input} 件ずつ表示" other: "%{items_input} 件ずつ表示" @@ -143,8 +143,8 @@ tr: other: "kayıt" compact: "Sayfa %{page_input} / %{pages}" items: - one: "Göster %{items_input} sayfa başı" - other: "Göster %{items_input} sayfa başı" + one: "Sayfada %{items_input} kayıt göster" + other: "Sayfada %{items_input} kayıt göster" zh-cn: pagy: nav: @@ -153,15 +153,15 @@ zh-cn: gap: "…" info: single_page: - zero: " %{item_name}未找到" - one: "显示 1 条%{item_name}" - other: "显示所有 %{count} 条%{item_name}" - multiple_pages: "共 %{count} 条%{item_name},显示 %{from}-%{to}" + zero: "%{item_name}未找到" + one: "显示 1 项%{item_name}" + other: "显示所有 %{count} 项%{item_name}" + multiple_pages: "共 %{count} 项%{item_name},显示 %{from}-%{to}" item_name: zero: "项目" one: "" other: "" - compact: "页面 %{page_input} / %{pages}" + compact: "第 %{page_input} / %{pages} 页" items: one: "每页显示 %{items_input} 条" other: "每页显示 %{items_input} 条" From 6998932684ecd2591e37b7f9f293e7a0230326fb Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Tue, 2 Oct 2018 13:42:13 +0700 Subject: [PATCH 5/8] pagy.yml properly split into separate locale files --- README.md | 4 +- docs/api/frontend.md | 27 ++++--- docs/extras/items.md | 2 +- docs/migration-tips.md | 2 +- lib/locales/en.yml | 20 +++++ lib/locales/es.yml | 20 +++++ lib/locales/id.yml | 20 +++++ lib/locales/ja.yml | 20 +++++ lib/locales/pagy.yml | 169 ---------------------------------------- lib/locales/pt-br.yml | 20 +++++ lib/locales/ru.yml | 25 ++++++ lib/locales/tr.yml | 20 +++++ lib/locales/zh-cn.yml | 20 +++++ lib/pagy/extras/i18n.rb | 2 +- lib/pagy/frontend.rb | 2 +- 15 files changed, 186 insertions(+), 187 deletions(-) create mode 100644 lib/locales/en.yml create mode 100644 lib/locales/es.yml create mode 100644 lib/locales/id.yml create mode 100644 lib/locales/ja.yml delete mode 100644 lib/locales/pagy.yml create mode 100644 lib/locales/pt-br.yml create mode 100644 lib/locales/ru.yml create mode 100644 lib/locales/tr.yml create mode 100644 lib/locales/zh-cn.yml diff --git a/README.md b/README.md index b7b07cb09..580107a2a 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Besides the classic pagination `nav`, Pagy offers a few ready to use alternative ## Please Star and Share! -Pagy is young and needs to be known, and **you** can really help, even with just a click on the star, or sharing a tweet with friends and collegues. A big thank you for your help! +Pagy is young and needs to be known, and **you** can really help, even with just a click on the star, or sharing a tweet with friends and collegues. A big thank you for your support! ## Help Wanted @@ -148,7 +148,7 @@ Pagy is a fresh project and your help would be great. If you like it, you have a - Create an issue if anything should be improved/fixed - Submit a pull request to improve Pagy - Submit some cool extra -- Submit your translation if your language is missing from the [dictionary file](https://github.com/ddnexus/pagy/blob/master/lib/locales/pagy.yml) +- Submit your translation if your language is missing from the [dictionary files](https://github.com/ddnexus/pagy/blob/master/lib/locales) - Write a Tutorial or a "How To" topic ## Branches and Pull Requests diff --git a/docs/api/frontend.md b/docs/api/frontend.md index 1749fcd38..e325f877a 100644 --- a/docs/api/frontend.md +++ b/docs/api/frontend.md @@ -158,20 +158,17 @@ This method is similar to the `I18n.t` and its equivalent rails `t` helper. It i ## I18n -**IMPORTANT**: if you are using pagy with some language missing from the dictionary file, please, submit your translation! +**IMPORTANT**: if you are using pagy with some language missing from the [dictionary files](https://github.com/ddnexus/pagy/blob/master/lib/locales), please, submit your translation! -Pagy is I18n ready. That means that all its strings are stored in a [dictionary file](https://github.com/ddnexus/pagy/blob/master/lib/locales/pagy.yml), ready to be customized and/or translated/pluralized and used with or without the `I18n` gem. +Pagy is I18n ready. That means that all its strings are stored in a dictionary file of one of its [languages](https://github.com/ddnexus/pagy/blob/master/lib/locales), ready to be customized and/or translated/pluralized and used with or without the `I18n` gem. -The Pagy dictionary is a YAML file containing a few entries used in the the UI by helpers and templates through the [pagy_t method](#pagy_tpath-vars) (eqivalent to the `I18n.t` or rails `t` helper). The file follows the same structure of the standard locale files for `i18n`. +A Pagy dictionary file is a YAML file containing a few entries used in the the UI by helpers and templates through the [pagy_t method](#pagy_tpath-vars) (eqivalent to the `I18n.t` or rails `t` helper). The file follows the same structure of the standard locale files for `i18n`. ### Multi-language apps -For multi-language apps you need the dynamic translation provided by the [i18n extra](../extras/i18n.md), which delegates the handling of the pagy strings to the `I18n` gem. In that case you need only 2 steps: +For multi-language apps you need the dynamic translation provided by the [i18n extra](../extras/i18n.md), which delegates the handling of the pagy strings to the `I18n` gem. In that case you need only to require the I18n extra in the initializer file. -1. require the I18n extra in the initializer file -2. add a copy of the locale file(s) to the usual I18n dir(s), and/or add the pagy entries to the existing files - -**Notice**: For simplicity, you could also use the previous 2 steps for single-language apps, but if you want more performance, please follow the specific documentation below. +**Notice**: For simplicity, you could also use the `i18n` extra for single-language apps, but if you want more performance, please follow the specific documentation below. ### Single-language apps @@ -179,11 +176,17 @@ Single-language apps (i.e. only `fr` or only `en` or only ...) don't need to swi By default, Pagy handles its own dictionary file directly, providing pluralization and interpolation (without dynamic translation) _5x faster_ and using _3.5x less memory_ than the standard `I18n` gem. -If you need to use your own language and/or customize the Pagy strings in this scenario, you need the following steps: +If you are fine with the locales provided with pagy, you just need to load the dictionary file of your language by adding this line the initializer file. For example with `zh-cn`: + +```ruby +Pagy::Frontend::I18N.load(file: Pagy.root.join('locales', 'zh-cn.yml'), language:'zh-cn') +``` + +If you need to use your own translation file and/or customize the Pagy strings in this scenario, you may need the following steps: -1. copy and edit the [dictionary file](https://github.com/ddnexus/pagy/blob/master/lib/locales/pagy.yml) -2. see [Adding the model translations](#adding-the-model-translations) below -3. load the dictionary file in the initializer file (e.g. `Pagy::Frontend::I18N.load(file:..., language:'en')` +1. copy and edit one of the [dictionary files](https://github.com/ddnexus/pagy/blob/master/lib/locales) +2. load it in the initializer file (e.g. `Pagy::Frontend::I18N.load(file:..., language:'tr')` +3. see [Adding the model translations](#adding-the-model-translations) below 4. check if you need to configure some of the following variables in the [pagy.rb](https://github.com/ddnexus/pagy/blob/master/lib/config/pagy.rb) initializer. #### Pagy::Frontend::I18N Constant diff --git a/docs/extras/items.md b/docs/extras/items.md index 8b8092d04..8cb8c0bb8 100644 --- a/docs/extras/items.md +++ b/docs/extras/items.md @@ -77,6 +77,6 @@ This helper provides an items selector UI, which allows the user to select any a Show items per page -You can change/translate its text by editing the [dictionaray YAML file](https://github.com/ddnexus/pagy/blob/master/lib/locales/pagy.yml) at the `pagy.items` path. +You can change/translate its text by editing the `pagy.items` value in the [dictionaray files](https://github.com/ddnexus/pagy/blob/master/lib/locales). When the items number is changed with the selector, pagy will reload the pagination UI using the selected items per page. It will also request the _right_ page number calculated in order to contain the first item of the previously displayed page. That way the new displayed page will roughly show the same items in the collection before the items change. diff --git a/docs/migration-tips.md b/docs/migration-tips.md index 051a7718c..7a90605a1 100644 --- a/docs/migration-tips.md +++ b/docs/migration-tips.md @@ -129,6 +129,6 @@ If the app uses the bootstrap pagination, the same CSSs should work seamlessly w ### I18n -If the app uses `I18n` you should copy and paste the entries in the [pagy.yml dictionary file](https://github.com/ddnexus/pagy/blob/master/lib/locales/pagy.yml) to the dictionaries of your app, and translate them accordingly. +If the app uses `I18n` you should follow the [I18n doc](api/frontend.md#i18n) See also [I18n](api/frontend.md#i18n). diff --git a/lib/locales/en.yml b/lib/locales/en.yml new file mode 100644 index 000000000..f8e795ac9 --- /dev/null +++ b/lib/locales/en.yml @@ -0,0 +1,20 @@ +en: + pagy: + nav: + prev: "‹ Prev" + next: "Next ›" + gap: "…" + info: + single_page: + zero: "No %{item_name} found" + one: "Displaying 1 %{item_name}" + other: "Displaying all %{count} %{item_name}" + multiple_pages: "Displaying %{item_name} %{from}-%{to} of %{count} in total" + item_name: + zero: "items" + one: "item" + other: "items" + compact: "Page %{page_input} of %{pages}" + items: + one: "Show %{items_input} item per page" + other: "Show %{items_input} items per page" diff --git a/lib/locales/es.yml b/lib/locales/es.yml new file mode 100644 index 000000000..22ae2f55b --- /dev/null +++ b/lib/locales/es.yml @@ -0,0 +1,20 @@ +es: + pagy: + nav: + prev: "‹ Prev" + next: "Siguiente ›" + gap: "…" + info: + single_page: + zero: "Sin resultados" + one: "Mostrando 1 %{item_name}" + other: "Mostrando %{count} %{item_name}" + multiple_pages: "Mostrando %{item_name} %{from}-%{to} de %{count} en total" + item_name: + zero: "ítems" + one: "ítem" + other: "ítems" + compact: "Página %{page_input} de %{pages}" + items: + one: "Mostrar %{items_input} ítem por página" + other: "Mostrar %{items_input} ítems por página" diff --git a/lib/locales/id.yml b/lib/locales/id.yml new file mode 100644 index 000000000..d0cfe249a --- /dev/null +++ b/lib/locales/id.yml @@ -0,0 +1,20 @@ +id: + pagy: + nav: + prev: "‹ Balik" + next: "Lanjut ›" + gap: "…" + info: + single_page: + zero: "Tidak ditemukan %{item_name}" + one: "Menampilkan 1 %{item_name}" + other: "Menampilkan semua %{count} %{item_name}" + multiple_pages: "Menampilkan %{item_name} %{from}-%{to} dari total %{count}" + item_name: + zero: "item" + one: "item" + other: "item" + compact: "Halaman %{page_input} dari %{pages}" + items: + one: "Tampilkan %{items_input} item per halaman" + other: "Tampilkan %{items_input} item per halaman" diff --git a/lib/locales/ja.yml b/lib/locales/ja.yml new file mode 100644 index 000000000..a866d2020 --- /dev/null +++ b/lib/locales/ja.yml @@ -0,0 +1,20 @@ +ja: + pagy: + nav: + prev: "‹ 前へ" + next: "次へ ›" + gap: "…" + info: + single_page: + zero: "見つかりませんでした" + one: "1 件の%{item_name}" + other: "%{count} 件の%{item_name}" + multiple_pages: "%{count} 件中 %{from}-%{to} 件目の%{item_name}を表示中" + item_name: + zero: "結果" + one: "結果" + other: "結果" + compact: "%{page_input} / %{pages} ページ" + items: + one: "%{items_input} 件ずつ表示" + other: "%{items_input} 件ずつ表示" diff --git a/lib/locales/pagy.yml b/lib/locales/pagy.yml deleted file mode 100644 index 52984ae31..000000000 --- a/lib/locales/pagy.yml +++ /dev/null @@ -1,169 +0,0 @@ -# Standard pagy dictionary - -en: - pagy: - nav: - prev: "‹ Prev" - next: "Next ›" - gap: "…" - info: - single_page: - zero: "No %{item_name} found" - one: "Displaying 1 %{item_name}" - other: "Displaying all %{count} %{item_name}" - multiple_pages: "Displaying %{item_name} %{from}-%{to} of %{count} in total" - item_name: - zero: "items" - one: "item" - other: "items" - compact: "Page %{page_input} of %{pages}" - items: - one: "Show %{items_input} item per page" - other: "Show %{items_input} items per page" -es: - pagy: - nav: - prev: "‹ Prev" - next: "Siguiente ›" - gap: "…" - info: - single_page: - zero: "Sin resultados" - one: "Mostrando 1 %{item_name}" - other: "Mostrando %{count} %{item_name}" - multiple_pages: "Mostrando %{item_name} %{from}-%{to} de %{count} en total" - item_name: - zero: "ítems" - one: "ítem" - other: "ítems" - compact: "Página %{page_input} de %{pages}" - items: - one: "Mostrar %{items_input} ítem por página" - other: "Mostrar %{items_input} ítems por página" -id: - pagy: - nav: - prev: "‹ Balik" - next: "Lanjut ›" - gap: "…" - info: - single_page: - zero: "Tidak ditemukan %{item_name}" - one: "Menampilkan 1 %{item_name}" - other: "Menampilkan semua %{count} %{item_name}" - multiple_pages: "Menampilkan %{item_name} %{from}-%{to} dari total %{count}" - item_name: - zero: "item" - one: "item" - other: "item" - compact: "Halaman %{page_input} dari %{pages}" - items: - one: "Tampilkan %{items_input} item per halaman" - other: "Tampilkan %{items_input} item per halaman" -ja: - pagy: - nav: - prev: "‹ 前へ" - next: "次へ ›" - gap: "…" - info: - single_page: - zero: "見つかりませんでした" - one: "1 件の%{item_name}" - other: "%{count} 件の%{item_name}" - multiple_pages: "%{count} 件中 %{from}-%{to} 件目の%{item_name}を表示中" - item_name: - zero: "結果" - one: "結果" - other: "結果" - compact: "%{page_input} / %{pages} ページ" - items: - one: "%{items_input} 件ずつ表示" - other: "%{items_input} 件ずつ表示" -pt-br: - pagy: - nav: - prev: "‹ Anterior" - next: "Próximo ›" - gap: "…" - info: - single_page: - zero: "Sem resultados" - one: "Mostrando 1 %{item_name}" - other: "Mostrando %{count} %{item_name}" - multiple_pages: "Mostrando %{item_name} %{from}-%{to} no total de %{count}" - item_name: - zero: "itens" - one: "item" - other: "itens" - compact: "Página %{page_input} de %{pages}" - items: - one: "Mostrar %{items_input} iten por página" - other: "Mostrar %{items_input} itens por página" -ru: - pagy: - nav: - prev: "‹ Назад" - next: "Вперёд ›" - gap: "…" - info: - single_page: - zero: "Пока %{item_name} нет" - one: "1 %{item_name}" - few: "%{count} %{item_name}" - many: "Всего %{count} %{item_name}" - other: "Всего %{count} %{item_name}" - multiple_pages: "Всего %{count} %{item_name}, показаны с %{from} по %{to}" - item_name: - one: "запись" - few: "записи" - many: "записей" - other: "записей" - compact: "Страница %{page_input} из %{pages}" - items: - one: "Показать %{items_input} записей на странице" - few: "Показать %{items_input} записей на странице" - many: "Показать %{items_input} записей на странице" - other: "Показать %{items_input} записей на странице" -tr: - pagy: - nav: - prev: "‹ Önceki" - next: "Sonraki ›" - gap: "…" - info: - single_page: - zero: "Hiç %{item_name} bulunamadı." - one: "1 %{item_name} gösteriliyor." - other: "Toplam %{count} %{item_name} gösteriliyor." - multiple_pages: "%{count} %{item_name} içerisinden %{from}-%{to} kadarı gösteriliyor." - item_name: - zero: "kayıt" - one: "kayıt" - other: "kayıt" - compact: "Sayfa %{page_input} / %{pages}" - items: - one: "Sayfada %{items_input} kayıt göster" - other: "Sayfada %{items_input} kayıt göster" -zh-cn: - pagy: - nav: - prev: "‹ 上一页" - next: "下一页 ›" - gap: "…" - info: - single_page: - zero: "%{item_name}未找到" - one: "显示 1 项%{item_name}" - other: "显示所有 %{count} 项%{item_name}" - multiple_pages: "共 %{count} 项%{item_name},显示 %{from}-%{to}" - item_name: - zero: "项目" - one: "" - other: "" - compact: "第 %{page_input} / %{pages} 页" - items: - one: "每页显示 %{items_input} 条" - other: "每页显示 %{items_input} 条" - -# PR for other languages are very welcome. Thanks! diff --git a/lib/locales/pt-br.yml b/lib/locales/pt-br.yml new file mode 100644 index 000000000..eaa9607f6 --- /dev/null +++ b/lib/locales/pt-br.yml @@ -0,0 +1,20 @@ +pt-br: + pagy: + nav: + prev: "‹ Anterior" + next: "Próximo ›" + gap: "…" + info: + single_page: + zero: "Sem resultados" + one: "Mostrando 1 %{item_name}" + other: "Mostrando %{count} %{item_name}" + multiple_pages: "Mostrando %{item_name} %{from}-%{to} no total de %{count}" + item_name: + zero: "itens" + one: "item" + other: "itens" + compact: "Página %{page_input} de %{pages}" + items: + one: "Mostrar %{items_input} iten por página" + other: "Mostrar %{items_input} itens por página" diff --git a/lib/locales/ru.yml b/lib/locales/ru.yml new file mode 100644 index 000000000..308862c50 --- /dev/null +++ b/lib/locales/ru.yml @@ -0,0 +1,25 @@ +ru: + pagy: + nav: + prev: "‹ Назад" + next: "Вперёд ›" + gap: "…" + info: + single_page: + zero: "Пока %{item_name} нет" + one: "1 %{item_name}" + few: "%{count} %{item_name}" + many: "Всего %{count} %{item_name}" + other: "Всего %{count} %{item_name}" + multiple_pages: "Всего %{count} %{item_name}, показаны с %{from} по %{to}" + item_name: + one: "запись" + few: "записи" + many: "записей" + other: "записей" + compact: "Страница %{page_input} из %{pages}" + items: + one: "Показать %{items_input} записей на странице" + few: "Показать %{items_input} записей на странице" + many: "Показать %{items_input} записей на странице" + other: "Показать %{items_input} записей на странице" diff --git a/lib/locales/tr.yml b/lib/locales/tr.yml new file mode 100644 index 000000000..4f40f66d1 --- /dev/null +++ b/lib/locales/tr.yml @@ -0,0 +1,20 @@ +tr: + pagy: + nav: + prev: "‹ Önceki" + next: "Sonraki ›" + gap: "…" + info: + single_page: + zero: "Hiç %{item_name} bulunamadı." + one: "1 %{item_name} gösteriliyor." + other: "Toplam %{count} %{item_name} gösteriliyor." + multiple_pages: "%{count} %{item_name} içerisinden %{from}-%{to} kadarı gösteriliyor." + item_name: + zero: "kayıt" + one: "kayıt" + other: "kayıt" + compact: "Sayfa %{page_input} / %{pages}" + items: + one: "Sayfada %{items_input} kayıt göster" + other: "Sayfada %{items_input} kayıt göster" diff --git a/lib/locales/zh-cn.yml b/lib/locales/zh-cn.yml new file mode 100644 index 000000000..0387f8add --- /dev/null +++ b/lib/locales/zh-cn.yml @@ -0,0 +1,20 @@ +zh-cn: + pagy: + nav: + prev: "‹ 上一页" + next: "下一页 ›" + gap: "…" + info: + single_page: + zero: "%{item_name}未找到" + one: "显示 1 项%{item_name}" + other: "显示所有 %{count} 项%{item_name}" + multiple_pages: "共 %{count} 项%{item_name},显示 %{from}-%{to}" + item_name: + zero: "项目" + one: "" + other: "" + compact: "第 %{page_input} / %{pages} 页" + items: + one: "每页显示 %{items_input} 条" + other: "每页显示 %{items_input} 条" diff --git a/lib/pagy/extras/i18n.rb b/lib/pagy/extras/i18n.rb index 68b658f9c..a8b487964 100644 --- a/lib/pagy/extras/i18n.rb +++ b/lib/pagy/extras/i18n.rb @@ -4,7 +4,7 @@ class Pagy # Use ::I18n gem module Frontend - ::I18n.load_path << Pagy.root.join('locales', 'pagy.yml') + ::I18n.load_path += Dir[Pagy.root.join('locales', '*.yml')] # Override the built-in pagy_t def pagy_t(*args) diff --git a/lib/pagy/frontend.rb b/lib/pagy/frontend.rb index c4118a543..ff15702c7 100644 --- a/lib/pagy/frontend.rb +++ b/lib/pagy/frontend.rb @@ -55,7 +55,7 @@ def pagy_link_proc(pagy, link_extra='') end # Pagy::Frontend::I18N - def (I18N = {data:{}}).load(file:Pagy.root.join('locales', 'pagy.yml'), language: 'en') + def (I18N = {data:{}}).load(file:Pagy.root.join('locales', 'en.yml'), language: 'en') self[:data] = YAML.load_file(file)[language] self[:plural] = eval(Pagy.root.join('locales', 'plurals.rb').read)[language] #rubocop:disable Security/Eval end; I18N.load From 5680628294f822c8411b518278641cc2571cea1d Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Tue, 2 Oct 2018 17:34:58 +0700 Subject: [PATCH 6/8] fix for wrong indentation in zh-cn --- lib/locales/zh-cn.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locales/zh-cn.yml b/lib/locales/zh-cn.yml index 0387f8add..de1da2a52 100644 --- a/lib/locales/zh-cn.yml +++ b/lib/locales/zh-cn.yml @@ -9,7 +9,7 @@ zh-cn: zero: "%{item_name}未找到" one: "显示 1 项%{item_name}" other: "显示所有 %{count} 项%{item_name}" - multiple_pages: "共 %{count} 项%{item_name},显示 %{from}-%{to}" + multiple_pages: "共 %{count} 项%{item_name},显示 %{from}-%{to}" item_name: zero: "项目" one: "" From c46188587c6abcdf337fbfaffeea1781bdffd015 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Tue, 2 Oct 2018 14:34:10 +0700 Subject: [PATCH 7/8] added ru plural proc --- lib/locales/plurals.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/locales/plurals.rb b/lib/locales/plurals.rb index faa199586..ae3309a99 100644 --- a/lib/locales/plurals.rb +++ b/lib/locales/plurals.rb @@ -3,13 +3,25 @@ # frozen_string_literal: true # utility variables -zero_one = ['zero', 'one'] +zero_one = ['zero', 'one'] +from2to4 = (2..4) +from5to9 = (5..9) +from11to14 = (11..14) +from12to14 = (12..14) # Plurals # A plural proc returns a plural type string based on the passed count # Each plural proc may apply to one or more languages below plurals = { - zero_one_other: -> (count) {zero_one[count] || 'other'} + zero_one_other: -> (count) {zero_one[count] || 'other'}, + one_few_many_other: -> (count) do + mod10, mod100 = count % 10, count % 100 + if mod10 == 1 && mod100 != 11 ; 'one' + elsif from2to4.cover?(mod10) && !from12to14.cover?(mod100) ; 'few' + elsif mod10 == 0 || from5to9.cover?(mod10) || from11to14.cover?(mod100) ; 'many' + else 'other' + end + end } # Languages (language/plural pairs) @@ -17,7 +29,7 @@ # The default plural for missing languages is the :zero_one_other plural (used for English) Hash.new(plurals[:zero_one_other]).tap do |languages| languages['en'] = plurals[:zero_one_other] - - # PR for other languages and plurals are very welcome. Thanks! - + languages['ru'] = plurals[:one_few_many_other] end + +# PR for other languages and plurals are very welcome. Thanks! From f8017c3bb40c0e8fe762941272bef4bb774f334d Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Tue, 2 Oct 2018 18:24:39 +0700 Subject: [PATCH 8/8] updated config/pagy.rb --- lib/config/pagy.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/config/pagy.rb b/lib/config/pagy.rb index 8e015169e..b2c6f65ce 100644 --- a/lib/config/pagy.rb +++ b/lib/config/pagy.rb @@ -101,8 +101,9 @@ # I18n: faster internal pagy implementation (does not use the I18n gem) # Use only for single language apps that don't need dynamic translation between multiple languages # See https://ddnexus.github.io/pagy/api/frontend#i18n -# Notice: Do not use the following 2 lines if you use the i18n extra below -# Pagy::Frontend::I18N.load(file:'path/to/dictionary.yml', language:'en') # load a custom file +# Notice: Do not use any of the following lines if you use the i18n extra below +# Pagy::Frontend::I18N.load(file: Pagy.root.join('locale', 'es.yml'), language:'es') # load 'es' pagy language file +# Pagy::Frontend::I18N.load(file:'path/to/dictionary.yml', language:'en') # load a custom 'en' file # Pagy::Frontend::I18N[:plural] = -> (count) {(['zero', 'one'][count] || 'other')} # default # I18n: Use the `I18n` gem instead of the pagy implementation