-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set html lang attribute from language setting #5685
Conversation
src/vector/index.html
Outdated
@@ -1,5 +1,5 @@ | |||
<!doctype html> | |||
<html lang="en" style="height: 100%;"> | |||
<html id="root" lang="en" style="height: 100%;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why adding a redundant id instead of using document.getElementsByTagName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason other than I thought that might be more explicit. I wasn't sure which would be more ideal. I can go ahead and change this to use document.getElementsByTagName
instead if that is preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a chance that home.html
, when opened, contains extra html
tags. To prevent conflicts, assigning an id is probably best. Although I'd prefix it to avoid more conflicts (eg mx_PageRoot
).
src/vector/index.js
Outdated
@@ -382,6 +382,7 @@ async function loadLanguage() { | |||
} | |||
try { | |||
await languageHandler.setLanguage(langs); | |||
document.getElementById("root").setAttribute("lang", languageHandler.getCurrentLanguage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should propably be done in matrix-react-sdk inside the languageHandler.js. Otherwise it doesn't get changed if the user changes the language in the settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is true, and then even more evidently you can't rely on the outermost html element having an id since riot isn't the only consumer of matrix-react-sdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You actually want document.documentElement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MTRNord Are you sure? Doesn't the entire page get reloaded when you change language, and, thus, loadLanguage()
would be called again, updating the attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafcu well the current would propably need a refactor as soon as the translation change uses states instead a full reload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MTRNord And the "put it into the sdk" would need a refactor as soon as the split between the sdk and riot-web is made more clear.
Perhaps the correct approach is to fire a languageChanged
event that the application can listen to. But considering how small the current proposed change is, I'd say use it as is, and change it if and when someone implements something more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafcu what about putting this (in another PR) inside a promise returned from setLanguage()? That would propably make more sense to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that solve the issue of an app-developer only wanting to change the language of the matrix-specifc part of their page, rather than the entire page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafcu no but the issue that a reload might not happen in the future on language changes. (Thats what my point is)
Change the root <html> element id to follow Matrix naming conventions.
src/vector/index.js
Outdated
@@ -382,6 +382,7 @@ async function loadLanguage() { | |||
} | |||
try { | |||
await languageHandler.setLanguage(langs); | |||
document.getElementById("mx_PageRoot").setAttribute("lang", languageHandler.getCurrentLanguage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a special id, you should just use document.documentElement
. That way you don't need to add any id to the <html>
element at all.
Use documentElement to get the root <html> element instead of adding an id to the root element.
I can't make sense of the Travis CI failure, so I don't know what I broke. |
@aidalgol I don't think you actually broke it. It looks more like a problem with Travis? Perhaps someone with admin access to this repository could try to re-run the tests. |
I restarted it but its still failing, I'll take a look at it now |
@t3chguy looks like that some deps failed to install. Propably a timing issue :/ (and not related to this change) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
Fixes #5662. (Trivial two-line change.)
Signed-off-by: Aidan Gauland [email protected]