From 7bc7c4013eb2fa4facb2c4588c2a40450b008fa1 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Wed, 20 Jan 2021 14:22:52 +0530 Subject: [PATCH] simplified pluralization logic --- assets/javascripts/wizard/helpers/char-counter.js.es6 | 9 ++++----- config/locales/client.en.yml | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/wizard/helpers/char-counter.js.es6 b/assets/javascripts/wizard/helpers/char-counter.js.es6 index 4cc12463..c27c0818 100644 --- a/assets/javascripts/wizard/helpers/char-counter.js.es6 +++ b/assets/javascripts/wizard/helpers/char-counter.js.es6 @@ -3,14 +3,13 @@ import I18n from "I18n"; export default registerUnbound("char-counter", function(body, maxLength) { let bodyLength = body ? body.length : 0; - let length = maxLength || bodyLength; - let characterString = length == 1 ? 'wizard.character' : 'wizard.characters'; let finalString; - if(maxLength) { - finalString = `
${bodyLength} / ${maxLength} ${ I18n.t(characterString)}
`; + if (maxLength) { + finalString = `
${bodyLength} / ${I18n.t('wizard.x_characters', { count: parseInt(maxLength) })}
`; } else { - finalString = `
${bodyLength} ${ I18n.t(characterString)}
`; + finalString = `
${I18n.t('wizard.x_characters', { count: parseInt(bodyLength) })}
`; } + return new Handlebars.SafeString(finalString); }); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index fef9c870..28304120 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -471,8 +471,9 @@ en: requires_login: "You need to be logged in to access this wizard." reset: "Reset this wizard." step_not_permitted: "You're not permitted to view this step." - characters: "Characters" - character: "Character" + x_characters: + one: "%{count} Character" + other: "%{count} Characters" wizard_composer: show_preview: "Preview Post"