Making admin page code ready for translation
The previous recipe showed how to look up the translation of a text item and return its value for further processing in the plugin code. There are many instances where it is more practical to display the translated content immediately, as we'll see in this recipe.
Getting ready
You should have already followed the Adapting default user settings for translation recipe to have a starting point for this recipe. Alternatively, you can get the resulting code (ch12/ch12-hello-world/ch12-hello-world-v1.php
) for that recipe from the book's GitHub page and rename the file to ch12-hello-world.php
.
How to do it...
Follow these steps to translate the contents of a simple administration page for immediate display:
- Navigate to the
ch12-hello-world
folder of the WordPressplugins
directory of your development installation. - Open the
ch12-hello-world.php
file in a text editor. - Add the following line of code at the end...