From 796debadbc3b67b2cb6400764b11365d8d9253c5 Mon Sep 17 00:00:00 2001 From: Avris Date: Sun, 15 Nov 2020 09:39:26 +0100 Subject: [PATCH] #61 [en] save bytes in generator, no use for honorifics --- locale/en/config.suml | 2 ++ locale/pl/config.suml | 2 ++ nuxt.config.js | 1 + src/classes.js | 38 +++++++++++++++++++++++++++----------- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/locale/en/config.suml b/locale/en/config.suml index 4f74b7d6..3110c930 100644 --- a/locale/en/config.suml +++ b/locale/en/config.suml @@ -7,6 +7,8 @@ pronouns: default: 'he' any: route: 'any' + plurals: true + honorifics: false sources: enabled: true diff --git a/locale/pl/config.suml b/locale/pl/config.suml index 58ca8369..2bbb948a 100644 --- a/locale/pl/config.suml +++ b/locale/pl/config.suml @@ -7,6 +7,8 @@ pronouns: default: 'on' any: route: 'dowolne' + plurals: true + honorifics: true sources: enabled: true diff --git a/nuxt.config.js b/nuxt.config.js index 352503df..2ef46c41 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -100,6 +100,7 @@ export default { BASE_URL: process.env.BASE_URL, TITLE: title, PUBLIC_KEY: fs.readFileSync(__dirname + '/keys/public.pem').toString(), + CONFIG: config, LOCALE: config.locale, LOCALES: locales, FLAGS: buildDict(function *() { diff --git a/src/classes.js b/src/classes.js index 06983726..d5ded1e4 100644 --- a/src/classes.js +++ b/src/classes.js @@ -193,12 +193,15 @@ export class Pronoun { } toArray() { - return [ - ...Object.values(this.morphemes).map(s => escape(s)), - this.plural.map(p => p ? 1 : 0).join(''), - this.pluralHonorific.map(p => p ? 1 : 0).join(''), - escape(this.description), - ]; + const elements = Object.values(this.morphemes).map(s => escape(s)); + if (process.env.CONFIG.pronouns.plurals) { + elements.push(this.plural.map(p => p ? 1 : 0).join('')); + if (process.env.CONFIG.pronouns.honorifics) { + elements.push(this.pluralHonorific.map(p => p ? 1 : 0).join('')); + } + } + elements.push(escape(this.description)); + return elements; } toString() { @@ -206,16 +209,29 @@ export class Pronoun { } static from(data) { - if (data.length === MORPHEMES.length + 2) { + let extraFields = 1; // description + + if (process.env.CONFIG.pronouns.plurals) { + extraFields += 1; + if (![0, 1].includes(parseInt(data[MORPHEMES.length]))) { + return null; + } + if (process.env.CONFIG.pronouns.honorifics) { + extraFields += 1; + if (![0, 1].includes(parseInt(data[MORPHEMES.length + 1]))) { + return null; + } + } + } + + if (data.length === MORPHEMES.length + extraFields - 1) { data.push(''); } - if (data.length !== MORPHEMES.length + 3 + if (data.length !== MORPHEMES.length + extraFields || data[0].length === 0 || data[data.length - 1].length > 48 - || ![0, 1].includes(parseInt(data[MORPHEMES.length])) - || ![0, 1].includes(parseInt(data[MORPHEMES.length + 1])) - || data.slice(1, data.length - 3).filter(s => s.length > 12).length + || data.slice(1, data.length - extraFields).filter(s => s.length > 12).length ) { return null; }