Published in WordPress
avatar
5 minutes read

Polylang: How to translate custom strings?

My test: I'm utilizing Polylang to interpret my site, however I'm battling with custom string interpretations. The strings aren't showing up in the "Strings interpretation" menu inside the WP dashboard.

My test: I'm utilizing Polylang to interpret my site, however I'm battling with custom string interpretations. The strings aren't showing up in the "Strings interpretation" menu inside the WP dashboard.

Significant: I'm not intimately acquainted with PHP, so pll_register_string is befuddling to carry out.

Cited from Polylang documentation:

Polylang Capabilities Reference

pll_register_string

This capability lets modules add custom strings to the "strings interpretation" board. It ought to be approached the administrator side (for subjects, functions.php is reasonable). Void strings can be enlisted (e.g., when they're from choices) however won't show in the rundown table.

pll_register_string($name, $string, $group, $multiline);

$name => (required) a name for arranging (e.g., 'myplugin')

$string => (required) the string to interpret

$bunch => (discretionary) gathering to arrange the string, default is 'polylang'

$multiline => (discretionary) if valid, interpretation field will be multiline, default is misleading

pll__

Gets an interpreted string recently enrolled with pll_register_string.

Utilization:

pll__($string);

$string => the string to interpret (returns the deciphered string).

pll_e

Yields an interpreted string recently enlisted with pll_register_string.

Utilization:

pll_e($string);

$string => the string to interpret

Best respects!

Labels: PHP, WordPress, Polylang, string interpretation

Our Solutions

These strings should initially be enlisted for interpretation. For example, in a layout document, you could repeat "Hi world" like follows:  

<?php pll_e('Hello world'); ?>

Add the accompanying to your functions.php record to show the string in the "Strings interpretation":

add_action('init', function() {
  pll_register_string('mytheme-hello', 'Hello world');
});

To this capability, add any custom strings you wish to decipher.

Comments