Fallback to generic language file when specific locale file absent

  1. Claude Vedovini


    Let's allow plugin and theme developers to provide generic language files.

    For example, I am French, I usually provide French translations with my plugins that actually are fr_FR, but someone with a fr_CA install won't get them despite the fact that fr_FR will likely be good enough.

    so the idea would be to let me provide fr only files that would be loaded in a fr_CA settings instead of falling back to English.

    I actually wrote a blog post about that, with code, here: http://vedovini.net/2013/12/smart-fallback-mechanism-for-loading-text-domains-in-wordpress/

    Posted: 3 years ago #
  2. Devin Price


    Hi Claude. This is a great idea. I've started looking into how a patch for this might work.

    The .mo file is defined like this:
    $mofile = $domain . '-' . $locale . '.mo';

    For a plugin the lookup goes like this:

    1. Find $mofile load_textdomain( $domain, $path . '/'. $mofile )
    2. Find $mofile in WP_LANG_DIR . '/plugins/' . $mofile;

    If that's not found, we could default to a non-localized version of the language:

    $mofile = $domain . '.mo';

    1. Find $mofile load_textdomain( $domain, $path . '/'. $mofile )
    2. Find $mofile in WP_LANG_DIR . '/plugins/' . $mofile;

    If a non-localized version of the language is not supported (which is very likely in the beginning, since no one is doing it), we'd probably want to make one more attempt at a native language before falling back to English.

    a) We could stack rank languages by size of population (e.g. en_us, en_gb, en_ca, en_au). This would make sense, but might be difficult to maintain.
    b) We could sort locales alphabetically, which might cause some random locales to load before more well-used one, but would be easier to maintain.
    c) A mix of both. If population stack rank exists, use it. If not, sort alpha.

    Finally, if no localization is found, fallback to en_us.

    Let me know if you have any feedback. I'll post a link once I get a patch together.

    Posted: 2 years ago #
  3. Devin Price


    I started a ticket for this:

    I also created a plugin to load fallbacks:

    Posted: 2 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    5 Votes
  • Status

    This idea is under consideration