React-native-router-flux: Navbar title - translation

Created on 4 Dec 2017  路  6Comments  路  Source: aksonov/react-native-router-flux

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?

Most helpful comment

Try to pass function instead of value.

All 6 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sylvainbaronnet picture sylvainbaronnet  路  3Comments

booboothefool picture booboothefool  路  3Comments

moaxaca picture moaxaca  路  3Comments

wootwoot1234 picture wootwoot1234  路  3Comments

YouYII picture YouYII  路  3Comments