Answer the question
In order to leave comments, you need to log in
How to translate arbitrary strings with Polylang?
There is a site on wordpress. I use the Polylang plugin to create the English version of the site. It works well, but I can’t find a solution to the question: how to make it so that when clicking on the English version of the site, for example, it translates the line in the header "we are in social networks" to the English line "social links"? Similarly with divs and pictures.
Thanks
Answer the question
In order to leave comments, you need to log in
Polylang has its own little functions that are useful for such purposes. Specifically, in this case, there are 3 options:
1. Localization of the string using the usual WordPRess method - in the template we find where this text is and wrap it in the _e() or __() function. After that, we do a line feed in POedit, as usual.
2. Localization of the string is exactly the same as in step 1, but instead of the external POedit we put the Loco Translate plugin and translate the string directly in the admin panel.
3. Instead of the _e() or __() functions, we use the pll__(), pll_e() functions together with pll_register_string() and translate them in the WordPress admin panel on the Polylang settings page. Documentation .
In any case, you will have to poke around in the code.
Understood. Used pll_register_string().
I added the following line to function.php:
Next, in the admin panel, I added the translation of the phrase in the new lines that appeared, after which I wrote this in the template (header.php):
And it all worked.
Thanks @HeadOnFire
Good day! How to translate the value of a standard "Search" button using a Polylang function?
Thanks for the discussion!
Tell me, how to translate the slider on the main page if it is built into the theme?
theme - Accesspress Root. For multilingual site I use Polylang
Headers, for example - registration of new strings - figured it out. (thanks to your discussion!!!)
But with the slider? I tried creating strings, but then when you insert the code - the same title is translated when you change the language, but remains on all five slides in the slider. And there are 5 of them and they change ...
Thank you!
I welcome everyone.
Who can help me with my problem.
I used the pll_register_string(); function, the required values appeared in Polylang string translations, but no changes occur during editing.
What could be the problem?
Good afternoon everyone) I studied the instructions for a long time and how the developers helped in this topic under this question. But I'm trying to implement all this on my own and it doesn't work, I'm a novice developer. I will be grateful for your help!
I need to translate the phrase "Buy now", add it to Strings translations. This phrase is written separately in the theme and woocommerce does not translate it, so you need to try it through Strings translations. What specifically needs to be written in function.php? Just pll_register_string( 'mythemeorpluginslug', 'English text to translate' ); he does not understand. I would be grateful for your help!!
Here is the code where this button is called
/**
* Display buy now button
*
* @since 1.0
*/
function product_buy_now_button() {
global $product;
if ( ! intval( supro_get_option( 'product_buy_now' ) ) ) {
return;
}
if ( $product->get_type() == 'external' ) {
return;
}
echo sprintf( '%s', wp_kses_post( supro_get_option( 'product_buy_now_text' ) ) );
}
function buy_now_redirect( $url ) {
if ( ! isset( $_REQUEST['buy_now'] ) || $_REQUEST['buy_now'] == false ) {
return $url;
}
if ( empty( $_REQUEST['quantity'] ) ) {
return $url;
}
if ( is_array( $_REQUEST['quantity'] ) ) {
$quantity_set = false;
foreach ( $_REQUEST['quantity'] as $item =>
continue;
}
$quantity_set = true;
}
if ( ! $quantity_set ) {
return $url;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question