Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Translated page numbers with toLocaleString #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/guide/api/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ Limit of pages to be rendered. `0` shows all pages (default). `-1` will hide num
* `Boolean` (optional)

When `true`, the pagination component will keep the same length regardless of the position of the page number. This is useful when you want to keep the pagination component always the same size and not vary at the first or last pages. The `limit` prop is used to determine the length of the pagination.

## lang

* `String` (optional)

The default lang value is `en-US`. Translating page numbers depends on Javascript toLocaleString method.
11 changes: 8 additions & 3 deletions src/Bootstrap4Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:data="data"
:limit="limit"
:keep-length="keepLength"
:lang="lang"
@pagination-change-page="onPaginationChangePage"
v-slot="slotProps"
>
Expand All @@ -28,7 +29,7 @@

<li class="page-item pagination-page-nav" v-for="(page, key) in slotProps.computed.pageRange" :key="key" :class="{ 'active': page == slotProps.computed.currentPage }">
<a class="page-link" href="#" v-on="slotProps.pageButtonEvents(page)">
{{ page }}
{{ slotProps.translatePage(page) }}
<span class="sr-only" v-if="page == slotProps.computed.currentPage">(current)</span>
</a>
</li>
Expand All @@ -53,7 +54,7 @@ export default {
compatConfig: {
MODE: 3
},

inheritAttrs: false,

emits: ['pagination-change-page'],
Expand Down Expand Up @@ -92,7 +93,11 @@ export default {
validator: value => {
return ['left', 'center', 'right'].indexOf(value) !== -1;
}
}
},
lang: {
type: String,
default: 'en-US',
},
},

methods: {
Expand Down
11 changes: 8 additions & 3 deletions src/Bootstrap5Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:data="data"
:limit="limit"
:keep-length="keepLength"
:lang="lang"
@pagination-change-page="onPaginationChangePage"
v-slot="slotProps"
>
Expand All @@ -27,7 +28,7 @@

<li class="page-item pagination-page-nav" v-for="(page, key) in slotProps.computed.pageRange" :key="key" :class="{ 'active': page == slotProps.computed.currentPage }">
<a class="page-link" href="#" v-on="slotProps.pageButtonEvents(page)" :aria-current="page == slotProps.computed.currentPage ? 'page' : null">
{{ page }}
{{ slotProps.translatePage(page) }}
</a>
</li>

Expand All @@ -50,7 +51,7 @@ export default {
compatConfig: {
MODE: 3
},

inheritAttrs: false,

emits: ['pagination-change-page'],
Expand Down Expand Up @@ -89,7 +90,11 @@ export default {
validator: value => {
return ['left', 'center', 'right'].indexOf(value) !== -1;
}
}
},
lang: {
type: String,
default: 'en-US',
},
},

methods: {
Expand Down
10 changes: 10 additions & 0 deletions src/RenderlessPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default {
type: Boolean,
default: false,
},
lang: {
type: String,
default: 'en-US',
},
},

computed: {
Expand Down Expand Up @@ -195,6 +199,12 @@ export default {
this.selectPage(page);
},
}),
translatePage: (page) => {
if (typeof page !== 'number') {
return page;
}
return page.toLocaleString(this.lang);
},
});
},
};
Expand Down
7 changes: 6 additions & 1 deletion src/TailwindPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:data="data"
:limit="limit"
:keep-length="keepLength"
:lang="lang"
@pagination-change-page="onPaginationChangePage"
v-slot="slotProps"
>
Expand Down Expand Up @@ -41,7 +42,7 @@
v-on="slotProps.pageButtonEvents(page)"
:disabled="page === slotProps.computed.currentPage"
>
{{ page }}
{{ slotProps.translatePage(page) }}
</button>

<button
Expand Down Expand Up @@ -110,6 +111,10 @@ export default {
'text-blue-600',
],
},
lang: {
type: String,
default: 'en-US',
},
},

methods: {
Expand Down
15 changes: 13 additions & 2 deletions src/demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
<option value="right">Right</option>
</select>
</div>
<div class="col">
<label class="form-label" for="align">Translate</label><br>
<select id="align" class="form-select" v-model="lang">
<option value="en-US">English</option>
<option value="bn-BD">Bengali</option>
</select>
</div>
</div>
<div class="row">
<div class="col">
Expand Down Expand Up @@ -55,10 +62,11 @@
:show-disabled="showDisabled"
:size="size"
:align="align"
:lang="lang"
@pagination-change-page="getResults"
/>
</RenderToIFrame>

<h3 class="mt-3 mb-2">Bootstrap 5</h3>
<RenderToIFrame>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
Expand All @@ -70,6 +78,7 @@
:show-disabled="showDisabled"
:size="size"
:align="align"
:lang="lang"
@pagination-change-page="getResults"
/>
</RenderToIFrame>
Expand All @@ -80,6 +89,7 @@
:data="laravelData"
:limit="limit"
:keep-length="keepLength"
:lang="lang"
@pagination-change-page="getResults"
/>
</RenderToIFrame>
Expand Down Expand Up @@ -133,7 +143,8 @@ export default {
keepLength: false,
showDisabled: false,
size: 'default',
align: 'left'
align: 'left',
lang: 'en-US'
}
},

Expand Down