question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to change language based of mobx/redux?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
adraicommented, Aug 14, 2019

Can you try to just require/import your i18n file and call the changeLanguage function from wherever you want?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found