VOOZH about

URL: https://deepwiki.com/Automattic/BuddyPress-VIP-Go/6.6-internationalization

⇱ Internationalization | Automattic/BuddyPress-VIP-Go | DeepWiki


Loading...
Menu

Internationalization

Purpose and Scope

This document explains the internationalization (i18n) infrastructure for the BuddyPress VIP Go plugin. It covers the text domain configuration, translation template generation workflow, translatable strings in the codebase, and the file structure for translation files.

For information about building and distributing the plugin, see Build and Distribution Process.


Text Domain Configuration

The plugin uses buddypress-vip-go as its text domain, declared in the main plugin file header at buddypress-vip-go.php17

Text Domain: buddypress-vip-go

This text domain serves as the unique identifier for all translatable strings within the plugin. WordPress uses this domain to load the appropriate translation files when the plugin is active.

The text domain must match:

  • The plugin slug used in the WordPress.org plugin directory
  • The directory name inside /languages/
  • The base filename of POT/PO/MO files

Sources: buddypress-vip-go.php17


Translation Template Structure

The POT (Portable Object Template) file is located at languages/buddypress-vip-go.pot This file contains all translatable strings extracted from the plugin's PHP files.

POT File Metadata

The template includes standard metadata headers:

HeaderValuePurpose
Project-Id-VersionBuddyPress VIP Go 1.0.12Plugin name and version
Report-Msgid-Bugs-ToWordPress.org support URLWhere to report translation issues
POT-Creation-DateAuto-generated timestampWhen the template was last generated
MIME-Version1.0Standard MIME header
Content-Typetext/plain; charset=UTF-8UTF-8 encoding for international characters
X-GeneratorWP-CLI 2.12.0Tool used to generate the template
X-Domainbuddypress-vip-goText domain identifier

The POT-Creation-Date field is automatically updated each time the template is regenerated, ensuring translators can track when strings were last updated.

Sources: languages/buddypress-vip-go.pot1-15


Translation Template Generation

Generation Command

Translation templates are generated using the WP-CLI i18n tool via a Composer script:


This command executes: wp i18n make-pot . ./languages/buddypress-vip-go.pot

The command:

  1. Scans all PHP files in the plugin directory (excluding vendor/)
  2. Extracts translatable strings wrapped in WordPress i18n functions
  3. Generates/updates the POT file at languages/buddypress-vip-go.pot
  4. Preserves translator comments and context information

Automated Generation in CI/CD

The POT file should be regenerated before each release to ensure all new translatable strings are included. While the repository includes a pre-generated POT file, developers should run composer i18n after adding or modifying translatable strings.

Sources: composer.json49 composer.json61


Translation Workflow Diagram


Workflow Steps:

  1. Development Phase: Developers add translatable strings to PHP files using WordPress i18n functions
  2. Template Generation: Run composer i18n to extract strings into the POT file
  3. Translation Phase: Translators create locale-specific PO files from the POT template
  4. Compilation: PO files are compiled into binary MO files for performance
  5. Runtime Loading: WordPress loads the appropriate MO file based on site locale

Sources: composer.json49 languages/buddypress-vip-go.pot1-50


Translatable Strings in the Codebase

Current Translatable Content

The plugin currently contains four distinct translatable strings, all located in files.php. These are user-facing error messages that appear during media upload operations.

Plugin Metadata Strings

StringLocationContext
"BuddyPress VIP Go"buddypress-vip-go.php11Plugin name
"Makes BuddyPress' media work with WordPress VIP's hosting."buddypress-vip-go.php12Plugin description
"Human Made, WordPress VIP"buddypress-vip-go.php16Author name

These strings are extracted from the plugin header and appear in the WordPress plugin list.

Error Message Strings

StringPOT LinesSource LocationParametersUsage Context
"Upload failed! Error was: %s"33-37files.php373 files.php499%s: Error messageAvatar upload failure
"You have selected an image that is smaller than recommended. For best results, upload a picture larger than %1$d x %2$d pixels."39-43files.php451%1$d: Width, %2$d: HeightAvatar size warning
"Upload Failed! Error was: %s"45-49files.php602%s: Error messageCover image upload failure

Sources: languages/buddypress-vip-go.pot17-50


String Extraction and Context Diagram


