i18n-helper
Handle WordPress internationalization. Use when adding translatable strings.
When & Why to Use This Skill
The i18n-helper Claude skill streamlines WordPress internationalization (i18n) by providing automated assistance for adding translatable strings. It ensures developers adhere to WordPress coding standards by using correct text domains and specific functions like `__()`, `_e()`, and security-focused escaping functions. This tool simplifies the localization workflow, from initial string implementation to the generation of POT files for translation teams.
Use Cases
- Developing WordPress plugins or themes that require multi-language support by automatically wrapping UI strings in the correct i18n functions.
- Refactoring legacy WordPress code to meet modern internationalization standards and ensure all output is properly escaped for security.
- Automating the maintenance of translation templates by executing Composer-based POT file generation commands within the development environment.
| name | i18n-helper |
|---|---|
| description | Handle WordPress internationalization. Use when adding translatable strings. |
i18n Helper
Instructions
When adding translatable strings to the plugin:
- Use the correct text domain:
'retrologin' - Choose the right function:
__()- Return translated string_e()- Echo translated stringesc_html__()- Return escaped translated stringesc_html_e()- Echo escaped translated stringesc_attr__()- Return escaped for HTML attributes
- Generate POT file:
composer run make-pot - Keep strings in English (US)
Translation Functions
| Function | Output | Use When |
|---|---|---|
__($text, $domain) |
Return | Strings in PHP variables |
_e($text, $domain) |
Echo | Direct output |
esc_html__($text, $domain) |
Return + escape | Displaying user content |
esc_html_e($text, $domain) |
Echo + escape | Direct output of user content |
esc_attr__($text, $domain) |
Return + escape | HTML attributes |
Example
// Basic usage
__('Login Page', 'retrologin');
_e('Welcome back!', 'retrologin');
// With escaping
esc_html__('Please log in to continue', 'retrologin');
esc_attr__('Username', 'retrologin');
// In attributes
<input placeholder="<?php esc_attr_e('Enter username', 'retrologin'); ?>">
Generate Translations
# Generate POT file for translations
composer run make-pot
# POT file location: inc/languages/retrologin.pot
Guidelines
- Always include text domain second parameter
- Use escaping functions for user-generated content
- Keep strings concise for translation
- Avoid embedding variables in translatable strings