Skip to content

Best practice for user input text (i18n) #315

Closed Answered by gabro
mperrando asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @mperrando, it's correct, LocalizedString is there to ensure you don't forget localizing a component, but if you're sure this is user generated content you can definitely use unsafeLocalizedString.

Two more things:

  • if these strings come from an external source, you may want to validate those and convert them to LocalizedString during the validation (e.g. using something like https://github.com/colinhacks/zod)

  • I would recommend to limit the number of unsafeLocalizedString around the app, so if possible I would create a dedicated component like UserGeneratedLabel or something, which accepts string and wraps the actual unsafeLocalizedString usage

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mperrando
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants