From 349663e40dd0eac9dbb7327e1181825b07cba580 Mon Sep 17 00:00:00 2001 From: alxndrsn Date: Wed, 26 Jul 2023 13:05:59 +0000 Subject: [PATCH 1/6] transifex: show clearer whitespace errors --- bin/util/transifex.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/util/transifex.js b/bin/util/transifex.js index d5b88ec11..57b04bb2b 100644 --- a/bin/util/transifex.js +++ b/bin/util/transifex.js @@ -72,15 +72,22 @@ const parseVars = (pluralForm) => { class PluralForms { static empty(length) { return new PluralForms(new Array(length).fill('')); } - static fromVueI18n(message) { + static fromVueI18n(path, message) { const forms = message.split(' | '); if (forms.length > 2) logThenThrow(message, 'a pluralized message must have exactly two forms'); for (const form of forms) { if (form.includes('|')) logThenThrow(message, 'unexpected |'); - if (/(^\s|\s$|\s\s)/.test(form)) - logThenThrow(message, 'unexpected white space'); + + const badWhitespace = form.match(/^\s+|\s+$|\s\s+/); + if (badWhitespace) { + const badLength = badWhitespace[0].length; + console.error(`unexpected white space in translation string '${path}':`); + console.error(` [${message}]`); + console.error(` [${''.padStart(badLength, '^').padStart(badWhitespace.index+badLength, ' ').padEnd(message.length, ' ')}]`); + throw new Error(`unexpected whitespace in message '${path}' at index ${badWhitespace.index} ("${message}")`); + } } return new PluralForms(forms); @@ -663,8 +670,8 @@ const rekeyTranslations = (source, translated, transifexPaths) => { // Returns the Vue I18n messages for the source locale after converting them to // PluralForms objects. const readSourceMessages = (localesDir, filenamesByComponent) => { - const reviver = (_, value) => - (typeof value === 'string' ? PluralForms.fromVueI18n(value) : value); + const reviver = (path, value) => + (typeof value === 'string' ? PluralForms.fromVueI18n(path, value) : value); // Read the root messages. const messages = parse( From 537d6afccbcb6b81112af6e0cc7467f5fe248230 Mon Sep 17 00:00:00 2001 From: alxndrsn Date: Wed, 26 Jul 2023 13:16:27 +0000 Subject: [PATCH 2/6] fix lint violations --- bin/util/transifex.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/util/transifex.js b/bin/util/transifex.js index 57b04bb2b..7a3ac4313 100644 --- a/bin/util/transifex.js +++ b/bin/util/transifex.js @@ -83,9 +83,9 @@ class PluralForms { const badWhitespace = form.match(/^\s+|\s+$|\s\s+/); if (badWhitespace) { const badLength = badWhitespace[0].length; - console.error(`unexpected white space in translation string '${path}':`); - console.error(` [${message}]`); - console.error(` [${''.padStart(badLength, '^').padStart(badWhitespace.index+badLength, ' ').padEnd(message.length, ' ')}]`); + console.error(`unexpected white space in translation string '${path}':`); // eslint-disable-line no-console + console.error(` [${message}]`); // eslint-disable-line no-console + console.error(` [${''.padStart(badLength, '^').padStart(badWhitespace.index + badLength, ' ').padEnd(message.length, ' ')}]`); // eslint-disable-line no-console throw new Error(`unexpected whitespace in message '${path}' at index ${badWhitespace.index} ("${message}")`); } } From 72d660d9020267fbc3da836c0ca80d2b3d761be2 Mon Sep 17 00:00:00 2001 From: alxndrsn Date: Wed, 6 Sep 2023 08:33:17 +0000 Subject: [PATCH 3/6] rename path as key --- bin/util/transifex.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/util/transifex.js b/bin/util/transifex.js index 7a3ac4313..9cf81b4de 100644 --- a/bin/util/transifex.js +++ b/bin/util/transifex.js @@ -72,7 +72,7 @@ const parseVars = (pluralForm) => { class PluralForms { static empty(length) { return new PluralForms(new Array(length).fill('')); } - static fromVueI18n(path, message) { + static fromVueI18n(key, message) { const forms = message.split(' | '); if (forms.length > 2) logThenThrow(message, 'a pluralized message must have exactly two forms'); @@ -83,10 +83,10 @@ class PluralForms { const badWhitespace = form.match(/^\s+|\s+$|\s\s+/); if (badWhitespace) { const badLength = badWhitespace[0].length; - console.error(`unexpected white space in translation string '${path}':`); // eslint-disable-line no-console + console.error(`unexpected white space in translation string '${key}':`); // eslint-disable-line no-console console.error(` [${message}]`); // eslint-disable-line no-console console.error(` [${''.padStart(badLength, '^').padStart(badWhitespace.index + badLength, ' ').padEnd(message.length, ' ')}]`); // eslint-disable-line no-console - throw new Error(`unexpected whitespace in message '${path}' at index ${badWhitespace.index} ("${message}")`); + throw new Error(`unexpected whitespace in message '${key}' at index ${badWhitespace.index} ("${message}")`); } } @@ -670,8 +670,8 @@ const rekeyTranslations = (source, translated, transifexPaths) => { // Returns the Vue I18n messages for the source locale after converting them to // PluralForms objects. const readSourceMessages = (localesDir, filenamesByComponent) => { - const reviver = (path, value) => - (typeof value === 'string' ? PluralForms.fromVueI18n(path, value) : value); + const reviver = (key, value) => + (typeof value === 'string' ? PluralForms.fromVueI18n(key, value) : value); // Read the root messages. const messages = parse( From f47d54a5a98ca9fda928942bad806f07d737dd2e Mon Sep 17 00:00:00 2001 From: alxndrsn Date: Wed, 6 Sep 2023 08:53:21 +0000 Subject: [PATCH 4/6] Fix plural errors --- bin/util/transifex.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/util/transifex.js b/bin/util/transifex.js index 9cf81b4de..2a9fd62ef 100644 --- a/bin/util/transifex.js +++ b/bin/util/transifex.js @@ -77,16 +77,19 @@ class PluralForms { if (forms.length > 2) logThenThrow(message, 'a pluralized message must have exactly two forms'); - for (const form of forms) { + for (let i=0; i Date: Wed, 6 Sep 2023 09:21:29 +0000 Subject: [PATCH 5/6] fix lint violations --- bin/util/transifex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/util/transifex.js b/bin/util/transifex.js index 2a9fd62ef..a0d1f8da8 100644 --- a/bin/util/transifex.js +++ b/bin/util/transifex.js @@ -77,7 +77,7 @@ class PluralForms { if (forms.length > 2) logThenThrow(message, 'a pluralized message must have exactly two forms'); - for (let i=0; i Date: Wed, 6 Sep 2023 09:23:59 +0000 Subject: [PATCH 6/6] try again --- bin/util/transifex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/util/transifex.js b/bin/util/transifex.js index a0d1f8da8..276aede1d 100644 --- a/bin/util/transifex.js +++ b/bin/util/transifex.js @@ -77,7 +77,7 @@ class PluralForms { if (forms.length > 2) logThenThrow(message, 'a pluralized message must have exactly two forms'); - for (let i = 0; i < forms.length; i = i + 1) { + for (let i = 0; i < forms.length; i += 1) { const form = forms[i]; if (form.includes('|')) logThenThrow(message, 'unexpected |');