Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit 44273b0

Browse files
authored
Merge pull request #8 from protonemedia/pagination-translations
Translatable pagination
2 parents 93ad219 + 680f6d3 commit 44273b0

File tree

3 files changed

+69
-11
lines changed

3 files changed

+69
-11
lines changed

__tests__/Pagination.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { mount } from "@vue/test-utils"
2+
import BasePagination from "../js/Components/Pagination.vue";
3+
import Pagination from "../js/Tailwind2/Pagination.vue";
4+
import expect from 'expect'
5+
6+
describe('Pagination.vue', () => {
7+
it('uses the default translations', () => {
8+
const component = mount(Pagination, {
9+
propsData: {
10+
meta: {
11+
total: 0
12+
},
13+
}
14+
});
15+
16+
expect(component.html()).toContain("No results found");
17+
});
18+
19+
it('can use custom translations', () => {
20+
BasePagination.setTranslations({
21+
no_results_found: "Geen resultaten gevonden"
22+
})
23+
24+
const component = mount(Pagination, {
25+
propsData: {
26+
meta: {
27+
total: 0
28+
},
29+
}
30+
});
31+
32+
expect(component.html()).toContain("Geen resultaten gevonden");
33+
});
34+
35+
})

js/Components/Pagination.vue

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
<script>
2-
export default {
2+
const Pagination = {
33
props: {
4-
meta: Object,
5-
required: false,
4+
meta: {
5+
type: Object,
6+
required: false,
7+
},
8+
},
9+
10+
computed: {
11+
translations() {
12+
return Pagination.defaultTranslations;
13+
},
14+
},
15+
16+
defaultTranslations: {
17+
no_results_found: "No results found",
18+
previous: "Previous",
19+
next: "Next",
20+
to: "to",
21+
of: "of",
22+
results: "results",
23+
},
24+
25+
setTranslations(translations) {
26+
Pagination.defaultTranslations = translations;
627
},
728
};
29+
30+
export default Pagination;
831
</script>

js/Tailwind2/Pagination.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6"
44
v-if="meta"
55
>
6-
<p v-if="meta.total < 1">No results found</p>
6+
<p v-if="meta.total < 1">{{ translations.no_results_found }}</p>
77
<div v-if="meta.total > 0" class="flex-1 flex justify-between sm:hidden">
88
<component
99
:is="meta.prev_page_url ? 'inertia-link' : 'div'"
1010
:href="meta.prev_page_url"
1111
class="relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:text-gray-500"
12-
>Previous</component>
12+
>{{ translations.previous }}</component>
1313
<component
1414
:is="meta.next_page_url ? 'inertia-link' : 'div'"
1515
:href="meta.next_page_url"
1616
class="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:text-gray-500"
17-
>Next</component>
17+
>{{ translations.next }}</component>
1818
</div>
1919
<div v-if="meta.total > 0" class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
2020
<div>
2121
<p class="hidden lg:block text-sm text-gray-700">
2222
<span class="font-medium">{{ meta.from }}</span>
23-
to
23+
{{ translations.to }}
2424
<span class="font-medium">{{ meta.to }}</span>
25-
of
25+
{{ translations.of }}
2626
<span class="font-medium">{{ meta.total }}</span>
27-
results
27+
{{ translations.results }}
2828
</p>
2929
</div>
3030
<div>
@@ -37,7 +37,7 @@
3737
:href="meta.prev_page_url"
3838
class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50"
3939
>
40-
<span class="sr-only">Previous</span>
40+
<span class="sr-only">{{ translations.previous }}</span>
4141
<svg
4242
xmlns="http://www.w3.org/2000/svg"
4343
class="h-5 w-5"
@@ -69,7 +69,7 @@
6969
:href="meta.next_page_url"
7070
class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50"
7171
>
72-
<span class="sr-only">Next</span>
72+
<span class="sr-only">{{ translations.next }}</span>
7373
<svg
7474
xmlns="http://www.w3.org/2000/svg"
7575
class="h-5 w-5"

0 commit comments

Comments
 (0)