Skip to content

Commit

Permalink
geosolutions-it#10158: set HTML document language
Browse files Browse the repository at this point in the history
On Behalf of DB Systel
  • Loading branch information
Florian Kellner committed Apr 4, 2024
1 parent bbfa7d7 commit f7db699
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/client/components/I18N/Localized.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Localized extends React.Component {
if (typeof children === 'function') {
children = children();
}
document.documentElement.setAttribute("lang", this.props.locale);

return (<IntlProvider key={this.props.locale} locale={this.props.locale}
messages={this.flattenMessages(this.props.messages)}
Expand Down
15 changes: 15 additions & 0 deletions web/client/components/I18N/__tests__/Localized-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ describe('Test the localization support HOC', () => {
expect(dom.innerHTML).toBe("my message");
});

it('correctly sets the document language', () => {
ReactDOM.render(
<Localized locale="it-IT" messages={messages}>
{() => <Message msgId="testMsg"/> }
</Localized>
, document.getElementById("container"));
expect(document.documentElement.lang).toBe("it-IT");
ReactDOM.render(
<Localized locale="de-DE" messages={messages}>
{() => <Message msgId="testMsg"/> }
</Localized>
, document.getElementById("container"));
expect(document.documentElement.lang).toBe("de-DE");
});

it('localizes wrapped HTML component', () => {
var localized = ReactDOM.render(
<Localized locale="it-IT" messages={messages}>
Expand Down

0 comments on commit f7db699

Please sign in to comment.