Skip to content

Commit

Permalink
geosolutions-it#10158: set HTML document language once per mount/update
Browse files Browse the repository at this point in the history
now with eslint fixes
  • Loading branch information
fkellner authored Sep 10, 2024
1 parent fed18c5 commit b05cd29
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions web/client/components/I18N/Localized.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ class Localized extends React.Component {
};
}

componentDidMount() {
this.updateDocumentLangAttribute();
}

componentDidUpdate(prevProps) {
if (this.props.locale !== prevProps.locale) {
this.updateDocumentLangAttribute();
}
}

updateDocumentLangAttribute() {
if (document?.documentElement) {
document.documentElement.setAttribute("lang", this.props.locale);
}
}

render() {
let { children } = this.props;

Expand All @@ -50,22 +66,6 @@ class Localized extends React.Component {
return null;
}

componentDidMount() {
this.updateDocumentLangAttribute();
}

componentDidUpdate(prevProps) {
if (this.props.locale !== prevProps.locale) {
this.updateDocumentLangAttribute();
}
}

updateDocumentLangAttribute() {
if (document?.documentElement) {
document.documentElement.setAttribute("lang", this.props.locale);
}
}

flattenMessages = (messages, prefix = '') => {
return Object.keys(messages).reduce((previous, current) => {
return typeof messages[current] === 'string' ? {
Expand Down

0 comments on commit b05cd29

Please sign in to comment.