Polylang Integration
Configure multilingual support with Polylang through the Combo plugin.
Configuration Options
Configure Polylang integration in your config.yml file:
1pll:2domain: 'cbowp' # Text domain3strings: false # Load strings from file4reference: 'key' # Reference by key or value
Options
- domain: Text domain used for translations.
- strings: Whether to load strings from the
strings.ymlfile. - reference: How strings are referenced:
'key': Reference strings by key (recommended)'value': Reference strings by their content
String Translations
When strings is set to true, Combo will load string translations from the strings.yml file:
strings.yml
1# strings.yml2my-string-key: "My default Polylang string"
These strings can then be translated in the Polylang Strings Translation interface in the WordPress admin.
Usage in Templates
Combo provides utility functions for working with Polylang translations:
Key Mode
When reference is set to 'key':
1// Configuration2$cbo['pll']['reference'] = 'key';3$cbo['pll']['strings'] = [4'my-string-key' => 'My default Polylang string'5];67// Usage8pl_e('my-string-key'); // Displays "My default Polylang string" or its translation
Value Mode
When reference is set to 'value':
1// Configuration2$cbo['pll']['reference'] = 'value';34// Usage5pl_e('My default Polylang string'); // Displays "My default Polylang string" or its translation
Advanced Usage
With Variables
1// Using with variables2$username = 'John';3pl_e(sprintf('Hello %s, welcome to our website', $username));45// Using with key mode and parameters6$cbo['pll']['reference'] = 'key';7$cbo['pll']['strings'] = [8'welcome_user' => 'Hello %s, welcome to our website'9];1011echo sprintf(pl__('welcome_user'), $username);
With HTML
1// Using with HTML tags2pl_e('Check out our <a href="/contact">contact page</a>');