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.
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
How to do it...
Follow these steps to translate the contents of a simple administration page for immediate display:
- Navigate to the
ch12-hello-worldfolder of the WordPress
pluginsdirectory of your development installation.
- Open the
ch12-hello-world.phpfile in a text editor.
- Add the following line of code at the end...