WordPress.org

Ready to get started?Download WordPress

Ideas

Fallback to generic language file when specific locale file absent

  1. Claude Vedovini
    Member

    12345

    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: 6 months ago #
  2. Devin Price
    Member

    12345

    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 months ago #
  3. Devin Price
    Member

    12345

    I started a ticket for this:
    https://core.trac.wordpress.org/ticket/28197

    I also created a plugin to load fallbacks:
    https://github.com/devinsays/fallback-languages

    Posted: 2 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    3 Votes
  • Status

    This idea is under consideration