Skip to:
Content

BuddyPress.org

Changeset 9247


Ignore:
Timestamp:
12/21/2014 11:23:43 AM (10 years ago)
Author:
imath
Message:

Make sure custom language files (if they exist) are taking precedence over GlotPress language packs

There can be cases where a community needs cutom language files. In order to make sure these custom language files are loaded, BuddyPress will first check 2 locations before loading the GlotPress language packs :

  • WP_LANG_DIR . '/buddypress'
  • WP_LANG_DIR

Using the WP_LANG_DIR . '/buddypress' location for the custom language files avoids the mo file name to be listed into the site's language setting of the WordPress general options.

We are also introducing a new filter 'buddypress_locale_locations' so that it's possible to add a custom location to the ones listed above.

Props r-a-y, boonebgorges,danbp,DJPaul

Fixes #5887

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r9242 r9247  
    17471747 */
    17481748function bp_core_load_buddypress_textdomain() {
    1749     // Try to load via load_plugin_textdomain() first, for future
    1750     // wordpress.org translation downloads
    1751     if ( load_plugin_textdomain( 'buddypress', false, 'buddypress/bp-languages' ) ) {
    1752         return true;
    1753     }
    1754 
    1755     // Nothing found in bp-languages, so try to load from WP_LANG_DIR
    1756     $locale = apply_filters( 'buddypress_locale', get_locale() );
    1757     $mofile = WP_LANG_DIR . '/buddypress-' . $locale . '.mo';
    1758 
    1759     return load_textdomain( 'buddypress', $mofile );
     1749    $domain = 'buddypress';
     1750    $mofile_custom = sprintf( '%s-%s.mo', $domain, apply_filters( 'buddypress_locale', get_locale() ) );
     1751
     1752    $locations = apply_filters( 'buddypress_locale_locations', array(
     1753        trailingslashit( WP_LANG_DIR . '/' . $domain  ),
     1754        trailingslashit( WP_LANG_DIR ),
     1755    ) );
     1756
     1757    // Try custom locations in WP_LANG_DIR
     1758    foreach ( $locations as $location ) {
     1759        if ( load_textdomain( 'buddypress', $location . $mofile_custom ) ) {
     1760            return true;
     1761        }
     1762    }
     1763
     1764    // default to WP and glotpress
     1765    return load_plugin_textdomain( $domain );
    17601766}
    17611767add_action ( 'bp_core_loaded', 'bp_core_load_buddypress_textdomain' );
Note: See TracChangeset for help on using the changeset viewer.