Skip to content
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

Update locale forwarding via path #61

Conversation

sarayourfriend
Copy link

@sarayourfriend sarayourfriend commented Feb 15, 2022

https://meta.trac.wordpress.org/ticket/6105

Forwards the locale via the iframe's path rather than relying on a cookie.

To test, follow setup instructions in the README of the wporg-openverse theme. Set the "Use path based locale forwarding" setting to on by checking the box in the customizer. And redirect the iframe to use staging or localhost as production does not yet support path based locales.

Next, to test that the locales are working, replace the call to get_locale() with a wp_locale string (like pt_BR etc) to verify that it is working to forward the locale as expected (as far as I know there's no way to test this "for real" locally as subdomain locale choosing isn't supported in the local wp-env when I tried it).

Be sure to navigate around the various pages of the application. Pay special attention to the URL being shown in the host frame. It should never include the locale slug.

Next, test it with the en_US locale and make sure everything works, again paying attention to the locale slug.

Finally, turn off the path based locale forwarding setting and switch the frame back to production. Ensure that it continues to work as expected, especially the host frame URL updates. I'm not sure how to test other locales other than again, manually replacing the call to get_locale() with a locale string of choice. I noticed that it takes at least one page navigation for the locale to actually propagate via the cookie. This is the same as the behavior on trunk.

@sarayourfriend
Copy link
Author

cc @WordPress/openverse-developers

@sarayourfriend
Copy link
Author

Before merging this it needs the new functionality to be put behind a theme setting.

@sarayourfriend sarayourfriend marked this pull request as draft February 16, 2022 18:24
@sarayourfriend sarayourfriend force-pushed the update/openverse-locale-forwarding branch from dd98c6d to fc433fc Compare February 16, 2022 19:02
@sarayourfriend sarayourfriend marked this pull request as ready for review February 16, 2022 19:11
@sarayourfriend
Copy link
Author

Okay this is ready for review now. @WordPress/openverse-developers please take a look at this, thanks!

@@ -5,7 +5,7 @@ document.addEventListener('DOMContentLoaded', () => {
.toLocaleLowerCase()
.replace(openverseSubpath, '')
.replace(/^\/$/, ''); // Remove Openverse site subpath
iframePath = `${openverseUrl}${iframePath}${query}`; // Add domain and query
iframePath = `${openverseUrl}${localeSlug ? `/${localeSlug}` : ''}${iframePath}${query}`; // Add domain and query
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
iframePath = `${openverseUrl}${localeSlug ? `/${localeSlug}` : ''}${iframePath}${query}`; // Add domain and query
iframePath = `${openverseUrl}${localeSlug ? `${localeSlug}` : ''}${iframePath}${query}`; // Add domain and query

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This slash causes the openverse_embed url have 2 slashes: <iframe id="openverse_embed" src="http://localhost:8443//ru">.
Without it, everything works, and if I use the branch from the translation banner fix PR, I can see the banner!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I don't see that locally. For example, if I change the get_locale call to just be pt_BR I see this logged:

Navigating iframe to https://search-staging.openverse.engineering/pt-br

Copy link
Author

@sarayourfriend sarayourfriend Feb 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think this depends on what you set the ov_embed_url value to in customizer. If you add a trailing slash to that then it doubles the slash.

The default value does not include a trailing slash and I've just been testing by changing the subdomain to search-staging so that's what I haven't seen the double slash locally.

I guess we could make the code detect whether a the trailing slash is there and add it conditionally.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I was testing it is by setting the language of the site in wp-admin. So, the top bar would display in the language I selected.

@@ -5,7 +5,12 @@ document.addEventListener('DOMContentLoaded', () => {
.toLocaleLowerCase()
.replace(openverseSubpath, '')
.replace(/^\/$/, ''); // Remove Openverse site subpath
iframePath = `${openverseUrl}${localeSlug ? `/${localeSlug}` : ''}${iframePath}${query}`; // Add domain and query
const localePart = localeSlug
? openverseUrl.endsWith('/')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@obulat
Copy link

obulat commented Feb 18, 2022

We can also remove step 3 from the README instructions, as the mu-plugin is already set up, at least it is for me?

@sarayourfriend
Copy link
Author

We can also remove step 3 from the README instructions, as the mu-plugin is already set up, at least it is for me?

That's just you 🙂 On a fresh clone they're set up by composer install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants