Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogCoursesPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Courses
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 32 of the WordPress Plugin Development: Foundations (PHP & MVC) course
WordPressJune 25, 20263 min read

Mastering WordPress Internationalization (i18n) for Plugins

Learn to implement WordPress internationalization (i18n) to make your plugins translation-ready. Master text domains, translation functions, and POT file generation.

WordPressPHPi18nlocalizationtranslationaccessibilityplugin-development

Previously in this course, we discussed handling plugin updates to keep your database schema in sync with your codebase. Now that our Knowledge Base plugin is stable and secure, it’s time to open it up to the world by implementing internationalization (i18n).

Internationalization—often abbreviated as "i18n" because there are 18 letters between the 'i' and the 'n'—is the process of developing your plugin so it can easily be adapted for different languages and regions. Without this, your plugin is locked into the language you wrote it in, severely limiting your user base.

The Principles of Translation-Ready Code

To make your plugin "translation-ready," you must stop hardcoding display strings directly into your PHP files. Instead, you wrap every user-facing string in specific WordPress functions. These functions tell WordPress that the string should be passed through a translation engine before being sent to the browser.

When you do this, you define a text domain. A text domain is a unique string—usually the slug of your plugin—that acts as a namespace for your translations. This ensures that WordPress knows which language file belongs to your plugin and not another.

Using Translation Functions

There are two primary functions you need to master for basic output:

  1. __(): Retrieves the translated string. Use this when you need to store the string in a variable or pass it to another function.
  2. _e(): Retrieves and echoes the translated string. Use this for direct output in your templates.

Both functions accept two arguments: the string to translate and the text domain.

PHP
#6A9955">// Storing for later use
$label = __('Knowledge Base Article', 'knowledge-base-plugin');

#6A9955">// Echoing directly to the page
_e('Click here to read more', 'knowledge-base-plugin');

Integrating i18n into the Knowledge Base Plugin

Let's update our plugin's core initialization to load our text domain. In your main plugin file, you need to hook into the plugins_loaded action.

PHP
class KnowledgeBasePlugin {
    public function __construct() {
        add_action('plugins_loaded', [$this, 'load_textdomain']);
    }

    public function load_textdomain() {
        load_plugin_textdomain(
            'knowledge-base-plugin', 
            false, 
            dirname(plugin_basename(__FILE__)) . '/languages'
        );
    }
}

Now, every time you output text in your views or admin controllers, use the translation functions. For example, in your AdminController, when you define your menu page:

PHP
add_menu_page(
    __('Knowledge Base Settings', 'knowledge-base-plugin'),
    __('Knowledge Base', 'knowledge-base-plugin'),
    'manage_options',
    'knowledge-base',
    [$this, 'render_admin_page']
);

Generating the POT File

A POT (Portable Object Template) file is a master template containing all the translatable strings in your plugin. Translators use this file to create language-specific .po files.

You don't need to write this file manually. You can use tools like the WP-CLI to generate it automatically:

  1. Open your terminal in your plugin's root directory.
  2. Run the following command: wp i18n make-pot . languages/knowledge-base-plugin.pot

This command scans your entire directory for __() and _e() functions, extracts the strings, and creates the .pot file in your /languages folder.

Hands-on Exercise

  1. Refactor: Audit your AdminController and your frontend shortcode views. Find every hardcoded string (like "Submit," "Settings," or "Article Title") and wrap it in the __() or _e() function.
  2. Namespace: Ensure every function call uses your unique text domain string.
  3. Generate: Run the wp i18n make-pot command and verify that your languages/ folder now contains your .pot file.

Common Pitfalls

  • Forgetting the Text Domain: If you omit the text domain in your function calls, WordPress won't know where to look for your translations.
  • Variable Interpolation: Never do this: __('Hello ' . $user_name, 'domain'). The translation engine cannot parse concatenated strings. Instead, use printf() with placeholders: printf(__('Hello %s', 'domain'), $user_name);.
  • Dynamic Strings: Avoid translating dynamic data stored in the database. Only translate static, hardcoded UI text.
  • Case Sensitivity: Ensure your text domain is consistent throughout every single file in your project.

