Skip Navigation

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

Problem:
You are trying to translate a string from Hebrew to English using the

wpml_translate_single_string

hook in WPML, but it fails to translate into the website's default language (English), while it successfully translates into Russian.
Solution:
The

wpml_translate_single_string

hook does not translate into the default language because WPML assumes the string in the default language is the original value and does not store translations for it. To retrieve a translation based on the current language, use the default language string as the source and pass the current language as the target:

$current_lang = apply_filters('wpml_current_language', null);<br />$translated = apply_filters('wpml_translate_single_string', 'Subject en', 'admin_texts_woocommerce_new_order_settings', '[woocommerce_new_order_settings]subject', $current_lang);<br />error_log($translated);

This method uses the default language string ('Subject en') as the source, and WPML looks up the appropriate translation for the current language. For further understanding, you might find these guides helpful:

If this solution does not apply to your case, or if it 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: WPML 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.

This topic contains 1 reply, has 0 voices.

Last updated by rayaA 1 month, 2 weeks ago.

Assisted by: Carlos Rojas.

Author Posts
May 2, 2025 at 5:52 pm #16990459

rayaA

Background of the issue:
I am trying to get a translation into English from Hebrew of a specific string using the wpml_translate_single_string hook. I am going to WooCommerce > Settings > Emails > New order, and under Subject, I write 'Subject en' and then click on Save Changes. Then in WPML > String Translations, I search for 'Subject en' and find the string with domain admin_texts_woocommerce_new_order_settings and name [woocommerce_new_order_settings]subject. I add a translation to Hebrew 'Subject he' and to Russian 'Subject ru'. My website's default language is English. Then in my plugin's code: add_action('init', function () { $original = apply_filters('wpml_translate_single_string', 'Subject he', 'admin_texts_woocommerce_new_order_settings', '[woocommerce_new_order_settings]subject', 'en'); error_log($original); });

Symptoms:
The string will not be translated and will log 'Subject he'. However, if I change the language in the code to 'ru', then the string would be translated and will log 'Subject ru'.

Questions:
Why is the string not translating from Hebrew to English (website's default language) using the wpml_translate_single_string hook, but will translate into Russian (any language which is not the website's default language)?

May 6, 2025 at 7:39 am #16999555

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Hello,
Thank you for contacting us

The apply_filters( 'wpml_translate_single_string', ... ) hook does not translate into the default language, because WPML does not store translations for the default language — it assumes the string you originally registered (or input) is already in the default language.

In your case:
- You saved "Subject en" in the WooCommerce settings. Since English is your default language, this is treated as the source/original value.
- When you call:

apply_filters( 'wpml_translate_single_string', 'Subject he', 'admin_texts_woocommerce_new_order_settings', '[woocommerce_new_order_settings]subject', 'en' );

you're asking WPML to translate "Subject he" into English — which doesn't exist, because English is the original and WPML doesn’t track translations into the default language.

However, when you ask to translate into Russian:

apply_filters( 'wpml_translate_single_string', 'Subject he', ..., 'ru' );

WPML does return the translation, because it's stored in String Translation.

Why This Happens
WPML stores translations from the default language into secondary languages only, not the other way around.

So:
- Default (English) → Hebrew or Russian (Supported)
- Hebrew or Russian → English (not supported via this hook)

Solution / Recommendation
If you're trying to retrieve the translated version based on the current language, use the default string as the source and pass the current language as the target:

$current_lang = apply_filters( 'wpml_current_language', null );
$translated = apply_filters(
    'wpml_translate_single_string',
    'Subject en', // default language value
    'admin_texts_woocommerce_new_order_settings',
    '[woocommerce_new_order_settings]subject',
    $current_lang
);
error_log($translated);

This way:
- You're using the default language string ('Subject en') as the source.
- WPML looks up the appropriate translation for the current language, which can be Hebrew or Russian.

I'd recommend checking these guides that might help you understand this behavior better and find a solution:
- https://wpml.org/wpml-hook/wpml_translate_single_string/
- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#wpml_translate_single_string

Regards,
Carlos

May 7, 2025 at 11:37 am #17006207

rayaA

Thank you!