Using the translated strings
-
Hi, Marcin
I’m trying to use your plugin but I cannot find the method to show them, because i’m a begginer with PHPI don’t know if the solution is the explanation in the “Installation” tab
<?php
pll_e(‘My string’); // similar to _e();
// or:
$var = pll_(‘My string’); // similar to __();
// or:
_e(‘My string’, ‘my_theme’);
// or:
$var = __(‘My string’, ‘my_theme’);Or how can i use the answer in another ticket:
You can use:
<?php print pll_e( ‘Menu’, ‘menu_name’ ); ?>
or
<?php print pll__( ‘Menu’, ‘menu_name’ ); ?>
for display your string.Should i use it in the functions.php or in the plugin that i want to translate?
Thanks a lot
-
polylang plugin have function to print or render translations in your theme:
https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/You can use pll_e() instead of _e() or pll__() instead of __() for translate your plugin.
But at now Theme and plugin translation for Polylang (TTfP) plugin supports translation directly from _e() or __().
You can use this functions in functions.php or in other theme PHP files.
If you have any questions, feel free to write ??
Thanks, Marcin
I’ve read the polylang documentation, and I cannot get the whole picture:
I have in my admin panel a list of strings, thanks to your plugin, with the different languages (EN, ES, FR)
I’ve translated all the strings that I need, but doesn’t show in the frontendI found this code in https://stackoverflow.com/questions/46557981/polylang-how-to-translate-custom-strings:
/** * Outputs localized string if polylang exists or output's not translated one as a fallback * * @param $string * * @return void */ function pl_e( $string = '' ) { if ( function_exists( 'pll_e' ) ) { pll_e( $string ); } else { echo $string; } } /** * Returns translated string if polylang exists or output's not translated one as a fallback * * @param $string * * @return string */ function pl__( $string = '' ) { if ( function_exists( 'pll__' ) ) { return pll__( $string ); } return $string; } // these function prefixes can be either you are comfortable with.
But i don’t know if this is the way to use the code or if i need to put some value for the string in function pl_e( $string = ” ) and function pl__( $string = ” )
I used this code without value and with the value in the column Name in the list of strings. I tried it in the functions.php of my theme and of my child-theme but neither worked.
If i use the pluging Hyyan WooCommerce Polylang Integration, the strings translations appear in the frontend. The problem is that these plugin is outdated, and interferes with the products.
Sorry if i ask too much and thanks again!
Can you put here some code snippet from your functions.php where translations not works? ??
Thanks, Marcin
Here are the original archives
From Jupiter X – functions.php
<?php /** * Jupiter X Framework. * This core file should only be overwritten via your child theme. * * We strongly recommend to read the Jupiter documentation to find out more about * how to customize the Jupiter theme. * * @author JupiterX * @link https://artbees.net * @package JupiterX\Framework */ /** * Initialize Jupiter theme framework. * * @author JupiterX * @link https://artbees.net */ require_once dirname( __FILE__ ) . '/lib/init.php';
From Jupiter X Child – functions.php
<?php /** * Use WC 2.0 variable price format, now include sale price strikeout * * @param string $price * @param object $product * @return string */ function wc_wc20_variation_price_format( $price, $product ) { // Main Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); // Sale Price $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) ); sort( $prices ); $saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); if ( $price !== $saleprice ) { $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>'; } return $price; } add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); ?> <?php // Include Jupiter X. require_once( get_template_directory() . '/lib/init.php' ); /** * Enqueue assets. * * Add custom style and script. */ jupiterx_add_smart_action( 'wp_enqueue_scripts', 'jupiterx_child_enqueue_scripts', 8 ); function jupiterx_child_enqueue_scripts() { // Add custom script. wp_enqueue_style( 'jupiterx-child', get_stylesheet_directory_uri() . '/assets/css/style.css' ); // Add custom script. wp_enqueue_script( 'jupiterx-child', get_stylesheet_directory_uri() . '/assets/js/script.js', [ 'jquery' ], false, true ); } /** * Example 1 * * Modify markups and attributes. */ // jupiterx_add_smart_action( 'wp', 'jupiterx_setup_document' ); function jupiterx_setup_document() { // Header jupiterx_add_attribute( 'jupiterx_header', 'class', 'jupiterx-child-header' ); // Breadcrumb jupiterx_remove_action( 'jupiterx_breadcrumb' ); // Post image jupiterx_modify_action_hook( 'jupiterx_post_image', 'jupiterx_post_header_before_markup' ); // Post read more jupiterx_replace_attribute( 'jupiterx_post_more_link', 'class' , 'btn-outline-secondary', 'btn-danger' ); // Post related jupiterx_modify_action_priority( 'jupiterx_post_related', 11 ); } /** * Example 2 * * Modify the sub footer credit text. */ // jupiterx_add_smart_action( 'jupiterx_subfooter_credit_text_output', 'jupiterx_child_modify_subfooter_credit' ); function jupiterx_child_modify_subfooter_credit() { ?> <a href="https//jupiterx.com" target="_blank">Jupiter X Child</a> theme for <a href="https://www.remarpro.com" target="_blank">WordPress</a> <?php }
ok, thanks, whats texts you cann’t translate? which translations do not work?
Hi, Marcin
The translation from spanish to english, in the plugin for the credit card payment
You can find it,if you add a product (https://cliente.morganmedia.es/caraibishop/en/product/yoga-mat-sunkissed/) and go to the checkout (https://cliente.morganmedia.es/caraibishop/en/checkout/). The text says “Pago con tarjeta”
In the strings list there is the translation: “Pay with credit card”
String list table
String: Pago con tarjeta
Name: Pago con tarjeta
Group: TTfP: class-wc-redsys
EN: Pay with credit card
ES: Pago con tarjetaThanks a lot!
ok, but i don’t see these strings in your functions.php.
I need snippet of code with these untranslatable strings to help find solution ??Hi, Marcin
I tried this:
<?php /** * Outputs localized string if polylang exists or output's not translated one as a fallback * * @param $string * * @return void */ function pl_e( $string = 'Pago con tarjeta' ) { if ( function_exists( 'pll_e' ) ) { pll_e( $string ); } else { echo $string; } } /** * Returns translated string if polylang exists or output's not translated one as a fallback * * @param $string * * @return string */ function pl__( $string = 'Pay with credit card' ) { if ( function_exists( 'pll__' ) ) { return pll__( $string ); } return $string; } // these function prefixes can be either you are comfortable with. ?>
ok, it has no right to work because you put into pll__ variable ??
my plugin scan files and search raw strings in pll__() or __().You can use in your theme functions: pll__() or __() instead of pl__() (and same for pl_e).
Hi, Marcin
Thanks for your patienteI cannot make it works, so i’m wondering if i’ve understood it correctly:
First, i’ve installed polylang, and there are 15 strings in the table “Strings translations” and the translations appeared in the frontend
Next, i’ve intalled your plugin and now there are 20.000 strings in the table, but the translations don’t show in the frontendI understand that the code
<?php pll_e('My string'); ?>
have the function to show the translations in the frontend (but maybe i’ve got this wrong)
So, if i want to show the translation of “Pago con tarjeta” that is “Pay with credit card”, i must write in “functions.php” of my theme this code?:
<?php pll__('Pago con tarjeta'); pll_e('Pay with credit card'); ?>
Here is the screenshot of the string translation table: screenshot, with the data for the string that i want to translate “Pago con tarjeta” (that is of a plugin, not of the theme, if this fact is important)
I don’t know if you can help me further with this info, and i am really thankfull for your help
Thanks!
have you checked your theme?
https://ps.w.org/theme-translation-for-polylang/assets/screenshot-3.png?rev=2268491> So, if i want to show the translation of “Pago con tarjeta” that is “Pay with credit card”, i must write in “functions.php” of my theme this code?:
– yes, you should use pll__ / pll_e or __ / _e in your functions.php or template php files.
Hi, Marcin
I’ve tried to use the code:
<?php pll__('Pago con tarjeta'); pll_e('Pay with credit card'); ?>
But i’ve achieved nothing
I wonder: your plugin adds to the list of strings with the terms that finds in the php, inc, twig archives, and shows them with the languages in use, so we can put the desired translation for each term
But, if your plugin already shows the term that i want (in this case “Pago con tarjeta”), with it translation, doesn’t polylang must show it in the frontend?
Or is this code, that i cannot resolve, the one in charge of showing the translation?I ask this because if i use the Hyyan WooCommerce Polylang Integration plugin, my translations show in the frontend. (I prefer to not use this plugin, because generate an error with the products)
Again, thanks a lot!
Help. How to fix the error?
K?ūdas deta?as
=================
E_ERROR tipa k?ūda tika izraisīta /var/www/vhosts/bioberes.lv/zooakai.lv/wp-content/plugins/theme-translation-for-polylang/polylang-theme-translation.php datnes 142. rindi?ā. K?ūdas pazi?ojums: Maximum execution time of 30 seconds exceeded@zooakai
You have too many texts to translate…
You can disable unnecessary plugins and themes on “Languages -> Export/import translations” page:
https://ps.w.org/theme-translation-for-polylang/assets/screenshot-3.png?rev=2268491
- The topic ‘Using the translated strings’ is closed to new replies.