The code is based on Polylang Pro and need Polylang is installed and activated to work.
This an example of a custom menu item (Language switcher) that needs to be converted in its corresponding polylang/navigation-language-switcher
block.
It is a base to test the issue in the Gutenberg project.
- Polylang plugin 3.1.2 (latest version)
- WordPress 5.8.2 or later
- Gutenberg 12.0.x or later
- A classic WordPress theme like Twenty Twenty-one
Simply put in your wp-content/mu-plugins/
folder of your WordPress instance:
- the
block-editor-switcher-block.php
andgutenberg-block-navigation-conversion-test.php
files - the
dist/
folder - create a new post by using the block editor
- See you can add the language switcher block and the navigation block
- Go to Languages
- Create two languages: English as the default one and French for example
- Create a new post Posts > Add New
- Add a language switcher block
- Play with the language switcher block attributes and see the block WYSIWYG rendering. NB: some of them have no effects because it depends on the frontend context:
Hides languages with no translation
for example
- Follow the first two steps in the first case above
- Go to Appearance > Menus
- Create a classic menu named
Main
for example and checked the theme location Primary menu English. It's sufficient for testing the classic menu conversion - Add the language switcher in the menu as it's explained in the Polylang documentation https://polylang.pro/doc/the-language-switcher/#ls-in-menu. Ensure that you can add the language switcher by refering to the Polylang FAQ https://polylang.pro/doc/i-cant-add-the-language-switcher-in-the-menus/ and verifying the WordPress screen options.
- Check the language switcher
Display flags
option - Add another page for example in the menu
- Save the menu
- Create a new post by using the block editor
- Add a navigation block
- Select the
Main
menu from the Classic menus list - See the language switcher is correctly coverted to its corresponding block however the flags aren't rendered and the
Display flags
block attribute isn't checked as it should and as it has been checked previously in theMain
classic menu.
- Follow the first two steps in the first case above
- Create a new post by using the block editor
- Add a navigation block
- Click on
Start empty
- Add a page link in the navigation block
- Transform it as a language switcher block and check its
Display flags
attribute - Add a page link again to complete the navigation block