Translate Widget: update layout to be responsive.#7296
Conversation
modules/widgets/google-translate.php
Outdated
| * | ||
| * @param string $layout layout of the Google Translate Widget. | ||
| */ | ||
| 'layout' => esc_js( apply_filters( 'jetpack_google_translate_widget_layout', '' ) ), |
There was a problem hiding this comment.
On one hand, this is incompatible with what google.translate.TranslateElement accepts for the layout property, it accepts a number, not a string.
Logging in console:
google.translate.TranslateElement.InlineLayout.VERTICAL throws 0
google.translate.TranslateElement.InlineLayout.HORIZONTAL throws 1
google.translate.TranslateElement.InlineLayout.SIMPLE throws 2
So this filter should accept a number and validate that number. Otherwise a method should be devised in JS to parse the route received as string and resolve it in the google object to get the right value.
However, this is very cumbersome for users. I'd rather have a <select> controls that user can pull to choose the desired layout.
There was a problem hiding this comment.
That makes sense. I don't know that we need a UI for this though; we don't really receive requests for that option.
I updated the PR to validate the filter and only accept integers between 0 and 2. If anything else, we fallback to the default.
Fixes #5962 This commit includes 2 changes: 1. Change the default layout of the widget displayed by Google. Until now the widget used the "Dropdown Only" mode. It now uses the "Vertical" mode. This layout is more compatible with mobile devices. 2. Create a new filter, `jetpack_google_translate_widget_layout`, allowing one to switch between layouts if needed.
38cf641 to
f54e3d0
Compare
Fixes #5962 again. When I worked on #7296 to first fix this issue, I wanted to change from the old unresponsive dropdown only layout (`2`) to the new vertical layout that would be responsive (`0`). But while addressing other feedback on the PR I reverted that change, ant the old layout remained the default. This fixes that. The default is 0 (vertical layout) now.
Fixes #5962 again. When I worked on #7296 to first fix this issue, I wanted to change from the old unresponsive dropdown only layout (`2`) to the new vertical layout that would be responsive (`0`). But while addressing other feedback on the PR I reverted that change, ant the old layout remained the default. This fixes that. The default is 0 (vertical layout) now.
Fixes #5962
Changes proposed in this Pull Request:
This PR includes 2 changes:
the "Vertical" mode. This layout is more compatible with mobile devices.
jetpack_google_translate_widget_layout, allowing one to switch between layouts if needed:Before:
After:
Testing instructions:
google.translate.TranslateElement.InlineLayout.HORIZONTALstring for another layout.Proposed changelog entry for your changes: