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 thread is resolved. Here is a description of the problem and solution.

Problem: I created a custom snippet in PHP and I don't know how can I translate it.

Solution: https://wpml.org/forums/topic/i-need-help-translating-a-snip/#post-4290471

This topic contains 4 replies, has 2 voices.

Last updated by javierr-35 2 months, 3 weeks ago.

Assigned support staff: Mihai Apetrei.

Author Posts
July 26, 2019 at 11:00 am #4289259

javierr-35

add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
$new_str = $str . ' <br><br><b>IMPORTANT: If you do not receive your availability response, check your “spam” or “spam” email or check that the email you have given us is correct. </b><br><br>Read carefully the instructions to make the payment of the deposit and information on how to get to the surf camp.';
return $new_str;
}

i cant seem to translate that string

July 26, 2019 at 3:34 pm #4290471

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi and thank you for contacting WPML Support!

I will be happy to help you with this.

Please use this instead of that part from the code that you have:

$str . __(' <br><br><b>IMPORTANT: If you do not receive your availability response, check your "spam" or "spam" email or check that the email you have given us is correct. </b><br><br>Read carefully the instructions to make the payment of the deposit and information on how to get to the surf camp.', "my-custom-domain");

Here is some helpful documentation for that:
https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

After saving it, please see if you can now find it in WPML > String Translation.

If you don't, you might need to scan the theme that's generating the strings and then go back to WPML > String Translation and see if the strings show up:
https://wpml.org/documentation/getting-started-guide/theme-localization/

Please let me know if this solved your issue or if you still need help.

I will be waiting for your response.

Just a note that I won't be working on the weekend so I will be able to get back to you at the beginning of next week.

Kind regards,
Mihai Apetrei

July 27, 2019 at 9:52 am #4293071

javierr-35

hi thanks mihai, but im runnin in to the next issue each time i save it i will get this error in the front end this is the new code added

add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
$new_str = $str . _(' <br><br><b>IMPORTANT: If you do not receive your availability response, check your "spam" or "spam" email or check that the email you have given us is correct. </b><br><br>Read carefully the instructions to make the payment of the deposit and information on how to get to the surf camp.', "Blackstone");
return $new_str;
}

error code Warning: _() expects exactly 1 parameter, 2 given in /homepages/5/d358190389/htdocs/clickandbuilds/BLACKSTONESURFCAMP/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()'d code on line 3

July 29, 2019 at 1:11 pm #4300061

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi.

I think the issue might be due to the fact that you are using just one underscore instead of two.

I am attaching a screenshot - there we will need to have 2 underscores, one next to each other, instead of just one.

Like this:

__(

Please let me know how that goes and if that solved the issue.

Kind regards,
Mihai

July 29, 2019 at 2:46 pm #4301055

javierr-35

My issue is resolved now. Thank you!