Translation Context Notes:

  • Error Messages: Both upload error strings use %s as a placeholder for error messages returned by WordPress functions like wp_handle_sideload() or wp_handle_upload()
  • Size Warning: The avatar size warning uses numbered placeholders (%1$d, %2$d) to allow translators to reorder the dimensions if needed for their language
  • Translator Comments: Each string includes a translators: comment explaining what the placeholders represent, which appears in the POT file to help translators understand context

Sources: languages/buddypress-vip-go.pot32-49 files.php373 files.php451 files.php499 files.php602


Translation File Structure

Directory Layout

languages/
└── buddypress-vip-go.pot # Template file (versioned in Git)
└── buddypress-vip-go-*.po # Translation files (not in Git)
└── buddypress-vip-go-*.mo # Compiled files (not in Git)

File Naming Convention

Translation files follow WordPress's standard naming convention:

  • POT File: buddypress-vip-go.pot (template, no locale)
  • PO Files: buddypress-vip-go-{locale}.po (e.g., buddypress-vip-go-fr_FR.po)
  • MO Files: buddypress-vip-go-{locale}.mo (compiled from PO files)

The {locale} format follows WordPress locale codes (e.g., fr_FR, de_DE, ja, pt_BR).

Distribution Strategy

Only the POT file is included in the Git repository. Actual translations (PO/MO files) are:

  • Created by translators using tools like Poedit or the WordPress.org translation platform
  • Distributed separately through WordPress.org's translation system
  • Automatically downloaded by WordPress sites when available

Sources: languages/buddypress-vip-go.pot1-50


Translation Loading Mechanism

Current Implementation Status

Important: The plugin currently does not explicitly call load_plugin_textdomain(). This function is typically required to load translation files at runtime.

The absence of this call means:

  1. Translations may only load if WordPress's automatic translation loading handles it
  2. The plugin relies on WordPress 4.6+ automatic loading based on the Text Domain header
  3. For WordPress versions 4.6+, translations from wp-content/languages/plugins/ are automatically loaded

Expected Automatic Loading Behavior

WordPress automatically loads translations from:

wp-content/languages/plugins/buddypress-vip-go-{locale}.mo

This automatic loading occurs when:

  1. WordPress 4.6+ is installed (supported by the plugin's minimum requirement of 6.6)
  2. The Text Domain header is properly set in the plugin file
  3. MO files exist in the languages directory with the correct naming convention

Sources: buddypress-vip-go.php17


Adding New Translatable Strings

Developer Guidelines

When adding user-facing text to the plugin, developers should:

  1. Wrap strings in i18n functions:

    
    
  2. Use sprintf for dynamic content:

    
    
  3. Add translator comments for placeholders:

    
    
  4. Regenerate POT file:

    
    
  5. Commit updated POT file:

    
    

Placeholder Formatting

TypeExampleUsage
Single placeholder%sSimple substitution
Multiple ordered%1$s, %2$sAllows translators to reorder
Integers%d, %1$dNumeric values
Floats%f, %.2fDecimal values

Sources: languages/buddypress-vip-go.pot32-49


Integration with WordPress Translation Platform

Translation Coordination

While the POT file is maintained in the repository, actual translation work typically occurs through:

  1. WordPress.org Translation Platform: If the plugin is listed on WordPress.org, translations can be contributed through the official platform
  2. GlotPress: Community translation management system used by WordPress.org
  3. Automatic Distribution: WordPress sites automatically download available translations

Translation Priority

Given the plugin's limited scope (four error messages plus metadata), translations are straightforward. The strings are:

  • Technical error messages for end users
  • Clear in context
  • Minimal cultural/linguistic complexity
  • Include helpful translator comments

Sources: languages/buddypress-vip-go.pot1-50


Summary Table: Internationalization Components

ComponentFile PathPurposeMaintenance
Text Domainbuddypress-vip-go.php17Identifies translation namespaceUpdate only if plugin slug changes
POT Templatelanguages/buddypress-vip-go.potMaster translation templateRegenerate with composer i18n
Generation Scriptcomposer.json49Automates POT creationPre-configured, no maintenance
Translatable Stringsfiles.php373 files.php451 files.php499 files.php602User-facing textAdd i18n wrappers to new strings
Translation Fileslanguages/*.po, *.moLocale-specific translationsCreated by translators, not versioned

Sources: buddypress-vip-go.php17 languages/buddypress-vip-go.pot1-50 composer.json49