From b05cd29fca93ae4524e11fa87266c6c88e97d14e Mon Sep 17 00:00:00 2001 From: fkellner Date: Tue, 10 Sep 2024 14:37:56 +0200 Subject: [PATCH] geosolutions-it#10158: set HTML document language once per mount/update now with eslint fixes --- web/client/components/I18N/Localized.jsx | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/web/client/components/I18N/Localized.jsx b/web/client/components/I18N/Localized.jsx index 8473efee2b..b5adbccfe8 100644 --- a/web/client/components/I18N/Localized.jsx +++ b/web/client/components/I18N/Localized.jsx @@ -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; @@ -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' ? {