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.

initialize() and setActiveLanguage() take some time

See original GitHub issue

I need to fetch data via REST API according to the active language.

When I set the language using the standard Toggle component from the docs, and right after that send a query (parametrized using activeLanguage.code) to the API, the old language still applies. It seems like setActiveLanguage() (and intialize() as well) takes a little time to finish and works async.

It would be great if there was either some way to determine when these methods finisch their jobs (may something like a JS Promise) or if you could tell them to run synchronously.

I’m using react 16.8.6 and react-localize-redux 3.5.2

I hope I didn’t miss something very basic.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Myreagecommented, May 2, 2019

Hey I have quite the same problem with addTranslation, here’s my use case :

I’m loading several translation files with get requests, use addTranslation for each of them, then set translationsLoaded to true when it’s all done.

Sadly, translationsLoaded is set to true before the translations are added.

const transLoading = filesTranslationBrand.map((fileTranslation) => {
          axios.get(remote_translate_files_url)
            .then(res => { this.props.addTranslation(res.data); }) 
            .catch(err => { console.log(err); });           
        })
Promise.all(transLoading).then(() => this.setState({translationsLoaded:true}))             
1reaction
robfuscatorcommented, Apr 5, 2019

Sadly I don’t have that much time right now. But simply put I have a class component, where I initialize your library using the initialize() method. When I log the activeLanguage prop every time my component gets rendered, the first log is always undefined while every following log correctly shows the activeLanguage object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

getting-started – React Localize Redux Documentation
For your component to have access to the initialize prop you'll need to use the withLocalize higher-order component. Add translation data. To add...
Read more >
UMLLanguageManager - IBM
Retrieves the language descriptor initialized with the given context. ... public IUMLLanguageDescriptor getActiveDescriptor().
Read more >
[ABMaterial] 1.09 Localization using dynamic pages | B4X ...
As described in Part 1, dynamic pages was a must-have if you want to do ... The 'clientx' part is the param you...
Read more >
Solved: What is the specific use of gr.initialize()? - ServiceNow
insert();. So, for current GlideRecord, is there no need for initialize function? Then why is gr.initialize() specifically used?
Read more >
Index of all elements
HTML attributes of the select and the option tags; autoConv: in file I18Nv2.php, method I18Nv2::autoConv() Automatically transform output between character ...
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