-
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
Avoid page reload after interface language is changed #13712
Conversation
Removed code that triggers a refresh from the me/account form. Changing language now behaves like changing any other setting. Removed the redirect functionality from the me/form-base mixin, as it's no longer used anywhere. Also removed the 'changingUsername' property from the me/form-base state, as it seems to be a legacy property that's not used anywhere.
One idea how to solve the Currently, when .something {
margin-left: 10px;
} It's transformed by RTLCSS into a .something {
margin-right: 10px;
} What about splitting the rule into two and let them all live in one file? [dir=ltr] .something {
margin-left: 10px;
}
[dir=rtl] .something {
margin-right: 10px;
} I'm not sure if RTLCSS can do this, but I assume it shouldn't be hard to write a custom PostCSS plugin from scratch that does exactly this. |
Another place where the |
@@ -525,7 +516,7 @@ const Account = React.createClass( { | |||
onFocus={ this.recordFocusEvent( 'Interface Language Field' ) } | |||
valueKey="langSlug" | |||
value={ this.getUserSetting( 'language' ) || '' } | |||
onChange={ this.updateLanguage } | |||
onChange={ this.updateUsetSettingInput } |
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 is typo here updateUse*t*SettingInput
Closing as this PR is stale - please reopen if necessary |
The goal of this change is to avoid reloading the page after the interface language is changed and saved in the
me/account
form. Let's just refresh the UI in place by rerendering all React components that need to be updated!There are several problems that need to be solved to make this work.
First, all React components that use
i18n.translate
to localize strings need to translate them again and rerender. That will happen if the component uses thei18n.localize
HOC or thei18n.mixin
mixin. Both will be notified by thei18n
module and will callforceUpdate
.However, there are a few React components that call the
i18n.translate
function directly. (Just grep the sources to find them). These are not guaranteed to rerender. They will only if some parent callsforceUpdate
, and there is no intermediate component that would returnshouldComponentUpdate() == true
.Solution: migrate these
i18n.translate
callers to thelocalize
HOC.Then there are modules that call
i18n.translate
statically at module initializations. For these, the strings will never be translated again. I know about protect-form doing this, and there might be others.Second, there is some language-specific info that's rendered by the server into the index page that needs to be updated dynamically on language change. This is important mainly when switching between LTR and RTL languages:
<html>
element haslang
anddir
attributes that need to be changed<body>
element has anrtl
class when the language is RTLstyle.css
. For RTL, we loadstyle-rtl.css
, which is thestyle.css
processed by RTLCSS. We'll need to reload the stylesheet at runtime, or find a way to merge them into one. (This would be much easier if more browsers supported CSS logical properties likemargin-block-start
orborder-inline-end
. But except Firefox, they don't.)I pushed a commit that disables the page refresh on language change. It doesn't solve any of the problems mentioned above.