• Resolved digidev

    (@digidev)


    I need to force language before page loads, but I don’t see an option or a hook to do so.

    I could just replace all my pll__('string') with pll_translate_string('string','my-lang-code') but this would have to be done in many files.

    Is there an option to force the language somehow?

    Explanation: a user created a post (non-translatable) in a certain language. The language he used when creating the post, should be used to display the page and not the browser’s language or default polylang language.

    • This topic was modified 9 years, 8 months ago by digidev.
Viewing 1 replies (of 1 total)
  • Thread Starter digidev

    (@digidev)

    Ok, we got this solved using this part of code (found when backtracking polylang code):

    $lang_code = 'en'; // this way we force en for instance (here you can pass data from user's registration for example)
    global $polylang;
    $mo = new PLL_MO();
    $mo->import_from_db( $polylang->model->get_language( $lang_code ) );
    $GLOBALS['l10n']['pll_string'] = &$mo;
    $polylang->curlang = $polylang->model->get_language($lang_code); 
Viewing 1 replies (of 1 total)

The topic ‘Polylang : force language before page load based’ is closed to new replies.