I have a React-Native app that aims to do multilingual support.
It uses Relay
, so I have code like this above the root component.
Relay.injectNetworkLayer(new DefaultNetworkLayer("http://localhost/graphql"))
Now, the language parameter is passed via parameter as Facebook does it with their Graph API.
Relay.injectNetworkLayer(new DefaultNetworkLayer("http://localhost/graphql?locale=en_US"))
How can I change this on the fly when the app's language can be changed from the settings? And how would one, in a sense, restart the app with those language changes?
I might just be confusing myself by trying to implement for the first time relay
and react-native-router-flux
at the same time....
This is the root container code in its entirety:
import Relay, {
DefaultNetworkLayer,
RootContainer,
} from 'react-relay'
import RelayRenderer from 'rnrf-relay-renderer'
import {
Actions,
Reducer,
Router,
Scene
} from 'react-native-router-flux'
const locale = `en_US`
Relay.injectNetworkLayer(new DefaultNetworkLayer(`http://localhost/graphql?locale=${locale}`))
const reducerCreate = params => {
const defaultReducer = Reducer(params)
return (state, action) => {
return defaultReducer(state, action)
}
}
}
export default class App extends Component {
render() {
return (
<Router
createReducer={reducerCreate}
wrapBy={RelayRenderer()}
>
...
...
</Router>
)
}
}