Last active
December 10, 2021 07:26
-
-
Save BrianJVarley/9629f1ebc8969e7cf5fc7d1ce94c49e1 to your computer and use it in GitHub Desktop.
Mocking react-native-localization package in jest spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES6 module syntax | |
import LocalizedStrings from 'react-native-localization'; | |
let AppStrings = new LocalizedStrings({ | |
'en-US': { | |
settingMenuOptionOne: 'Centimeters ({0})', | |
}, | |
en: { | |
settingMenuOptionOne: 'Centimeters ({0})', | |
}, | |
it: | |
{ | |
} | |
}); | |
module.exports = AppStrings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class RNLocalization { | |
_language = 'en'; | |
constructor(props) { | |
this.props = props; | |
this._setLanguage(this._language); | |
} | |
_setLanguage(interfaceLanguage) { | |
this._language = interfaceLanguage; | |
if (this.props[interfaceLanguage]) { | |
const localizedStrings = this.props[this._language]; | |
for (const key in localizedStrings) { | |
if (localizedStrings.hasOwnProperty(key)) { | |
this[key] = localizedStrings[key]; | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment