WordPress.org

Ready to get started?Download WordPress

Forums

locale vs. load_textdomain (4 posts)

  1. Cipherlad
    Member
    Posted 2 years ago #

    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:

    load_textdomain()
    load_default_textdomain()
    load_plugin_textdomain()
    load_theme_textdomain()
    load_textdomain_mofile()

    ..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?

  2. bcworkz
    Member
    Posted 2 years ago #

    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.

  3. Cipherlad
    Member
    Posted 2 years ago #

    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

  4. bcworkz
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic