Let’s discuss a technical issue regarding WordPress and GlotPress. You tell me why the theme/plugin and readme.txt files on WordPress.org can be automatically loaded into GlotPress projects and displayed after translation?
This is a meticulously designed automated process within the WordPress.org ecosystem. Let me explain how it works:
Mechanism for Automatic Loading into GlotPress
-
SVN Hook Monitoring
When plugin/theme developers commit code to the WordPress.org SVN repository:- The SVN server is configured with post-commit hooks.
- These hooks trigger automated scripts to detect new commits.
-
Automatic Extraction Process
SVN Commit → Triggers Hook → Scans file changes ↓ Detects readme.txt or code files ↓ Runs extraction tool (similar to wp i18n make-pot) ↓ Generates/Updates POT file ↓ Automatically imports into GlotPress project -
Core Components
String Extraction:- Specific fields in readme.txt (Plugin Name, Description, Tags, etc.)
- Internationalization functions in PHP code like
__(),_e(),esc_html__() - Functions like
wp.i18n.__()in JavaScript
GlotPress Integration:
- WordPress.org uses a custom integration layer connecting SVN and GlotPress.
- Corresponding GlotPress projects are automatically created for each plugin/theme.
- Project structure:
/plugins/plugin-slug/and/themes/theme-slug/
-
Automatic Display Mechanism After Translation
Building Language Packs:Translators submit translations in GlotPress ↓ Approval threshold is met (usually requires editor approval) ↓ Automatically triggers language pack build ↓ Generates .po and .mo files ↓ Packages into ZIP (includes all translation domains) ↓ Deploys to translate.wordpress.org CDNAutomatic Download by WordPress Sites:
// WordPress core checks periodically update_translations() ↓ Queries API: api.wordpress.org/translations/plugins/1.0/ ↓ Detects available new language packs ↓ Downloads to wp-content/languages/plugins/ ↓ Automatically loads and uses them -
Key Technical Points
API Endpoints:https://api.wordpress.org/translations/plugins/1.0/?slug={plugin-slug}&version={version}- Returns metadata for all available language packs for that plugin.
Automatic Loading Logic:
// WordPress core when loading a plugin load_plugin_textdomain('plugin-slug', false, dirname(plugin_basename(__FILE__)) . '/languages'); // If translation file doesn't exist locally, loads from CDN // wp-content/languages/plugins/plugin-slug-zh_CN.moUpdate Frequency:
- Language pack build: Within minutes after translation approval.
- WordPress update check: Every 12 hours (via wp-cron).
- Can also be triggered manually: Dashboard → Updates.
-
Why is it Automatic?
Integration Layers:- SVN → GlotPress: post-commit hooks
- GlotPress → Language Packs: cronjob builders
- Language Packs → WordPress: core update mechanism
WordPress.org Privileges:
- This system is part of the official WordPress.org infrastructure.
- Uses internal APIs and direct database access.
- Not implemented via public APIs.
If You Want to Implement a Similar System
You would need to build the following components:
- Code Repository Hook → Detects commits
- String Extractor → Parses POT
- GlotPress Integration → Automatic import/export
- Build Pipeline → Generates language packs
- Distribution API → Serves to clients
- Client Updater → Automatically downloads and loads
This is a complete CI/CD + i18n automation system. Its core lies in event-driven automation and a standardized file structure.