Skip to content

fix(forms): explain all username rules in the dhis2Username message - #1797

Open
alexcpn wants to merge 1 commit into
dhis2:masterfrom
alexcpn:LIBS-637/username-validation-message
Open

alexcpn wants to merge 1 commit into
dhis2:masterfrom
alexcpn:LIBS-637/username-validation-message

Conversation

@alexcpn

@alexcpn alexcpn commented Nov 26, 2026 •

Copy link
Copy Markdown

Implements LIBS-637


Description

dhis2Username only accepts unaccented letters a-z/A-Z, digits and the separators . _ - @, and it rejects a separator at the start or end or two separators in a row. The error message only said:

Please provide a username between 4 and 255 characters long and possibly separated by . _ - or @

So a user typing josé.silva or a Cyrillic or Japanese name got no hint about what was wrong. The new message is:

Please provide a username between 4 and 255 characters long, using only letters a-z or A-Z without accents, digits 0-9 and the separators . _ - @. A username cannot start or end with a separator or have two separators in a row

The validation rule itself is unchanged.

Side fix, i18n extraction: with a literal _ in the string, the extractor treated the text after _ as a context. en.pot therefore had msgctxt " - or @" and a truncated msgid ending in separated by . , which is what translators saw on Transifex. The separators are now passed as an interpolated value ({{separators}}, the same pattern as the other validators in this folder), so en.pot gets the full message with no msgctxt. en.pot was regenerated with d2-app-scripts i18n extract.

How it was tested

  • New tests check that the message names the allowed letters (and "without accents"), digits, the separators, and the start/end/repeat rule. They fail on master and pass with this change.
  • Added josé.silva, пользователь and user name to the rejected-characters cases.
  • All 38 dhis2Username tests pass. eslint and prettier --check are clean.

Known issues

  • Because the msgid changed, existing translations of this message will show English until they are re-translated on Transifex.
  • The wording is my best attempt; happy to change it. For example, "unaccented letters" vs "English letters", or splitting it into one message per rule.

Checklist

  • API docs are generated
  • Tests were added
  • Storybook demos were added

No props changed. This is a validator message, so there's no API doc or Storybook change.


AI disclosure

This change was written and tested by an AI model, Claude Opus 5.5 (via Claude Code), and submitted by a human contributor.

#T4G (tokens for good project)

🤖 Generated with Claude Code

@alexcpn
alexcpn requested a review from a team as a code owner November 26, 2026 14:13
The validator only allows unaccented letters a-z/A-Z, digits and the
separators . _ - @, and rejects separators at the start or end or two in
a row. The message only mentioned the length and the separators, so
users with names like "josé" got no hint why their username was invalid.

The separators are now passed as an interpolated value: with a literal
`_` in the string, the i18n extractor split the message at the
underscore and put a truncated msgid in en.pot.

Implements LIBS-637

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexcpn
alexcpn force-pushed the LIBS-637/username-validation-message branch from d394639 to cc2aad8 Compare December 4, 2026 13:44
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant