Support » Plugins » Hacks » locale vs. load_textdomain

  • I needed to make modifications to existing code to act as a language switcher. So I looked at existing plugins and other questions posted on the topic, and there was a lot of references to various hooks:


    ..and other override hooks for these as well.

    Documentation is horrible on these, and the language switcher code is pretty complex. But then I found the locale() hook, and just returning the iso code from that seems to do the trick just fine.

    Am I missing something? If locale() makes it that easy, why all these other textdomain hooks?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    Passing the language iso code to, and executing locale() will do nothing on it’s own, unless the matching language files have been loaded via one of the ???_textdomain() functions.

    It may work on your installation if the language files are already loaded somehow, but it will not work so easily on most installations.

    I wonder what might be loading the language files, then. I only have one plugin activated, and nowhere in it does it hook/override any of the _textdomain() functions.

    I’m working in 3.3.2

    Moderator bcworkz


    It does make a difference where locale() is executed. If executed early enough, it’ll work as expected. My difficulty occurred when I tried to use it to change the language of a specific page, not the whole installation.

    This gives me the idea to somehow force a reload of the entire environment when a user selects a new language, but in a way that will not alter the language of other threads.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘locale vs. load_textdomain’ is closed to new replies.