By following these practices, you ensure that your plugin remains accessible to a global audience, allowing community contributors to localize your work effectively.

Up next: We'll dive into Debugging WordPress Plugins to learn how to identify and resolve issues when things don't go according to plan.

Previous lessonHandling Plugin UpdatesNext lesson Debugging WordPress Plugins
Back to Blog

Similar Posts

WordPressWordPressJune 25, 20263 min read

Capability Checks: Securing WordPress Plugins with Authorization

Master WordPress security by implementing capability checks. Learn to use current_user_can to restrict admin features and enforce proper access control.

Read more
WordPressWordPressJune 25, 2026

Part of the course

WordPress Plugin Development: Foundations (PHP & MVC)

beginner · Lesson 32 of 47

  1. 1

    Plugin Anatomy and File Structure

    3 min
  2. 2

    The Plugin Lifecycle Hooks

    4 min
  3. 3

    Designing for MVC in WordPress

    3 min
4 min read

Understanding WordPress Hooks: Actions vs. Filters Explained

Master the WordPress event-driven architecture. Learn the difference between actions and filters and how to implement callbacks to build robust plugins.

Read more
WordPressWordPressJune 25, 20263 min read

REST API Integration: Exposing Data for External Consumption

Learn to extend the WordPress REST API by registering custom endpoints. We'll show you how to securely serve your Knowledge Base data as structured JSON.

Read more
4

Defining the Plugin Core Class

4 min
  • 5

    Understanding WordPress Hooks

    4 min
  • 6

    Implementing Custom Action Hooks

    4 min
  • 7

    Managing Hook Priorities

    3 min
  • 8

    Creating Admin Menus

    3 min
  • 9

    The Controller Layer for Admin Pages

    3 min
  • 10

    Registering Custom Post Types

    3 min
  • 11

    Configuring CPT Arguments

    3 min
  • 12

    Introduction to Taxonomies

    3 min
  • 13

    Designing Meta-Boxes

    3 min
  • 14

    Sanitizing User Input

    4 min
  • 15

    Saving Meta Data

    3 min
  • 16

    Database Basics with wpdb

    3 min
  • 17

    Secure CRUD Operations

    3 min
  • 18

    Querying with WP_Query

    3 min
  • 19

    Optimizing Queries

    3 min
  • 20

    The Model Layer for Data

    3 min
  • 21

    Enqueuing Scripts and Styles

    3 min
  • 22

    Plugin Template Hierarchy

    3 min
  • 23

    Creating Frontend Templates

    3 min
  • 24

    Building Shortcodes

    3 min
  • 25

    Advanced Shortcode Logic

    3 min
  • 26

    Introduction to Gutenberg Blocks

    3 min
  • 27

    The Settings API

    3 min
  • 28

    Validating Settings

    3 min
  • 29

    Implementing Nonces

    3 min
  • 30

    Capability Checks

    3 min
  • 31

    Handling Plugin Updates

    3 min
  • 32

    Internationalization (i18n)

    3 min
  • 33

    Debugging WordPress Plugins

    4 min
  • 34

    Unit Testing Foundations

    3 min
  • 35

    Handling AJAX Requests

    3 min
  • 36

    REST API Integration

    3 min
  • 37

    Advanced Database Queries

    3 min
  • 38

    Caching Strategies

    3 min
  • 39

    Plugin Security Best Practices

    Coming soon
  • 40

    Composer for Dependencies

    Coming soon
  • 41

    Theme Integration Hooks

    Coming soon
  • 42

    Managing Assets with Gulp/Webpack

    Coming soon
  • 43

    Documentation Standards

    Coming soon
  • 44

    Plugin Deployment Strategy

    Coming soon
  • 45

    Advanced MVC: Dependency Injection

    Coming soon
  • 46

    Handling Large Datasets

    Coming soon
  • 47

    Error Handling and Logging

    Coming soon
  • View full course