This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 14 replies, has 2 voices.

Last updated by Riffaz 5 months, 1 week ago.

Assigned support staff: Riffaz.

Author Posts
May 11, 2019 at 2:39 pm #3790685

tomasD-10

I have strings in functions.php which are displayed in e-shop.

Here is the code:

<?php
function show_stock() {
global $product;
if ( $product->stock ) { // if manage stock is enabled
if ( number_format($product->stock,0,'','') < 3 ) { // if stock is low
echo '<div class="remaining">' . number_format($product->stock,0,'','') . ' na skladě, </div>';
}
}
}

add_action('woocommerce_after_shop_loop_item','show_stock', 10);

function backorder_text($availability) {

foreach($availability as $i) {

//$availability = str_replace('Dostupné na objednávku', 'Na objednávku do 3 - 7 týdnů', $availability);

$availability = str_replace('Dostupné na objednávku', 'Na objednávku do 3 - 7 týdnů', $availability);
}
return $availability;
}
add_filter('woocommerce_get_availability', 'backorder_text');

I need to translate phrases "na skladě" and "'Dostupné na objednávku', 'Na objednávku do 3 - 7 týdnů'"

URL of site: hidden link

May 12, 2019 at 11:02 am #3792845

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

Please refer :
1. https://wpml.org/forums/topic/how-to-best-translate-string-in-php-template/#post-2795659
2. https://wpml.org/forums/topic/translate-strings-function-php-child-theme/#post-2207051
3. https://wpml.org/forums/topic/making-string-translatable/#post-3084588

After the changes do not forget to click on WPML > Theme and Plugins Translations. Look for 'Strings in the theme' and click on the 'Scan the theme for strings' button.

Let me know how it goes.

Regards,
Riffaz.

May 12, 2019 at 3:16 pm #3793191

tomasD-10

Hello,
I have tried to edit my code about 5 times related to the links you sent me, but nothing worked. Probably I am editing the code in a bad way.

May 13, 2019 at 10:25 am #3796931

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Follow this structure :

echo '<div class="remaining">' . number_format($product->stock,0,'','') . ' ' . __('na skladě', 'my-text-domain') . '</div>';

just replace 'my-text-domain' with the domain name of yours.
whatever you use there can be used to find the string later in WPML -> ST

Let me know how it goes.

Regards,

May 13, 2019 at 12:18 pm #3798029

tomasD-10

Hello,
I have tried to add your code. After I did it, my code stopped to work. I was able to find the string in ST, but after I completed translation, I saw that phrase in the header as bad php. I put back my original source code, but the function does not work anymore. Do you want to grant access to WP?

May 13, 2019 at 4:38 pm #3800643

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Ok, let me know your site login details.
The next reply is private.

Also, let me know how and where to check this function.

Regards,

May 14, 2019 at 10:21 am #3805849

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

I escalated to this to our second tier support.
Please be patient till we get back to you.

Regards,

May 15, 2019 at 6:48 am #3812633

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

They replied:

in your suggested code, you have one more ' element that should be removed.

echo '<div class="remaining">' . number_format($product->stock,0,'','') . ' ' . __('na skladě', 'my-text-domain') . '</div>';

should become

echo '<div class="remaining">' . number_format($product->stock,0,'','')  . __('na skladě', 'my-text-domain') . '</div>';

Could you please check this and let me know?

Regards,

May 15, 2019 at 2:53 pm #3818029

tomasD-10

Hello,
this code works for me. Could I ask about the second code I have added?

I mean this one:
add_action('woocommerce_after_shop_loop_item','show_stock', 10);

function backorder_text($availability) {

foreach($availability as $i) {

//$availability = str_replace('Dostupné na objednávku', 'Na objednávku do 3 - 7 týdnů', $availability);

$availability = str_replace('Dostupné na objednávku', 'Na objednávku do 3 - 7 týdnů', $availability);
}
return $availability;
}
add_filter('woocommerce_get_availability', 'backorder_text');

In english it shows only in "Available on backorder" instead of "On order within 3 - 7 weeks."

May 16, 2019 at 5:54 am #3822071

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Great, it works now.

The second one needs a simple hack.
I'll update you again once I checked this with the team.

Regards,

May 16, 2019 at 6:43 am #3822261

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Add replaced that with this

$availability = str_replace('Dostupné na objednávku', __( 'Na objednávku do 3 - 7 týdnů', 'text-domain') , $availability);

and it shows up in the String Translation : hidden link

Anyhow, you are trying to replace programmatically a string that your theme or something else already sets.
That is actually not a function of WPML and so it falls into custom work.

Regards,

May 16, 2019 at 7:33 am #3822635

tomasD-10

Hello,
thank you for your reply. I found the string in TS, but the translation do not show on Front end.

May 16, 2019 at 8:11 am #3823017

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Your function has no this phrase: Available on backorder
So where does it come from?
It should be from somewhere else I think.
Did you check that phrase in String Translation?

May 16, 2019 at 8:35 am #3823283

tomasD-10

The code I sent do this: Available on backorder (English string in Woocomerce) = Dostupné na objednávku (Czech) and the code changes Dostupné na objednávku for another text. But it also overwrite the source code "Abailable on backorder". I think it is too complicated to translate this code.

We will keep it.

Thank you for your help!

May 16, 2019 at 8:55 am #3823397

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

I checked with the development team and they say this will require a lot of conditional and advanced PHP coding which is out of the support scope.
If you want you can check the contractors for this.
I sent the link already in a previous reply.

Regards,