How to change language based of mobx/redux?
See original GitHub issueI am using i18n to supply translations to my project, currently it will translate based on browser language. I want it to instead of that change the language based on a property in a mobx store.
I have tried looking into react-mobx-i18n
, and it seems like a bad solution. Because I would have to annotate every single component as translatable and restructure everything.
I am using a file for each language, so far I have four languages
import i18n from 'i18next'
import en from './en.json'
import fr from './fr.json'
i18n
.init({
fallbackLng: 'en',
resources: {
en:
},
ns: ['application'],
defaultNS: 'application',
en: en,
fr: fr
react: {
wait: true,
},
})
export default i18n
here is the render of my App.js
import React, { Component } from 'react';
import { I18nextProvider } from 'react-i18next'
import i18n from './i18n'
import { Provider } from 'mobx-react'
export default class App extends Component {
render() {
return (
<Provider {...this.props.stores}> //mobx stores
<I18nextProvider i18n={i18n}>
//router want to change mobx-state and rerender everything with a new language
</I18nextProvider>
</Provider>
)
}
}
en.json
{
"application" : {
"hello": "hello"
}
}
fr.json
{
"application" : {
"hello": "bonjour"
}
}
I would like to somehow make i18n subscribe to my mobx state and update when a new language is detected. Should this be impossible, then I would like to write a handler in a store to change the language based on some input.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Use Firefox in another language - Mozilla Support
Click Select more languages to add and choose the languages you want to add, then click the Add button.
Read more >Change your personal language and region settings
To change your personal language and region settings Select My Office profile and then Update profile. Select How can I change language and...
Read more >Change app language on your Android phone - Google Support
Change the language setting for a specific app. On your Android phone, open your Settings app. Tap System and then Languages & input...
Read more >redux alternatives
The caveat here is that each time any part of the state changes, ... Alternatively, view redux-devtools alternatives based on common mentions on...
Read more >Change the language on your iPhone or iPad - Apple Support
You can change the language setting on your iPhone or iPad if it's incorrect or if you've accidentally changed the language to one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you try to just require/import your i18n file and call the changeLanguage function from wherever you want?
@sanketdeshmukh19 https://github.com/i18next/react-i18next/issues/924