React-native-i18n: Check if key exists

Created on 12 Jul 2017  路  1Comment  路  Source: AlexanderZaytsev/react-native-i18n

Is there any available method to check if a key exists in the current language?
Currently if a key doesn't exist it returns a [missing "foo" translation], which I don't think its ideal.

Most helpful comment

You can use the in operator. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in

import en from './locales/en'

if ('key' in en) {
  // do something
}

>All comments

You can use the in operator. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in

import en from './locales/en'

if ('key' in en) {
  // do something
}
Was this page helpful?
0 / 5 - 0 ratings