Polylang Integration

Configure multilingual support with Polylang through the Combo plugin.

Configuration Options

Configure Polylang integration in your config.yml file:

1
pll:
2
domain: 'cbowp' # Text domain
3
strings: false # Load strings from file
4
reference: 'key' # Reference by key or value

Options

  • domain: Text domain used for translations.
  • strings: Whether to load strings from the strings.yml file.
  • 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.yml
2
my-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
// Configuration
2
$cbo['pll']['reference'] = 'key';
3
$cbo['pll']['strings'] = [
4
'my-string-key' => 'My default Polylang string'
5
];
6
7
// Usage
8
pl_e('my-string-key'); // Displays "My default Polylang string" or its translation

Value Mode

When reference is set to 'value':

1
// Configuration
2
$cbo['pll']['reference'] = 'value';
3
4
// Usage
5
pl_e('My default Polylang string'); // Displays "My default Polylang string" or its translation

Advanced Usage

With Variables

1
// Using with variables
2
$username = 'John';
3
pl_e(sprintf('Hello %s, welcome to our website', $username));
4
5
// Using with key mode and parameters
6
$cbo['pll']['reference'] = 'key';
7
$cbo['pll']['strings'] = [
8
'welcome_user' => 'Hello %s, welcome to our website'
9
];
10
11
echo sprintf(pl__('welcome_user'), $username);

With HTML

1
// Using with HTML tags
2
pl_e('Check out our <a href="/contact">contact page</a>');