Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

Chouby on "[Plugin: Polylang] Function to get all translations of a string"

$
0
0

pll__() works pretty much as __() and so can only access to the current language (Polylang does not load other languages).

Here is an example on how to proceed based on what is done in Polylang admin

global $polylang;
$strings = array('my 1st string', 'my 2nd string'); // for the example
foreach ($polylang->get_languages_list() as $language) {
	$mo = $polylang->mo_import($language);
	foreach ($strings as $key=>$row) {
		$translations[$key][$language->slug] = $mo->translate($row);
	}
}
echo $translations[1]['fr']; // outputs the French translation of 'my 1st string'

Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>