I18n-js - is there a way to check if a translation exists or not?

2.4k Views Asked by At

Is there a way to check if a translation exists or not with the library I18n-js?

1

There are 1 best solutions below

0
On BEST ANSWER

You can use the method lookup().

It returns undefined when the translation does not exist, so you can put it in your conditional.

For example:

if(!I18n.lookup('translation_key')) {
  console.log('Translation does not exist');
}
else {
  console.log('Translation does exist. Congrats.');
}