Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Internationalisation for WordPress Developers

Internationalisation for WordPress Developers

In this presentation I cover the concepts and terminology of internationalisation, the three core steps needed to internationalise your WordPress plugin or theme, some best practices, and advanced considerations to make the lives of your translators easier.

Video: https://wordpress.tv/2016/05/30/john-blackbourn-internationalisation-for-wordpress-developers/

This session has been presented at:

* Global WordPress Translation Day, April 2016
* WordCamp Europe Contributor Day, June 2016
* WordCamp Brighton Contributor Day, July 2016
* WordSesh, August 2016

John Blackbourn

June 26, 2016
Tweet

More Decks by John Blackbourn

Other Decks in Technology

Transcript

  1. __() and _e() echo 'Hello, World!'; _e( 'Hello, World!', 'my-plugin'

    ); echo __( 'Hello, World!', 'my-plugin' ); Step 1:
  2. echo 'Hello, World!'; _e( 'Hello, World!', 'my-plugin' ); echo __(

    'Hello, World!', 'my-plugin' ); Step 1: __() and _e()
  3. Loading MO Files Step 2: add_action( 'init', function() { load_plugin_textdomain(

    'my-plugin', false, dirname( __FILE__ ) . '/languages' ); } );
  4. Loading MO Files Step 2: add_action( 'after_setup_theme', function() { load_theme_textdomain(

    'my-theme', get_template_directory() . '/languages' ); } );
  5. Localised Headers Step 3: /* Plugin Name: My Plugin Author:

    John Blackbourn Description: My excellent plugin Version: 1.0 Text Domain: my-plugin Domain Path: /languages */
  6. Localised Headers Step 3: /* Theme Name: My Theme Author:

    John Blackbourn Description: My excellent theme Version: 1.0 Text Domain: my-plugin Domain Path: /languages */
  7. Context /* translators: column name header */ $col = __(

    'Comments', 'my-plugin' ); via translator comments
  8. Context _x() and _ex() Used to disambiguate text for translation

    Translator Comments Used to provide further context for translators
  9. Formatted Strings $text = __( 'Hello, World!', 'my-plugin' ); $text

    = __( "Hello, {$name}!", 'my-plugin' ); No!
  10. Formatted Strings $text = __( 'Hello, ', 'my-plugin' ); $text

    .= $name; $text .= __( '!', 'my-plugin' ); No!
  11. Formatted Strings $text = sprintf( /* translators: 1: user name

    */ __( 'Hello, %s!', 'my-plugin' ), $name ); via sprintf()
  12. Numbers $text = sprintf( /* translators: 1: number of posts

    */ _n( '%s Post', '%s Posts', $count, 'my-plugin' ), $count ); via sprintf() and _n()
  13. Numbers if ( 1 === $deleted ) { $message =

    __( 'Theme deleted.' ); } else { $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted ); } via sprintf() and _n()
  14. Numbers $label = _n_noop( 'Image (%s)', 'Images(%s)' ); echo sprintf(

    translate_nooped_plural( $label, $count ), $count ); via _n_noop()
  15. HTML in Strings $text = sprintf( /* translators: 1: user

    name */ __( 'Hello, %s!', 'my-plugin' ), $name );
  16. HTML in Strings $text = sprintf( /* translators: 1: user

    name */ __( 'Hello, <b>%s</b>!', 'my-plugin' ), $name ); Not great
  17. HTML in Strings $text = sprintf( /* translators: 1: user

    name */ __( 'Hello, %s!', 'my-plugin' ), '<b>' . $name . '</b>' ); Better