[Resolved] String Translation no longer functioning during save_post
This thread is resolved. Here is a description of the problem and solution.
Problem: You are encountering an issue where gettext functions used in an export mechanism on post save are not utilizing String Translation. This occurs despite using an identical template that works correctly elsewhere. The issue is visible when default English values for CTAs appear, suggesting that translations are not being applied. Solution: We have determined that the issues you are experiencing are due to errors in the custom code within the 'hope_ind-plugin'. Since this falls outside our standard support policy, we recommend consulting with a professional. If you need help troubleshooting or fixing the custom code, consider reaching out to a certified WPML contractor for specialized assistance.
Please note that this solution might be outdated or not applicable to your specific case. We highly recommend 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. If the issue persists, please open a new support ticket.
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 appears to resolve the issue, at least for standard string translations. However, there is still another aspect related to recent changes in WordPress and how text domains are loaded.
Simply relying on _load_textdomain_just_in_time() is not sufficient, as this method depends on the .mo file being registered in wp_textdomain_registry. Without load_plugin_textdomain(), this registration does not occur, causing _load_textdomain_just_in_time() to fail and return false. As a result, the translation appears loaded but is actually an instance of NOOP_Translations, meaning it is effectively empty.
We suspect that executing this logic on acf/save_post may be too early in the process, possibly before the locale has fully switched. We are still investigating this in combination with switch_to_locale() and will keep you updated.
I've added the hook for init:
add_action( 'init', 'hope_industrial_textdomain' );
function hope_industrial_textdomain() {
error_log("We're loading the hope_industrial domain (.mo file doesn't exist, but this should engage WPML strings in db)");
load_plugin_textdomain( 'hope_industrial', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
and I've added the switch_locale call at the beginning of the export:
// Figure out which language we're updating
$lang = apply_filters( 'wpml_post_language_details', NULL, $id );
switch_to_locale($lang['locale']);
error_log("We just switched to the {$lang['locale']} locale.");
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: Europe/Madrid (GMT+02:00)
Hi,
I checked the output log uploaded to Pastebin and noticed that after switching the locale to Italian, most of the strings appear in Italian. Could you clarify the exact issue? From what I see, the content is correctly displayed in Italian.
Regarding execution, the text domain was initially attempted to load just-in-time using the string "Invoices", but since the locale at that moment was still set to English, it was loaded as an instance of the NOOP_Translations class—meaning no translations were available.
By applying the suggested approach, we ensured that your logic correctly switches the locale within acf/save_post after retrieving it from our hook. In our test, this resulted in a valid translation being pulled from your text domain, though it contained only a handful of translations.
I'm checking the gettext responses for 'Description' and 'Features' (asked for in oro-export.php:601 or abouts) and outputting them to the log - these should be Descrizione and Proprietà respectively. Can you confirm your successful export reported these values?
The credentials in oro-api.php have changed recently, so you may not be able to complete the export until some adjustments have been made - standby.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: Europe/Madrid (GMT+02:00)
Hi,
Please note that our 2nd Tier team has already deleted the test environment, so we are unable to verify this further. However, we previously checked the array output and confirmed that it was returning IT.
That said, we can confirm that there are no errors on our side. The issues you’re experiencing originate from custom code within the "hopeind-plugin", which contains errors. Since custom development falls outside our support policy, we are unable to provide further assistance.
If you need help troubleshooting or fixing the custom code, I recommend reaching out to a certified WPML contractor for professional support.