Skip Navigation

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 17:00 10:00 – 17:00 10:00 – 17:00 10:00 – 17:00 10:00 – 17:00 -
- 18:00 – 19:00 18:00 – 19:00 18:00 – 19:00 18:00 – 19:00 18:00 – 19:00 -

Supporter timezone: Asia/Kathmandu (GMT+05:45)

This topic contains 5 replies, has 2 voices.

Last updated by Shekhar Bhandari 7 months ago.

Assisted by: Shekhar Bhandari.

Author Posts
September 25, 2023 at 2:00 am #14454197

vayawebs

I'm trying to translate the 'Choose an option' text that I added with Code Snippets plugin, but it doesn't appear on String Translation page:

function custom_wc_choose_option_text( $translated_text, $text, $domain ) {
if ( $domain === 'woocommerce' && $text === 'Choose an option' ) {
$translated_text = __( 'Choose a size', 'hello-elementor' ); // Change this text to your desired replacement
}
return $translated_text;
}
add_filter( 'gettext', 'custom_wc_choose_option_text', 20, 3 );

September 25, 2023 at 5:27 am #14454329

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello @vayawebs,

Before your question goes to someone else on my team, let me explain some first steps to help you. This will make getting support faster.

From the example you provided, there are two texts available
1) Choose an option
2) Choose a size

The 2nd one should be translated without any issue, the 1st one is added as an if/else condition so it will not be available for translations, in general, any code that's being printed/displayed should be translated.

If you want to check multiple items as either or for translations you can modify the code accordingly.

if ( $domain === 'woocommerce' && ( $text === 'Choose an option' || $text === 'Translated choose an option' ) ) {
    // Your code here if the condition is met
}

The above code checks if either the text is choose an option or Translated choose an option.

Let me know if this helps.

Thanks

September 25, 2023 at 8:15 am #14455433

vayawebs

Hi Shekhar,

I replaced the code but now the text "Choose an option" doesn't change on English version (hidden link). However, I can translate it into the other languages. How can I fix it?

Thank you,

Daniel

September 25, 2023 at 10:37 am #14457145

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

As mentioned in my previous reply, with the mentioned code, you can't translate "Choose a options" I think it's added using themes or plugins so please follow the below steps:

- Go to WPML->Strings Translations->Auto Register strings for translations
- Enable the "Look for strings while pages are rendered" options
- Now visit the page on front-end where string is shown, this will automatically register strings from that page
- Now go to WPML->Strings Translations->Auto Register strings for translations and disable the options
- Search for the strings in WPML->String Translations and translate it

or

- Go to WPML->String Translations
- At the bottom of the String Translation table, click on “Translate link in admin screens”
- Search for the strings there and see if you can find it.
- If you are able to find it, select it and add it using “Add to string translation” button
- Click on “Return to String Translations”
- Translate it

Let us know if this helps.

Thanks

September 26, 2023 at 12:56 am #14462669

vayawebs

Hi Shekhar,

On your first message you said "The 2nd one should be translated without any issue", but this is wrong because the text I can translate is the 1st one "Choose an option", as you can see on the screenshot I'm attaching.

So with my snippet I could change the text "Choose an option" to "Choose a size" but I can't translate "Choose a size". How can I translate it?

Thank you,

Daniel

Screen Shot 2023-09-26 at 8.51.17 AM.png
September 27, 2023 at 10:57 am #14473111

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Have you tried the steps I mentioned here: https://wpml.org/forums/topic/snippets-translation/#post-14457145

If the problem still exists, To debug this issue further, I would need to check your site settings once, for this I would need temporary access (wp-admin and ftp) to your site.

So could you please provide me with those details, you will find the needed fields for this below the comment area when you log in to leave your next reply.
hidden link

This info is private and available to you and WPML supporters only.
Read more about this: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Note:
Backup your sites before providing the credentials or if possible provide credentials for the test site

Look forward to your reply.

Thanks

The topic ‘[Closed] Snippets translation’ is closed to new replies.