Making admin page code ready for translation
While 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.
This recipe shows how to translate the contents of a simple administration page for immediate display.
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 (Chapter 11/ch11-hello-world/ch11-hello-world-v1.php
) for that recipe from the code bundle. You should rename the file to ch11-hello-world.php
before starting.
How to do it...
- Navigate to the
ch11-hello-world
folder of the WordPress plugin directory of your development installation. - Open the
ch11-hello-world.php
file in a text editor. - Add the following line of code at the end of the file to register a function to be called...