Title: Polylang : force language before page load based
Last modified: September 6, 2016

---

# Polylang : force language before page load based

 *  Resolved [digidev](https://wordpress.org/support/users/digidev/)
 * (@digidev)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/polylang-force-language-before-page-load-based/)
 * 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](https://wordpress.org/support/users/digidev/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [digidev](https://wordpress.org/support/users/digidev/)
 * (@digidev)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/polylang-force-language-before-page-load-based/#post-8157847)
 * 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.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [digidev](https://wordpress.org/support/users/digidev/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/polylang-force-language-before-page-load-based/#post-8157847)
 * Status: resolved