I’d like to translate one error message from a plugin that blocks spam from our forms but occasionally blocks legitimate (live-person) form submissions. The message is coded to be translateable – in the plugin itself, the line is:

$err_msg = __( 'That action is currently not allowed.' );

My problem is, my site is already in U.S. English just like the plugin, and technically when I “translate” this string so that visitors see a “it’s not your fault; please contact so-and-so so we can fix this issue for you” message, it will still be in U.S. English. I’ve set up a textdomain in my theme and was able to generate the .pot, .po and .mo files to translate this one string. The problem is, since I’m setting wp-config to en_US, it’s not actually changing anything.

Since I don’t have an exact process to trigger the error on the forms themselves, I set up an admin dashboard widget to test the translation. Sure enough, if the contents of the widget are

$err_msg = __( 'That action is currently not allowed.' );
echo $err_msg;

I get ‘That action is currently not allowed.’ If I change the widget contents to

$err_msg = __( 'That action is currently not allowed.', 'mytextdomain' );
echo $err_msg;

I get the custom message that I’m trying to achieve.

I don’t want to edit the plugin’s files themselves since they would revert every time there’s an update. There’s no filter or hook in the plugin for this particular message – there are filters for other errors, just not this generic one. Is there a better approach to getting this one string of user-facing text changed? I want something server-side rather than a JS/jQuery solution, if at all possible.

Read more here: Translating an error message


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: