Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To implement the multi language WordPress translation using __() in an external PHP file of a plugin, follow these steps:

  1. Create a new .pot file for your plugin using a tool like WP-CLI or Poedit.
  2. Add your plugin's strings to the .pot file and save it.
  3. Generate the .po and .mo files for each language using a tool like Poedit or WP-CLI.
  4. Load the .mo files for the user's current language in your plugin using the loadplugintextdomain() function.
  5. Use the __() function to translate your plugin's strings in the PHP file.

Here's an example code snippet:

// Load the text domain for the current language
load_plugin_textdomain( 'your-plugin-textdomain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

// Use the __() function to translate your strings
echo __( 'Hello world!', 'your-plugin-textdomain' );

This will translate the string 'Hello world!' into the user's current language, using the translation files located in the 'languages' folder of your plugin.