×
Copy
Open
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Slide 1
Slide 1 text
Internationalisation for WordPress Developers
Slide 2
Slide 2 text
Best Practices for Internationalising Themes and Plugins
Slide 3
Slide 3 text
Terminology Translation Localisation Internationalisation t9n l10n i18n
Slide 4
Slide 4 text
Terminology Translation Localisation Internationalisation t9n l10n i18n 18
Slide 5
Slide 5 text
Internationalisation for WordPress Developers
Slide 6
Slide 6 text
i18n for w7s d8s
Slide 7
Slide 7 text
Say no to Concatenation echo $post_type . ' updated'; echo 'You have ' . $number . ' posts';
Slide 8
Slide 8 text
$text = 'Hello, World!'; $text = __( 'Hello, World!', 'my-plugin' ); Step 1: __() and _e()
Slide 9
Slide 9 text
__() and _e() echo 'Hello, World!'; _e( 'Hello, World!', 'my-plugin' ); echo __( 'Hello, World!', 'my-plugin' ); Step 1:
Slide 10
Slide 10 text
echo 'Hello, World!'; _e( 'Hello, World!', 'my-plugin' ); echo __( 'Hello, World!', 'my-plugin' ); Step 1: __() and _e()
Slide 11
Slide 11 text
Loading MO Files Step 2: add_action( 'init', function() { load_plugin_textdomain( 'my-plugin', false, dirname( __FILE__ ) . '/languages' ); } );
Slide 12
Slide 12 text
Loading MO Files Step 2: add_action( 'after_setup_theme', function() { load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' ); } );
Slide 13
Slide 13 text
wp-content/plugins/my-plugin/languages
Slide 14
Slide 14 text
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 */
Slide 15
Slide 15 text
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 */
Slide 16
Slide 16 text
Step 1: __() and _e() Step 2: Loading MO Files Step 3: Localised Headers
Slide 17
Slide 17 text
Context _e( 'Comment', 'my-plugin' ); // A comment _e( 'Comment', 'my-plugin' ); // To comment
Slide 18
Slide 18 text
Context _ex( 'Comment', 'noun', 'my-plugin' ); _ex( 'Comment', 'verb', 'my-plugin' ); via _x() and _ex() Kommentar / Kommentieren
Slide 19
Slide 19 text
Context /* translators: column name header */ $col = __( 'Comments', 'my-plugin' ); via translator comments
Slide 20
Slide 20 text
Context _x() and _ex() Used to disambiguate text for translation Translator Comments Used to provide further context for translators
Slide 21
Slide 21 text
Formatted Strings $text = __( 'Hello, World!', 'my-plugin' ); $text = __( "Hello, {$name}!", 'my-plugin' ); No!
Slide 22
Slide 22 text
Formatted Strings $text = __( 'Hello, ', 'my-plugin' ); $text .= $name; $text .= __( '!', 'my-plugin' ); No!
Slide 23
Slide 23 text
Formatted Strings $text = sprintf( /* translators: 1: user name */ __( 'Hello, %s!', 'my-plugin' ), $name ); via sprintf()
Slide 24
Slide 24 text
Numbers $text = __( "You have {$count} posts", 'my-plugin' ); No!
Slide 25
Slide 25 text
Numbers $text = sprintf( /* translators: 1: number of posts */ _n( '%s Post', '%s Posts', $count, 'my-plugin' ), $count ); via sprintf() and _n()
Slide 26
Slide 26 text
Numbers if ( 1 === $deleted ) { $message = __( 'Theme deleted.' ); } else { $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted ); } via sprintf() and _n()
Slide 27
Slide 27 text
Numbers $label = _n_noop( 'Image (%s)', 'Images(%s)' ); echo sprintf( translate_nooped_plural( $label, $count ), $count ); via _n_noop()
Slide 28
Slide 28 text
Punctuation $text = __( 'Next Post', 'my-plugin' ); $text .= '»'; No!
Slide 29
Slide 29 text
Punctuation $text = __( 'Next Post »', 'my-plugin' ); Better
Slide 30
Slide 30 text
Security _e( 'Hello, World!', 'my-plugin' );
Slide 31
Slide 31 text
Security _e( 'Hello, World!', 'my-plugin' ); // alert("Hello!")
Slide 32
Slide 32 text
Security esc_html_e( 'Hello, World!', 'my-plugin' ); // <script>alert("Hello!")</script>
Slide 33
Slide 33 text
Security esc_attr__() esc_html__() esc_attr_e() esc_html_e() esc_attr_x() esc_html_x() esc_html( __n( ... ) )
Slide 34
Slide 34 text
HTML in Strings $text = sprintf( /* translators: 1: user name */ __( 'Hello, %s!', 'my-plugin' ), $name );
Slide 35
Slide 35 text
HTML in Strings $text = sprintf( /* translators: 1: user name */ __( 'Hello,
%s
!', 'my-plugin' ), $name ); Not great
Slide 36
Slide 36 text
HTML in Strings $text = sprintf( /* translators: 1: user name */ __( 'Hello, %s!', 'my-plugin' ), '
' . $name . '
' ); Better
Slide 37
Slide 37 text
i18n Tools translate.wordpress.org
Slide 38
Slide 38 text
i18n Tools develop.svn.wordpress.org trunk -> tools -> i18n Poedit
Slide 39
Slide 39 text
i18n Tools I18n for WordPress Developers More Information: developer.wordpress.org/plugins and
Slide 40
Slide 40 text
Test Your Knowledge! WordPress Developers: Test your i18n knowledge!
Slide 41
Slide 41 text
Internationalisation for WordPress Developers Questions!