WordPress.org

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: 3 years ago #
  2. Devin Price
    Inactive

    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: 3 years ago #
  3. Devin Price
    Inactive

    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: 3 years ago #
  4. sagenda
    Inactive

    12345

    Hello

    Right, we should be able to do one single file ".fr" and all ".fr_FR", ".fr_BE", ".fr_CA" will fallback on this if not existing.

    Most systems work like this, such as .NET .resx files and lots of other CMS.

    Posted: 6 months ago #
  5. Devin Price
    Inactive

    12345

    This project is now being discussed here: https://make.wordpress.org/core/tag/preferred-languages/

    Posted: 6 months ago #
  6. Claude Vedovini
    Member

    12345

    that stuff took a life of it's own under the impulse of the translators but the work now being done under #preferred-languages has little to do with what I was initially talking about. All of this because the translators don't want to decide what language variant should be in the .fr file, for example, despite the fact that no one (and certainly not me) ever ask them to make that decision, or asked them anything for that matter.

    Posted: 6 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    6 Votes
  • Status

    This idea is under consideration