Skip to content

Commit

Permalink
#10351: A saved map returns to the default state when the translation…
Browse files Browse the repository at this point in the history
… is changed (#10405)
  • Loading branch information
mahmoudadel54 authored Jun 11, 2024
1 parent cc4d494 commit efd006f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions web/client/components/I18N/Localized.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class Localized extends React.Component {
static propTypes = {
locale: PropTypes.string,
messages: PropTypes.object,
loadingError: PropTypes.string
loadingError: PropTypes.string,
localeKey: PropTypes.bool
};

static childContextTypes = {
locale: PropTypes.string,
messages: PropTypes.object
messages: PropTypes.object,
localeKey: true
};

getChildContext() {
Expand All @@ -38,7 +40,7 @@ class Localized extends React.Component {
children = children();
}

return (<IntlProvider key={this.props.locale} locale={this.props.locale}
return (<IntlProvider {...this.props.localeKey && { key: this.props.locale }} locale={this.props.locale}
messages={this.flattenMessages(this.props.messages)}
>
{children}
Expand Down
16 changes: 12 additions & 4 deletions web/client/components/app/StandardRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ class StandardRouter extends React.Component {
<div className={this.props.className}>

<ThemeProvider {...this.props.themeCfg} version={this.props.version} onLoad={this.props.onThemeLoaded}>
{this.props.themeLoaded ? (<Localized messages={this.props.locale.messages} locale={this.props.locale.current} loadingError={this.props.locale.localeError}>
{this.props.themeLoaded ? (<Localized localeKey={false} messages={this.props.locale.messages} locale={this.props.locale.current} loadingError={this.props.locale.localeError}>
<ConnectedRouter history={history}>
<div className="error-container">
{/** the key is moved from the above Localized to the next div after 'ConnectedRouter':
* to ensure the reload of children
* to avoid and prevent firing LOCATION_CHANGE action that caused reset map state in change locale
*/}
<div key={this.props.locale.current} className="error-container">
<ErrorBoundary
onError={e => {
/* eslint-disable no-console */
Expand All @@ -94,9 +98,13 @@ class StandardRouter extends React.Component {
return (
<div className={this.props.className}>
<Theme {...this.props.themeCfg} version={this.props.version}/>
<Localized messages={this.props.locale.messages} locale={this.props.locale.current} loadingError={this.props.locale.localeError}>
<Localized localeKey={false} messages={this.props.locale.messages} locale={this.props.locale.current} loadingError={this.props.locale.localeError}>
<ConnectedRouter history={history}>
<div className="error-container">
{/** the key is moved from the above Localized to the next div after 'ConnectedRouter':
* to ensure the reload of children
* to avoid and prevent firing LOCATION_CHANGE action that caused reset map state in change locale
*/}
<div key={this.props.locale.current} className="error-container">
<ErrorBoundary
onError={e => {
/* eslint-disable no-console */
Expand Down

0 comments on commit efd006f

Please sign in to comment.