Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is trying to translate customized fields using WPML but encounters an issue where the translations do not appear on the frontend. The client used a custom hook and registered labels to WPML, translating them successfully. However, despite following documentation and using code examples, the translations are not visible on the frontend.
Solution:
1. Ensure the text domain is correct. According to WordPress documentation, the text domain must use dashes, be lowercase, and have no spaces.
2. When using variables in translated strings, use the

printf()

function instead of echoing the variable directly. For example, change:

<p id="popup-title"><?= $popuptitle ?></p>

to:

<p id="popup-title"><?php echo __('Subscribe Now, Save 10%', 'storefront') ?></p>

After making these changes, re-scan the strings in the child theme, translate the string, and check if the translation displays on the frontend.
3. If using a custom text domain like "popup", register it with the following function in your theme's

functions.php

file:

add_action( 'after_setup_theme', function() {
    load_theme_textdomain( 'popup', get_template_directory() . '/languages' );
} );

Refer to the WordPress documentation on loading a text domain for more details.

If this solution does not resolve your issue or seems outdated, we recommend opening a new support ticket. We also highly suggest checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum.

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.

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by zurongz 1 month, 1 week ago.

Assisted by: Long Nguyen.

Author Posts
November 21, 2024 at 5:47 am #16427277

zurongz

Background of the issue:
I am trying to translate customized fields on my site hidden link using WPML. I created a hook and registered the label to WPML. The labels were discovered, and I translated them. I am following some documentation with code examples like $button = __('SHOP NOW', 'popup'); $thanks = __('THANK YOU!', 'popup');.

Symptoms:
Part of the customized fields is translated but doesn't show the translation version at the front end.

Questions:
Why are the translated customized fields not showing at the front end?

November 21, 2024 at 6:55 am #16427387

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi there,

Thank you for contacting WPML support, I’m happy to help you with this issue.

Can you please let me know where the strings are displayed in the frontend? I suggest you update WPML plugins to the new version
WPML Multilingual CMS 4.6.14.
WPML String Translation 3.2.15.
and follow the documentation below to scan strings and translate them https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/

Let me know how it goes.

November 21, 2024 at 9:07 am #16427961

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

According to the WordPress documentation https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/

1. The text domain isn't correct:
The text domain name must use dashes and not underscores, be lower case, and have no spaces.

2. You should echo the literal string instead of a variable, if you use a variable in the string, please use the printf() function. I change the code from

<p id="popup-title"><?= $popuptitle ?></p>

to

<p id="popup-title"><?php echo __('Subscribe Now, Save 10%', 'storefront') ?></p>

then I re-scan strings in the child theme, translate the string and the translation displayed in the frontend as well. Please check the attached screenshot.

Looking forward to your reply.
Thanks

Bring You Closer to the Wildlife with IP Technology - Green Backyard 2024-11-21 16-01-21.jpg
November 21, 2024 at 9:58 am #16428162

zurongz

Thanks for your effort. I followed your instructions replaced the variable with printf(), and made the translation for the first language (German). Everything worked as expected. Then I translated the second language (French). Now everything turns back to Engish again even for the German page. Somehow it triggered the issue after I saved the translation for French.

Could you please check it again?

Screenshot 2024-11-21 at 5.57.34 PM.png
November 22, 2024 at 1:37 am #16431465

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

If you want to use a custom text domain "popup", you need to register the text domain with the following function:

add_action( 'after_setup_theme', function() {
    load_theme_textdomain( 'popup', get_template_directory() . '/languages' );
} );

I add it to the file functions.php in the child theme folder and the translation strings are displayed in the frontend correctly.

Following the WordPress documentation https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#loading-text-domain

Thanks.

Bring You Closer to the Wildlife with IP Technology - Green Backyard 2024-11-22 08-36-15.jpg
Bring You Closer to the Wildlife with IP Technology - Green Backyard 2024-11-22 08-29-01.jpg
November 22, 2024 at 7:49 am #16432022

zurongz

Thank you. You are amazing!