Skip to content

Commit 658fa5c

Browse files
Alexandr Diachenkorstoenescu
authored andcommitted
* Add plurals rulss for many langs (quasarframework#1225)
* Fix ISO code Ukrainian ua -> uk
1 parent e14292a commit 658fa5c

File tree

7 files changed

+59
-10
lines changed

7 files changed

+59
-10
lines changed

dev/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
,{ label: 'Indonezian', value: 'id' }
2323
,{ label: 'Croatian', value: 'hr' }
2424
,{ label: 'Russian', value: 'ru' }
25-
,{ label: 'Ukrainian', value: 'ua' }
25+
,{ label: 'Ukrainian', value: 'uk' }
2626
,{ label: 'Polish', value: 'pl' }
2727
]"
2828
v-model="lang"

i18n/en-uk.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { declOfNum } from '../src/utils/plural'
2+
13
export default {
24
lang: 'en-uk',
35
label: {
@@ -32,7 +34,7 @@ export default {
3234
noData: 'No data available',
3335
noResults: 'No matching records found',
3436
loader: 'Loading...',
35-
selectedRows: rows => rows > 1 ? `${rows} selected row(s).` : `${rows === 0 ? 'No' : '1'} selected rows.`,
37+
selectedRows: rows => rows > 0 ? `${rows} ${declOfNum(rows, ['row', 'rows'])} selected.` : 'No selected rows.',
3638
rowsPerPage: 'Rows per page:',
3739
allRows: 'All',
3840
pagination: (start, end, total) => `${start}-${end} of ${total}`,

i18n/en-us.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { declOfNum } from '../src/utils/plural'
2+
13
export default {
24
lang: 'en-us',
35
label: {
@@ -32,7 +34,7 @@ export default {
3234
noData: 'No data available',
3335
noResults: 'No matching records found',
3436
loader: 'Loading...',
35-
selectedRows: rows => rows > 1 ? `${rows} selected row(s).` : `${rows === 0 ? 'No' : '1'} selected rows.`,
37+
selectedRows: rows => rows > 0 ? `${rows} ${declOfNum(rows, ['row', 'rows'])} selected.` : 'No selected rows.',
3638
rowsPerPage: 'Rows per page:',
3739
allRows: 'All',
3840
pagination: (start, end, total) => `${start}-${end} of ${total}`,

i18n/fr.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { declOfNum } from '../src/utils/plural'
2+
13
export default {
24
lang: 'fr',
35
label: {
@@ -32,7 +34,7 @@ export default {
3234
noData: 'Aucune donnée à afficher',
3335
noResults: 'Aucune donnée trouvée',
3436
loader: 'Chargement...',
35-
selectedRows: rows => rows > 1 ? `${rows} ligne(s) sélectionnée(s).` : `${rows === 0 ? 'Non' : '1'} ligne(s) sélectionnée(s).`,
37+
selectedRows: rows => rows > 0 ? `${rows} ${declOfNum(rows, ['ligne sélectionnée', 'lignes sélectionnées'])}.` : 'Non lignes sélectionnées.',
3638
rowsPerPage: 'Lignes par page:',
3739
allRows: 'Tous',
3840
pagination: (start, end, total) => `${start}-${end} sur ${total}`,

i18n/it.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { declOfNum } from '../src/utils/plural'
2+
13
export default {
24
lang: 'it',
35
label: {
@@ -32,7 +34,7 @@ export default {
3234
noData: 'Nessun dato disponibile',
3335
noResults: 'Nessuna corrispondenza trovata',
3436
loader: 'Caricamento...',
35-
selectedRows: rows => rows > 1 ? `${rows} righe selezionate.` : `${rows === 0 ? 'Nessuna' : '1'} riga selezionata.`,
37+
selectedRows: rows => rows > 0 ? `${rows} ${declOfNum(rows, ['riga selezionata', 'righe selezionate'])}.` : 'Nessuna riga selezionata.',
3638
rowsPerPage: 'Righe per pagina:',
3739
allRows: 'Tutte',
3840
pagination: (start, end, total) => `${start}-${end} di ${total}`,

i18n/ua.js renamed to i18n/uk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { declOfNum } from '../src/utils/plural'
22

33
export default {
4-
lang: 'ua',
4+
lang: 'uk',
55
label: {
66
clear: 'Очистити',
77
ok: 'OK',

src/utils/plural.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,51 @@ import i18n from '../i18n'
33
// Pluralization l10n http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms
44
export function declOfNum (n, titles) {
55
switch (i18n.name) {
6+
case 'ach':
7+
case 'ak':
8+
case 'am':
9+
case 'arn':
10+
case 'br':
11+
case 'fa':
12+
case 'fil':
13+
case 'fr':
14+
case 'gun':
15+
case 'ln':
16+
case 'mfe':
17+
case 'mg':
18+
case 'mi':
19+
case 'oc':
20+
case 'pt-br':
21+
case 'tg':
22+
case 'ti':
23+
case 'tr':
24+
case 'uz':
25+
case 'wa':
26+
return titles[n > 1 ? 1 : 0] // 2 plurals
27+
case 'be':
28+
case 'bs':
29+
case 'hr':
30+
case 'me':
631
case 'ru':
7-
case 'ua':
8-
return titles[n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2]
9-
default:
10-
return titles[n !== 1 ? 1 : 0]
32+
case 'sr':
33+
case 'uk':
34+
return titles[n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] // 3 plurals
35+
case 'cs':
36+
case 'sk':
37+
return titles[n === 1 ? 0 : (n >= 2 && n <= 4) ? 1 : 2] // 3 plurals
38+
case 'ga':
39+
return titles[n === 1 ? 0 : n === 2 ? 1 : (n > 2 && n < 7) ? 2 : (n > 6 && n < 11) ? 3 : 4] // 5 plurals
40+
case 'lt':
41+
return titles[n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] // 3 plurals
42+
case 'lv':
43+
return titles[n % 10 === 1 && n % 100 !== 11 ? 0 : n !== 0 ? 1 : 2] // 3 plurals
44+
case 'pl':
45+
return titles[n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] // 3 plurals
46+
case 'ro':
47+
return titles[n === 1 ? 0 : (n === 0 || (n % 100 > 0 && n % 100 < 20)) ? 1 : 2] // 3 plurals
48+
case 'sl':
49+
return titles[n % 100 === 1 ? 0 : n % 100 === 2 ? 1 : n % 100 === 3 || n % 100 === 4 ? 2 : 3] // 4 plurals
50+
default: // en-uk, en-us, de, nl, sv, da, no, nn, nb, fo, es, pt, it, bg, el, fi, et, he, hi, eo, hu...
51+
return titles[n !== 1 ? 1 : 0] // 2 plurals
1152
}
1253
}

0 commit comments

Comments
 (0)