return locals;
happens before your promise returns and so will be undefined
. You need to use a callback:
export default locales = (callback) => {
Expo.DangerZone.Localization.getCurrentLocaleAsync().then((value) => {
return callback(value);
});
}
then you can access the value like this:
your_module.locales((locals)=>{
// use locals here
});
or, if you have access to async/await in newer versions of node:
export default locales = async () => {
let value = await Expo.DangerZone.Localization.getCurrentLocaleAsync()
return value;
}
and then you would call the function like this:
let locals = await your_module.locales()
but, considering there is a function Expo.DangerZone.Localization.getCurrentLocaleAsync()
are you sure a synchronous version, getCurrentLocaleSync()
or getCurrentLocale()
don't exist? That would make this much easier you could just call the function directly and obtain the value.