mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 21:00:16 +02:00
fix(webui): support pl pluralization
Co-authored-by: @SubZeroPL
This commit is contained in:
parent
4446001310
commit
20afd83356
1 changed files with 31 additions and 1 deletions
|
|
@ -3,7 +3,7 @@ import VueI18n, {LocaleMessages} from 'vue-i18n'
|
||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
function loadLocaleMessages (): LocaleMessages {
|
function loadLocaleMessages(): LocaleMessages {
|
||||||
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
|
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
|
||||||
const messages: LocaleMessages = {}
|
const messages: LocaleMessages = {}
|
||||||
locales.keys().forEach(key => {
|
locales.keys().forEach(key => {
|
||||||
|
|
@ -20,4 +20,34 @@ export default new VueI18n({
|
||||||
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
|
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
|
||||||
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
|
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
|
||||||
messages: loadLocaleMessages(),
|
messages: loadLocaleMessages(),
|
||||||
|
pluralizationRules: {
|
||||||
|
/**
|
||||||
|
* @param choice {number} a choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)`
|
||||||
|
* @param choicesLength {number} an overall amount of available choices
|
||||||
|
* @returns a final choice index to select plural word by
|
||||||
|
*/
|
||||||
|
'pl': function (choice, choicesLength) {
|
||||||
|
// brak stron
|
||||||
|
if (choice === 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1 strona
|
||||||
|
if (choice === 1) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const betweenTwoAndFour = ((choice % 10) >= 2 && (choice % 10) <= 4)
|
||||||
|
const lessThanTen = choice < 10
|
||||||
|
const moreThanTwenty = choice > 20
|
||||||
|
|
||||||
|
// 2 strony, 3 strony, 4 strony, 22 strony ...
|
||||||
|
if (betweenTwoAndFour && (lessThanTen || moreThanTwenty)) {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
|
// other cases, 5 stron, 67 stron, 259 stron and so on
|
||||||
|
return (choicesLength < 4) ? 2 : 3
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue