• Resolved dcrystalj

    (@dcrystalj)


    Is there function to check if translation for current language for specific field/post exists?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @dcrystalj
    You can use wpm_is_ml_string() for check if it is multilingual string. Then You can use preg_match for find multilinagual tag for needed language.

    Thread Starter dcrystalj

    (@dcrystalj)

    Thank you.

    I managed to write helper for this:

    		function wpm_trans_exists($str, $lang) {
    			if (!wpm_is_ml_string($str)) {
    				return false;
    			}
    			preg_match('/\[:'. $lang .'\]/', $str, $matches, PREG_OFFSET_CAPTURE, 0);
    			return count($matches) > 0;
    		}

    do you know how can i get current selected language string? like ‘en’ ?

    • This reply was modified 8 years, 3 months ago by dcrystalj.

    Hi @dcrystalj
    What language are You need? Current localization language or current edit language?
    For get current language, You can use ‘wpm_get_language()’. For get current edit language(only in admin) You can use: $edit_lang = !empty($_GET['edit_lang']) ? $_GET['edit_lang'] : get_user_meta( get_current_user_id(), 'edit_lang', true );.

    • This reply was modified 8 years, 3 months ago by VaLeXaR.
    Thread Starter dcrystalj

    (@dcrystalj)

    thank you sir!

    wpm_get_language saved my day. You really should add this function to github readme/docs

    • This reply was modified 8 years, 3 months ago by dcrystalj.
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Has translation’ is closed to new replies.