A
A
Andrey Vasechkin2017-10-09 18:21:59
PHP
Andrey Vasechkin, 2017-10-09 18:21:59

How to put a condition in an array?

Hello dear!
I'm making a multilingual website using wpml. There is a function wp_json_send_error in which you need to apply a condition.
Here is the condition

<?php if(ICL_LANGUAGE_CODE=='en'): ?>Email error<?php elseif(ICL_LANGUAGE_CODE=='it'): ?>Email error<?php elseif(ICL_LANGUAGE_CODE=='ru'): ?>Неправильный email<?php endif; ?>

Here is a function in the code (there are a lot of them and you need to translate everything, for example one)
wp_send_json_error(array('message' => 'Неправильный email', 'redirect' => false));

Actually, it is necessary for the condition to work in the array instead of the phrase "Wrong email", how to do it I'll never know. All my attempts were in vain.
UPD: gettext does NOT work. Language translation files are not connected when changing the language. The reason is unknown. This option is out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-10-09
@Stalker_RED

Throw away this noodle*.
Start reading from here https://codex.wordpress.org/I18n_for_WordPress_Dev...
The result will be something like this:

$err_msg = __('Email error', LANGUAGE_CODE);
wp_send_json_error(array('message' => $err_msg, 'redirect' => false));

or so
------------------------------
* - it is possible together with wordpress.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question