madalinungureanu / user-profile-picture

WordPress User Profile Picture
GNU General Public License v2.0
15 stars 7 forks source link

Multi-lingual functionality for blocks? #15

Open ronalfy opened 4 years ago

ronalfy commented 4 years ago

User is currently concerned that Polylang doesn't work. I imagine other language issues exist for the blocks.

https://wordpress.org/support/topic/does-not-support-multilang/

The problem is that the description is loaded in the block via the REST API. In the REST API, there is no language set, which is a known bug: https://wordpress.org/support/topic/how-to-know-the-language-of-a-post-through-the-wordpress-rest-api/

Unfortunately I do not know enough about Polylang, WPML, or other translation plugins to know if this is possible through the current block implementations. For example, the legacy block, this is not possible. For the newer block, it pulls in the description using the REST API, and allows you to override it. The only way to compare it, I think, is seeing if the description matches, and if the language is different on the front-end, grab the meta description.

For example, the English description is get_user_meta( $user_id, 'description', true );

For Spanish, it would be: get_user_meta( $user_id, 'description_es', true );

There's pll_current_language built into Polylang, but in the REST API, it returns empty.

I'm not aware of any workaround or hack to get the correct description via the REST API for the selected language.

Any help by the community is appreciated, even if it requires another block that gets the data in a language-friendly way.