-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Support for accessing variations of a post in different languages through the REST API #5958
Comments
We had similar issues in the past with the AJAX URL because third party plugins were using strings concatenation instead of proper URL manipulation functions. I think that at least Gutenberg (and by extension, the WP-Core team) should avoid using simple strings concatenation when manipulating URLs. Of course, provided that this is the case: I was trying to figure out where the URL gets changed by Gutenberg, but I got a bit lost. Does the code rely on URL manipulation functions (PHP: |
Another idea you could consider, albeit not necessarily a good one:
The benefit of this approach: you'd be able to very cleanly introduce WPML functionality. The rewrite rule would introduce the language as a The downside of this approach: only one plugin gets to filter |
Thanks, @danielbachhuber. This is the very first time I dig into Gutenberg code base, so take it easy hehe. I've just pushed a PR containing a tiny fix that may resolve this question: #5976 |
@adrianosferreira Have you considered registering |
@danielbachhuber how? Can you give me one example? |
I was referring to using However, in considering this further, the client would still need some way of querying for a specific post variation from the server (i.e. the query parameter you've mentioned before). I think we're back at square one. Let's let this soak a bit and maybe a better solution will become more obvious with time. |
@adrianosferreira Were you able to get to an acceptable implementation? If yes, can you share the details of how you ended up handling this? If no, can you describe where you're currently stuck? |
Closing for now. Feel free to follow-up with additional details if there's something you're stuck on. https://github.com/polylang/polylang-gutenberg/issues/15 has a good amount of related detail on the topic. |
Issue Overview
On WPML, through a custom meta box in post edit page
post.php?post=43&action=edit
we let users add a translated version of the current post. This produces a new URL containing thelang
argument, something like this:post-new.php?lang=pt-br&post_type=page&trid=376&source_lang=en
Which allows us to save the language information in the database.
Recently we've added a new filter to hook into
rest_url
in order to convert the rest URL in the translated version, which basically appends thelang
argument into the rest URL. That way we can later properly save the language information of the post.However now trying the same thing with Gutenberg I've noticed some messed URL caused by our filter in
rest_url
:http://wpml.local/wp-json/?lang=pt-brwp/v2/types/page&context=edit
This happens because Gutenberg simply appends into the already filtered
rest_url
the path that it needs, doing the request with this messed URL.After a short discussion with @mcsf he said:
Whatever you decide, we simply need to have a way to hook into Gutenberg background rest requests in order to properly add the
lang
argument and later save WPML language information.The text was updated successfully, but these errors were encountered: