I'm using i18n https://github.com/AlexanderZaytsev/react-native-i18n to translate our app.
I'm trying to implement a "hot reload" of the languages. The user selects a language and the UI updates. Now this works, but It doesn't work with the navbar titles. I have to restart the app in order for the changes to take effect.
my scenes are defined like this:
<Scene hideNavBar={false}
gestureEnabled={true}
gestureResponseDistance={{horizontal: 50}}
renderBackButton={renderBackButton} key="settings"
rerender={this.state.rerender}
{...styles} component={Settings}
title={I18n.t('settings')}/>
I'm triggering a rerender in the component that defines the scenes. A console.log of I18n.t('settings') shows the translated string, but the title is not translated. Same applies to tab titles.
Is there a way to refresh the titles without having to rely on refreshing in componentWillMount in the component itself. I have defined like 40 scenes and it would be stupid to have to use componentWillMount to update the title?
Try to pass function instead of value.
@compojoom As a workaround, You can re-render top-level component which contains Router component with whole navigation tree, then probably all title props will be recalculated?
Closed due inactivity
@aksonov - thanks. Using a function for the titles worked.
I used this and it worked.
<Scene hideNavBar={false}
gestureEnabled={true}
gestureResponseDistance={{horizontal: 50}}
renderBackButton={renderBackButton} key="settings"
rerender={this.state.rerender}
{...styles} component={Settings}
title={() => I18n.t('settings')}/>
Try to pass function instead of value.
hey @aksonov , this was exactly what i was looking for. Thanks very much
Most helpful comment
Try to pass function instead of value.