Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character Count component throws error with missing plural text #2918

Closed
colinrotherham opened this issue Oct 13, 2022 · 0 comments · Fixed by #2921
Closed

Character Count component throws error with missing plural text #2918

colinrotherham opened this issue Oct 13, 2022 · 0 comments · Fixed by #2921
Assignees
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) character count 🕔 hours A well understood issue which we expect to take less than a day to resolve. javascript
Milestone

Comments

@colinrotherham
Copy link
Contributor

colinrotherham commented Oct 13, 2022

Description of the issue

The Character Count component is undergoing some localisation changes:

  1. Allow CharacterCount component to receive i18n config via JS #2887
  2. Add macro options to configure CharacterCount translations #2895

After the v4.3.1 → v4.4.0 upgrade, Character Counts might run as a different locale than intended.

This is a problem because we throw new Error() when the "new" locale's text can't be found:
https://github.com/alphagov/govuk-frontend/blob/main/src/govuk/i18n.mjs#L49

// Throw an error if this new key doesn't exist
if (!(lookupKey in this.translations)) {
  throw new Error('i18n: Plural form "' + pluralSuffix + '" is required for "' + this.locale + '" locale')
}

Teams may miss this issue because the error is only thrown when approaching the character limit.

Steps to reproduce the issue

  1. Upgrade to (future release) govuk-frontend@4.4.0
  2. Open the JavaScript console to watch for error messages
  3. Type into a Character Count component on a Welsh cy-GB (or other locale) page
  4. See errors are logged for missing plural forms "Many", "Few" and "Two"

Note: This can be triggered on the Translated page /examples/translated by setting <html lang="cy-GB"> before the JavaScript runs. You can do this with {% set htmlLang = 'cy-GB' %} in the Translated page template

Added a video demonstration from @36degrees:

Error.thrown.for.missing.plural.forms.when.approaching.character.limit.mp4

Actual vs expected behaviour

Actual behaviour

  1. Localised text doesn't display for plural forms "Many", "Few" and "Two"
  2. Error is thrown to the JavaScript console

Expected behaviour

  1. Localised text stays in English as it did in govuk-frontend@4.3.1 pre-upgrade
  2. Error is logged (but not thrown) to the JavaScript console for missing plural forms

Where the minimum "One" and "Other" text strings are available in the newly detected locale, could we avoid an English fallback despite the full suite of "Many", "Few" and "Two" plural forms are missing?

@colinrotherham colinrotherham added 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) 🕔 hours A well understood issue which we expect to take less than a day to resolve. javascript character count Frontend squad labels Oct 13, 2022
@colinrotherham colinrotherham added this to the v4.4.0 milestone Oct 13, 2022
@colinrotherham colinrotherham added this to Backlog 🗄 in Design System Sprint Board via automation Oct 13, 2022
@36degrees 36degrees self-assigned this Oct 14, 2022
@36degrees 36degrees moved this from Backlog 🗄 to In progress 📝 in Design System Sprint Board Oct 14, 2022
@36degrees 36degrees moved this from In progress 📝 to Needs review 🔍 in Design System Sprint Board Oct 14, 2022
@36degrees 36degrees moved this from Needs review 🔍 to Ready to release 🚀 in Design System Sprint Board Oct 21, 2022
@36degrees 36degrees moved this from Ready to release 🚀 to Done 🏁 in Design System Sprint Board Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) character count 🕔 hours A well understood issue which we expect to take less than a day to resolve. javascript
Projects
Development

Successfully merging a pull request may close this issue.

2 participants