Skip to content

[Question] How to check if translation string/id exists? #747

@tswardenski

Description

@tswardenski

I have a bit of an odd scenario where I'm displaying a list of mixed values; some system default string values that need to be translated, and some user defined strings that shouldn't be translated.

I've gone through the docs a handful of times to see if there's a "pretty" way to check if a translation string ID exists and I ended up just implementing:

if (formatMessage({ id: `some.key.${value}` }) !== `some.key.${value}`) { 
  // do stuff
}
else {
 // do other stuff
}

I don't like this method as it ends up giving me a TON of console errors. I'm wondering if there's a better way to do this. Any direction is appreciated!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions