From 375292a7ff74e0e2f3c45c89b1c55f7a99d28482 Mon Sep 17 00:00:00 2001 From: fkellner Date: Tue, 10 Sep 2024 14:31:53 +0200 Subject: [PATCH] geosolutions-it#10158: set HTML document language once per mount/update As requested, the document language is now set when the component is mounted or the language is changed instead of with every rerender. --- web/client/components/I18N/Localized.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/client/components/I18N/Localized.jsx b/web/client/components/I18N/Localized.jsx index 6b194d08af..12eecf448e 100644 --- a/web/client/components/I18N/Localized.jsx +++ b/web/client/components/I18N/Localized.jsx @@ -30,6 +30,16 @@ class Localized extends React.Component { }; } + componentDidMount() { + this.updateDocumentLangAttribute(); + } + + componentDidUpdate(prevProps) { + if (this.props.locale !== prevProps.locale) { + this.updateDocumentLangAttribute(); + } + } + render() { let { children } = this.props; @@ -37,7 +47,6 @@ class Localized extends React.Component { if (typeof children === 'function') { children = children(); } - document.documentElement.setAttribute("lang", this.props.locale); return (