Skip to content

Commit 9c35a77

Browse files
author
Yousef Sultan
committed
Implement localization. Closes #25
1 parent ff87f00 commit 9c35a77

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
## Features
1111
- Sorting, with numerical sorting
1212
- Pagination
13+
- Localization
1314
- Fuzzy searching
1415
- Excel export
1516
- Printing
@@ -123,6 +124,15 @@ customButtons => Custom buttons thingy => [
123124
]
124125
```
125126

127+
### Localization
128+
129+
You can use the property `locale` to set the display language. Available languages:
130+
131+
- `en` (default)
132+
- `ar`
133+
134+
> You can very easily contribute a locale. Just clone `locales/en.json` and `require` in `locales/index.js`
135+
126136
### React to click on row
127137

128138
The datatable will emit the `row-click` event if `clickable` is set to `true` (default).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-materialize-datatable",
3-
"version": "0.6.9",
3+
"version": "0.7.0",
44
"description": "Datatable for VueJS with Materialize",
55
"author": "Yousef Sultan <yousef.su.2000@gmail.com>",
66
"private": false,

src/DataTable.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,26 @@
6767
</table>
6868

6969
<div class="table-footer" v-if="paginate">
70-
<div class="datatable-length">
70+
<div :class="{'datatable-length': true, 'rtl': lang.__is_rtl}">
7171
<label>
72-
<span>Rows per page:</span>
72+
<span>{{lang['rows_per_page']}}:</span>
7373
<select class="browser-default" @change="onTableLength">
7474
<option v-for="option in perPageOptions" :value="option" :selected="option == currentPerPage">
75-
{{ option === -1 ? 'All' : option }}
75+
{{ option === -1 ? lang['all'] : option }}
7676
</option>
7777
</select>
7878
</label>
7979
</div>
80-
<div class="datatable-info">
81-
{{(currentPage - 1) * currentPerPage ? (currentPage - 1) * currentPerPage : 1}}
82-
-{{Math.min(processedRows.length, currentPerPage * currentPage)}} of {{processedRows.length}}
80+
<div :class="{'datatable-info': true, 'rtl': lang.__is_rtl}">
81+
<span>{{(currentPage - 1) * currentPerPage ? (currentPage - 1) * currentPerPage : 1}}
82+
-{{Math.min(processedRows.length, currentPerPage * currentPage)}}
83+
</span>
84+
<span>
85+
{{lang['out_of_pages']}}
86+
</span>
87+
<span>
88+
{{processedRows.length}}
89+
</span>
8390
</div>
8491
<div>
8592
<ul class="material-pagination">
@@ -101,6 +108,7 @@
101108

102109
<script>
103110
import Fuse from 'fuse.js';
111+
import locales from './locales';
104112
105113
export default {
106114
props: {
@@ -120,6 +128,7 @@
120128
paginate: {default: true},
121129
exportable: {default: true},
122130
printable: {default: true},
131+
locale: {default: 'en'},
123132
},
124133
125134
data: () => ({
@@ -327,10 +336,16 @@
327336
if (this.paginate)
328337
paginatedRows = paginatedRows.slice((this.currentPage - 1) * this.currentPerPage, this.currentPerPage === -1 ? paginatedRows.length + 1 : this.currentPage * this.currentPerPage);
329338
return paginatedRows;
339+
},
340+
341+
lang: function() {
342+
return this.locale in locales ? locales[this.locale] : locales['en'];
330343
}
331344
},
332345
333346
mounted: function() {
347+
if (!(this.locale in locales))
348+
console.error(`vue-materialize-datable: Invalid locale '${this.locale}'`);
334349
this.currentPerPage = this.currentPerPage
335350
}
336351
}
@@ -583,4 +598,8 @@
583598
table th:first-child, table td:first-child {
584599
padding-left: 24px;
585600
}
601+
602+
.rtl {
603+
direction: rtl;
604+
}
586605
</style>

src/locales/ar.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rows_per_page": "عدد النتائج كل صفحة",
3+
"out_of_pages": "من أصل",
4+
"all": "الكل",
5+
"__is_rtl": true
6+
}

src/locales/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rows_per_page": "Rows per page",
3+
"out_of_pages": "of",
4+
"all": "All"
5+
}

src/locales/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
en: require('./en.json'),
3+
ar: require('./ar.json'),
4+
};

0 commit comments

Comments
 (0)