-
-
Save ronal2do/12a680942774ff6ee0bdd3cc9c8b62aa 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