Can't setActiveLanguage
See original GitHub issueI have the locale
reducer set :
import { localeReducer as locale } from 'react-localize-redux';
combineReducers({ locale, otherReducers});
The languages initialized:
const languageToUse = 'en';
const languages = ['en', 'fr'];
store.dispatch(initialize(languages));
const json = require('../static/texts/global.locale.json');
store.dispatch(addTranslation(json));
store.dispatch(setActiveLanguage(languageToUse));
And the function mapped to the props:
import { getTranslate, getActiveLanguage, setActiveLanguage } from 'react-localize-redux';
function mapStateToProps(state) {
return {
restOfState: state.restOfState,
translate: getTranslate(state.locale),
currentLanguage: getActiveLanguage(state.locale).code,
setActiveLanguage: setActiveLanguage,
};
}
export default mapStateToProps;
However calling this.props.setActiveLanguage('fr')
in a connected component does not change anything (logging this.props.currentLanguage
). Is this an issue or am I missing something?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
getting-started – React Localize Redux Documentation
Use the setActiveLanguage method to change localize's active language. ... i.e. You cannot pass a React component to a string like "<strong>Hello</strong> ...
Read more >Keep getting the error MissingTranslationId - Stack Overflow
... react-localize-redux but I cannot create a tag for it yet. ... setActiveLanguage("es"); // Although Spanish was added first in the list ...
Read more >Add an API to set active language [#2849464] | Drupal.org
The root of the issue is that Title module can't properly determine the active language, since it has no clue about routes (e.g....
Read more >How to use setActiveLanguage function in react-localize-redux
changeLang(code) { this.props.dispatch(setActiveLanguage((languages.indexOf(code) !== -1) ? code : 'ru'));
Read more >Factory method does not create objects properly| JBoss.org Content ...
getIdentifier()); setActiveLanguage(xl); log.info("initActiveLanguage(1): ... It works for me now, but I can't really recall how I solved the problem ...
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
@Vict0rSch sorry missed that in original source you provided. The action creators need to be added to connect like you would any other dispatch props.
So all Action Creators would go in
dispatchProps
, while all Selectors would go instateProps
.Then in MyComponent you’d have access to
this.props.setActiveLanguage
.Ok that wokrs. Thanks a lot for your help 😃 Very useful and well done package btw!