Skip to:
Content
Pages
Categories
Search
Top
Bottom

Localize your BuddyPress plugins


  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    For plugin authors, it will be easier for your audience if you localize your plugins. This means more than just wrapping text in “__” and “_e” functions.

    1. You need a directory to put your po/mo files, preferably wp-content/plugins/your-plugin/languages/.

      You also need to make sure all of your plugin files exist within the same root folder and not have one go in /wp-content/plugins/ and the rest within /wp-content/plugins/your-plugin/.

      Why?

      For those of us that localize your files with a Po/mo editor, the file outside of the folder is missed in the scan, and those strings aren’t added to the translatable strings.

    2. You need to make sure you have your own textdomain and not rely on BuddyPress’s or WordPress’s.

      __( 'Title of page', 'your-own-text-domain' );

      Why?

      Because when theme authors want to use your plugin, they will need to know which translation files to edit to output the desired text without modifying your plugin to pieces.

    3. Be sure to include your language files gracefully. Use a method like…
      function bp_load_your_plugin_textdomain() {
      $locale = apply_filters( 'bp_load_your_plugin_textdomain', get_locale() );
      $mofile = WP_PLUGIN_DIR . "/bp-your-plugin/languages/bp-your-plugin-$locale.mo";
      if ( file_exists( $mofile ) )
      load_textdomain( 'bp-your-plugin', $mofile );
      }
      add_action ( 'plugins_loaded', 'bp_load_your_plugin_textdomain', 9 );

      Why?

      Because otherwise your translations will never load, or they will load out of order with the other plugins and cause things to get prematurely loaded that shouldn’t be.

    In all honestly very few, if any, plugins currently handle localization correctly. Even outside of the BuddyPress world there are thousands of plugins that are English only without a method to localize them properly.

    Taking the steps mentioned above will really help widen the audience of your plugin, and make sure that your users are able to translate and modify the verbiage it uses without hacking the core.

  • The topic ‘Localize your BuddyPress plugins’ is closed to new replies.
Skip to toolbar