SlideShare a Scribd company logo
Internationalization for
Plugin and Theme Developers
Sergey Biryukov
WordCamp Milano 2016
Sergey Biryukov
● WordPress Core Contributor at Yoast
yoast.com
● Co-founder of Russian WP community
ru.wordpress.org
● Polyglots, Support, and Meta teams
sergeybiryukov.com
@SergeyBiryukov
Plugins and Themes for the Whole World
● Internationalization (i18n) — providing the ability to translate
● Localization (L10n) — translating to a particular language
Plugins and Themes for the Whole World
● Over 100 languages
● More robust code
● Feedback
● It’s easy
Localized Theme Directories
Localized Plugin Directories
Introduction to gettext
● Text domain
– 'my-plugin'
● Preparing the strings
– <?php echo 'Title'; ?>→<?php _e( 'Title', 'my-plugin' ); ?>
● Language files
– .pot, .po, .mo
Text Domain
● Should match the plugin/theme slug (folder name):
– wp-content/plugins/my-plugin→'my-plugin'
– wp-content/themes/my-theme→'my-theme'
● Should be added to plugin/theme headers:
– Plugin Name: My Plugin
– Version: 1.0
– Text Domain: my-plugin
Text Domain
● Loading the text domain
– load_plugin_textdomain( 'my-plugin', false,
dirname( plugin_basename( __FILE__ ) ) . '/languages' );
– load_theme_textdomain( 'my-theme',
get_template_directory() . '/languages' );
Text Domain
● Loading the text domain
– load_plugin_textdomain( 'my-plugin', false,
dirname( plugin_basename( __FILE__ ) ) . '/languages' );
– load_theme_textdomain( 'my-theme',
get_template_directory() . '/languages' );
● wp-content/languages (WordPress 4.6+)
Preparing the Strings
● Regular strings:
– __( 'Hello world!', 'my-plugin' );
– _e( 'Hello world!', 'my-plugin' );
● Strings with context:
– _x( 'Hello world!', 'post title', 'my-plugin' );
– _ex( 'Hello world!', 'post title', 'my-plugin' );
Preparing the Strings
● Plural forms:
– _n( '%d item', '%d items', $count, 'my-plugin' );
– _nx( '%d item', '%d items', $count, 'comments', 'my-plugin' );
● If the number is not available yet:
– _n_noop( '%d item', '%d items', 'my-plugin' );
– _nx_noop('%d item', '%d items', 'comments', 'my-plugin' );
Preparing the Strings
● Escaping HTML tags:
– esc_html__( 'Hello <em>world</em>!', 'my-plugin' );
– esc_html_e( 'Hello <em>world</em>!', 'my-plugin' );
– esc_html_x( 'Hello <em>world</em>!', 'post title', 'my-plugin' );
● Escaping HTML attributes:
– esc_attr__( 'Hello "world"!', 'my-plugin' );
– esc_attr_e( 'Hello "world"!', 'my-plugin' );
– esc_attr_x( 'Hello "world"!', 'post title', 'my-plugin' );
Preparing the Strings
● Escaping HTML tags and attributes:
– <option value="<?php esc_attr_e( 'value', 'my-plugin' ); ?>">
<?php esc_html_e( 'Option label', 'my-plugin' ); ?>
</option>
● Same, in a longer notation:
– <option value="<?php echo esc_attr( __( 'value', 'my-plugin' ) ); ?>">
<?php echo esc_html( __( 'Option label', 'my-plugin' ) ); ?>
</option>
_e() ≠ echo()
● Don’t use PHP variables, only simple strings:
– _e( $string ); — don’t do that.
● Provide the ability to translate whole phrases, not separate words:
– echo __( 'Hello' ) . ' ' . __( 'world!' ); — don’t do that either.
● Don’t forget the text domain:
– _e( 'Hello world!', 'my-plugin' );
● Remove unnecessary HTML markup from the strings:
– _e( '<p>Hello world!</p>', 'my-plugin' );
Context and Comments
● Context — same string, different translations:
– _x( 'redirect', 'noun', 'my-plugin' );
– _x( 'redirect', 'verb', 'my-plugin' );
● Comments — to explain placeholders in a string:
– /* translators: %s: file name */
__( '%s was deleted.', 'my-plugin' );
Plural Forms
● ???
– _e( "You have $count items.", 'my-plugin' );
– _e( 'You have ' . $count . ' items.', 'my-plugin' );
– printf( __( 'You have %d items.', 'my-plugin' ), $count );
– printf( _n( 'You have %d item.', 'You have %d items.', $count ),
$count );
Plural Forms
● Incorrect:
– _e( "You have $count items.", 'my-plugin' );
– _e( 'You have ' . $count . ' items.', 'my-plugin' );
– printf( __( 'You have %d items.', 'my-plugin' ), $count );
● Almost correct:
– printf( _n( 'You have %d item.', 'You have %d items.', $count ),
$count );
Plural Forms
● Correct:
– printf( _n( 'You have %d item.', 'You have %d items.', $count ),
number_format_i18n( $count ) );
● number_format_i18n() — for displaying numbers
● date_i18n() — for displaying dates
Plural Forms
● If the number is not available:
– $items_plural = _n_noop( 'You have %s item.', 'You have %s items',
'my-plugin' );
● ...
● After it’s available:
– printf( translate_nooped_plural( $items_plural, $count ),
number_format_i18n( $count ) );
● translate_nooped_plural() — for deferred translations of plural strings
Plural Forms
● The first form is not necessarily used for 1 item:
– printf( _n( 'Theme deleted.', '%d themes deleted.', $count ),
number_format_i18n( $count ) );
● Better:
– if ( 1 === $count ) {
_e( 'Theme deleted.' );
– } else {
printf( _n( '%d theme deleted.', '%d themes deleted.', $count ),
number_format_i18n( $count ) );
– }
Language Files
● .pot (Portable Object Template)
– Translation template, contains English strings only.
● .po (Portable Object)
– Language file in a human-readable format.
● .mo (Machine Object)
– Compiled language file in a machine-readable format.
Language Files
makepot.php→.pot→Poedit→.po/.mo→email
Plugin Changelog
● Version 1.5.6
– Added Russian translation.
– That’s it!
● Version 1.5.6.1
– Fixed a typo in Russian translation.
Language Files
makepot.php→.pot→Poedit→.po/.mo→email
translate.wordpress.org
translate.wordpress.org
translate.wordpress.org
● GTE (General Translation Editor) — locale editors
– Can check and approve all translations.
● PTE (Project Translation Editor) — project editors
– Can approve translations for a particular project.
● Translators
– Can suggest translations.
If Someone Has Sent You Their Translation
● Ask them to create a WordPress.org account
– They can be added as a Project Translation Editor.
– They would be able to import the .po file themselves.
– ...and continue translating in the future.
● Ask locale editors to import the files
– No guarantee that the plugin will continue to be actively translated.
If Someone Has Sent You Their Translation
● Once the translator has a WordPress.org account:
– Go to the Polyglots team blog:
https://make.wordpress.org/polyglots/
– Find the Polyglots Handbook link:
https://make.wordpress.org/polyglots/handbook/
– On “Theme & Plugin Directories” page, find a post template for
requesting new translation editors.
– Submit your request to the Polyglots blog and wait for a reply.
@SergeyBiryukov
Thanks! Questions?

More Related Content

What's hot

Making static sites dynamic (with WordPress yo!)
Making static sites dynamic (with WordPress yo!)Making static sites dynamic (with WordPress yo!)
Making static sites dynamic (with WordPress yo!)
Anthony Montalbano
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
Marcus Ramberg
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
Tudor Constantin
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressHristo Chakarov
 
Mojolicious
MojoliciousMojolicious
Mojolicious
Marcus Ramberg
 
Creating a Wordpress Theme from Scratch
Creating a Wordpress Theme from ScratchCreating a Wordpress Theme from Scratch
Creating a Wordpress Theme from Scratch
Patrick Rauland
 
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10min
Ivelina Dimova
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
Anatoly Sharifulin
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
Cosimo Streppone
 
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Doris Chen
 
Let's write secure drupal code!
Let's write secure drupal code!Let's write secure drupal code!
Let's write secure drupal code!
Balázs Tatár
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Dotan Dimet
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
Dave Cross
 
Wordless, stop writing WordPress themes like it's 1998
Wordless, stop writing WordPress themes like it's 1998Wordless, stop writing WordPress themes like it's 1998
Wordless, stop writing WordPress themes like it's 1998
Filippo Dino
 
How to learn j query
How to learn j queryHow to learn j query
How to learn j queryBaoyu Xu
 

What's hot (20)

Making static sites dynamic (with WordPress yo!)
Making static sites dynamic (with WordPress yo!)Making static sites dynamic (with WordPress yo!)
Making static sites dynamic (with WordPress yo!)
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
20110820 header new style
20110820 header new style20110820 header new style
20110820 header new style
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPress
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Creating a Wordpress Theme from Scratch
Creating a Wordpress Theme from ScratchCreating a Wordpress Theme from Scratch
Creating a Wordpress Theme from Scratch
 
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10min
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
 
Pp checker
Pp checkerPp checker
Pp checker
 
Let's write secure drupal code!
Let's write secure drupal code!Let's write secure drupal code!
Let's write secure drupal code!
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Wordless, stop writing WordPress themes like it's 1998
Wordless, stop writing WordPress themes like it's 1998Wordless, stop writing WordPress themes like it's 1998
Wordless, stop writing WordPress themes like it's 1998
 
How to learn j query
How to learn j queryHow to learn j query
How to learn j query
 

Viewers also liked

i18n for Plugin and Theme Developers, WordCamp Moscow 2016
i18n for Plugin and Theme Developers, WordCamp Moscow 2016i18n for Plugin and Theme Developers, WordCamp Moscow 2016
i18n for Plugin and Theme Developers, WordCamp Moscow 2016
Sergey Biryukov
 
Conception de thèmes WordPress : construire et optimiser son espace de travail
Conception de thèmes WordPress : construire  et optimiser son espace de travailConception de thèmes WordPress : construire  et optimiser son espace de travail
Conception de thèmes WordPress : construire et optimiser son espace de travail
Frédérique Game
 
How to make your WordPress website multilingual - WordCamp Paris 2016
How to make your WordPress website multilingual - WordCamp Paris 2016How to make your WordPress website multilingual - WordCamp Paris 2016
How to make your WordPress website multilingual - WordCamp Paris 2016
Matt Pilarski
 
WordPress on HHVM + Hack
WordPress on HHVM + HackWordPress on HHVM + Hack
WordPress on HHVM + Hack
Takayuki Miyauchi
 
Contributing to WordPress, WordCamp Russia 2013
Contributing to WordPress, WordCamp Russia 2013Contributing to WordPress, WordCamp Russia 2013
Contributing to WordPress, WordCamp Russia 2013
Sergey Biryukov
 
Everything You Need to Know About WP_Query, WordCamp Russia 2014
Everything You Need to Know About WP_Query, WordCamp Russia 2014Everything You Need to Know About WP_Query, WordCamp Russia 2014
Everything You Need to Know About WP_Query, WordCamp Russia 2014
Sergey Biryukov
 
Looking into WordPress Core, WordCamp Russia 2015
Looking into WordPress Core, WordCamp Russia 2015Looking into WordPress Core, WordCamp Russia 2015
Looking into WordPress Core, WordCamp Russia 2015
Sergey Biryukov
 
Моделирование контента в WordPress
Моделирование контента в WordPressМоделирование контента в WordPress
Моделирование контента в WordPress
Anna Ladoshkina
 
Composer и разработка сайтов на WordPress
Composer и разработка сайтов на WordPressComposer и разработка сайтов на WordPress
Composer и разработка сайтов на WordPress
Anna Ladoshkina
 
Managing a Local WordPress Community, WordCamp Europe 2016
Managing a Local WordPress Community, WordCamp Europe 2016Managing a Local WordPress Community, WordCamp Europe 2016
Managing a Local WordPress Community, WordCamp Europe 2016
Sergey Biryukov
 
Практическая доступность с WordPress
Практическая доступность с WordPressПрактическая доступность с WordPress
Практическая доступность с WordPress
Anna Ladoshkina
 
Ведение бизнеса на основе WordPress
Ведение бизнеса на основе WordPressВедение бизнеса на основе WordPress
Ведение бизнеса на основе WordPress
Andrey Ovsyannikov
 
Using Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websitesUsing Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websites
Anna Ladoshkina
 
Surviving a Crisis of Confidence
Surviving a Crisis of ConfidenceSurviving a Crisis of Confidence
Surviving a Crisis of Confidence
Nathan Ingram
 
WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?
WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?
WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?
Kate Newbill
 
Website Pricing 101: Don’t Be a Commodity
Website Pricing 101: Don’t Be a CommodityWebsite Pricing 101: Don’t Be a Commodity
Website Pricing 101: Don’t Be a Commodity
Geoff Myers
 
WCBham Beginner WordPress Security
WCBham Beginner WordPress SecurityWCBham Beginner WordPress Security
WCBham Beginner WordPress Security
Gerroald Barron
 
WordCamp Tokyo2016itkaasan
WordCamp Tokyo2016itkaasanWordCamp Tokyo2016itkaasan
WordCamp Tokyo2016itkaasan
松田 千尋
 
Wordcamp Denver 2015 - Get Clear w Diane Whiddon
Wordcamp Denver 2015 - Get Clear w Diane WhiddonWordcamp Denver 2015 - Get Clear w Diane Whiddon
Wordcamp Denver 2015 - Get Clear w Diane Whiddon
Diane Whiddon
 
A House with No Walls: Building a Site Structure for Tomorrow
A House with No Walls: Building a Site Structure for TomorrowA House with No Walls: Building a Site Structure for Tomorrow
A House with No Walls: Building a Site Structure for Tomorrow
Gizmo Creative Factory, Inc.
 

Viewers also liked (20)

i18n for Plugin and Theme Developers, WordCamp Moscow 2016
i18n for Plugin and Theme Developers, WordCamp Moscow 2016i18n for Plugin and Theme Developers, WordCamp Moscow 2016
i18n for Plugin and Theme Developers, WordCamp Moscow 2016
 
Conception de thèmes WordPress : construire et optimiser son espace de travail
Conception de thèmes WordPress : construire  et optimiser son espace de travailConception de thèmes WordPress : construire  et optimiser son espace de travail
Conception de thèmes WordPress : construire et optimiser son espace de travail
 
How to make your WordPress website multilingual - WordCamp Paris 2016
How to make your WordPress website multilingual - WordCamp Paris 2016How to make your WordPress website multilingual - WordCamp Paris 2016
How to make your WordPress website multilingual - WordCamp Paris 2016
 
WordPress on HHVM + Hack
WordPress on HHVM + HackWordPress on HHVM + Hack
WordPress on HHVM + Hack
 
Contributing to WordPress, WordCamp Russia 2013
Contributing to WordPress, WordCamp Russia 2013Contributing to WordPress, WordCamp Russia 2013
Contributing to WordPress, WordCamp Russia 2013
 
Everything You Need to Know About WP_Query, WordCamp Russia 2014
Everything You Need to Know About WP_Query, WordCamp Russia 2014Everything You Need to Know About WP_Query, WordCamp Russia 2014
Everything You Need to Know About WP_Query, WordCamp Russia 2014
 
Looking into WordPress Core, WordCamp Russia 2015
Looking into WordPress Core, WordCamp Russia 2015Looking into WordPress Core, WordCamp Russia 2015
Looking into WordPress Core, WordCamp Russia 2015
 
Моделирование контента в WordPress
Моделирование контента в WordPressМоделирование контента в WordPress
Моделирование контента в WordPress
 
Composer и разработка сайтов на WordPress
Composer и разработка сайтов на WordPressComposer и разработка сайтов на WordPress
Composer и разработка сайтов на WordPress
 
Managing a Local WordPress Community, WordCamp Europe 2016
Managing a Local WordPress Community, WordCamp Europe 2016Managing a Local WordPress Community, WordCamp Europe 2016
Managing a Local WordPress Community, WordCamp Europe 2016
 
Практическая доступность с WordPress
Практическая доступность с WordPressПрактическая доступность с WordPress
Практическая доступность с WordPress
 
Ведение бизнеса на основе WordPress
Ведение бизнеса на основе WordPressВедение бизнеса на основе WordPress
Ведение бизнеса на основе WordPress
 
Using Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websitesUsing Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websites
 
Surviving a Crisis of Confidence
Surviving a Crisis of ConfidenceSurviving a Crisis of Confidence
Surviving a Crisis of Confidence
 
WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?
WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?
WordCamp Birmingham 2016 -- Do You Really Need a 3-lb Pocket Knife?
 
Website Pricing 101: Don’t Be a Commodity
Website Pricing 101: Don’t Be a CommodityWebsite Pricing 101: Don’t Be a Commodity
Website Pricing 101: Don’t Be a Commodity
 
WCBham Beginner WordPress Security
WCBham Beginner WordPress SecurityWCBham Beginner WordPress Security
WCBham Beginner WordPress Security
 
WordCamp Tokyo2016itkaasan
WordCamp Tokyo2016itkaasanWordCamp Tokyo2016itkaasan
WordCamp Tokyo2016itkaasan
 
Wordcamp Denver 2015 - Get Clear w Diane Whiddon
Wordcamp Denver 2015 - Get Clear w Diane WhiddonWordcamp Denver 2015 - Get Clear w Diane Whiddon
Wordcamp Denver 2015 - Get Clear w Diane Whiddon
 
A House with No Walls: Building a Site Structure for Tomorrow
A House with No Walls: Building a Site Structure for TomorrowA House with No Walls: Building a Site Structure for Tomorrow
A House with No Walls: Building a Site Structure for Tomorrow
 

Similar to i18n for Plugin and Theme Developers, WordCamp Milano 2016

i18n for Plugin and Theme Developers, Global WordPress Translation Day 3
i18n for Plugin and Theme Developers, Global WordPress Translation Day 3i18n for Plugin and Theme Developers, Global WordPress Translation Day 3
i18n for Plugin and Theme Developers, Global WordPress Translation Day 3
Sergey Biryukov
 
WCRI 2015 I18N L10N
WCRI 2015 I18N L10NWCRI 2015 I18N L10N
WCRI 2015 I18N L10N
Dave McHale
 
WordPress internationalization, localization, and multilingual
WordPress internationalization, localization, and multilingualWordPress internationalization, localization, and multilingual
WordPress internationalization, localization, and multilingual
mbigul
 
How to make multilingual plugins and themes
How to make multilingual plugins and themesHow to make multilingual plugins and themes
How to make multilingual plugins and themes
johnpbloch
 
Brian hogg word camp preparing a plugin for translation
Brian hogg   word camp preparing a plugin for translationBrian hogg   word camp preparing a plugin for translation
Brian hogg word camp preparing a plugin for translation
wcto2017
 
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
DouglasPickett
 
WordPress Internationalization, Localization and Multilingual - Do It Right
WordPress Internationalization, Localization and Multilingual - Do It RightWordPress Internationalization, Localization and Multilingual - Do It Right
WordPress Internationalization, Localization and Multilingual - Do It Right
Dat Hoang
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
Ngoc Dao
 
Modern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextModern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettext
Alexander Mostovenko
 
Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016
johnpbloch
 
Api Design
Api DesignApi Design
WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Trivandrum
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...
Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...
Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...Nicholas Dionysopoulos
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
Elizabeth Smith
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
Dirk Haun
 
Preparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for TranslationPreparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for Translation
Brian Hogg
 
WordPress 15th Meetup - Build a Theme
WordPress 15th Meetup - Build a ThemeWordPress 15th Meetup - Build a Theme
WordPress 15th Meetup - Build a Theme
Fadi Nicolas Zahhar
 

Similar to i18n for Plugin and Theme Developers, WordCamp Milano 2016 (20)

i18n for Plugin and Theme Developers, Global WordPress Translation Day 3
i18n for Plugin and Theme Developers, Global WordPress Translation Day 3i18n for Plugin and Theme Developers, Global WordPress Translation Day 3
i18n for Plugin and Theme Developers, Global WordPress Translation Day 3
 
WCRI 2015 I18N L10N
WCRI 2015 I18N L10NWCRI 2015 I18N L10N
WCRI 2015 I18N L10N
 
WordPress internationalization, localization, and multilingual
WordPress internationalization, localization, and multilingualWordPress internationalization, localization, and multilingual
WordPress internationalization, localization, and multilingual
 
How to make multilingual plugins and themes
How to make multilingual plugins and themesHow to make multilingual plugins and themes
How to make multilingual plugins and themes
 
Brian hogg word camp preparing a plugin for translation
Brian hogg   word camp preparing a plugin for translationBrian hogg   word camp preparing a plugin for translation
Brian hogg word camp preparing a plugin for translation
 
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
 
WordPress Internationalization, Localization and Multilingual - Do It Right
WordPress Internationalization, Localization and Multilingual - Do It RightWordPress Internationalization, Localization and Multilingual - Do It Right
WordPress Internationalization, Localization and Multilingual - Do It Right
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
 
Modern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextModern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettext
 
Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016
 
Api Design
Api DesignApi Design
Api Design
 
WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...
 
Multilingual drupal 7
Multilingual drupal 7Multilingual drupal 7
Multilingual drupal 7
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...
Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...
Joomla! Frappe - Κατασκευή εφαρμογών για το Joomla! χωρίς να τραβάτε τα μαλιά...
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Preparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for TranslationPreparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for Translation
 
WordPress 15th Meetup - Build a Theme
WordPress 15th Meetup - Build a ThemeWordPress 15th Meetup - Build a Theme
WordPress 15th Meetup - Build a Theme
 

Recently uploaded

Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 

Recently uploaded (20)

Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 

i18n for Plugin and Theme Developers, WordCamp Milano 2016

  • 1. Internationalization for Plugin and Theme Developers Sergey Biryukov WordCamp Milano 2016
  • 2. Sergey Biryukov ● WordPress Core Contributor at Yoast yoast.com ● Co-founder of Russian WP community ru.wordpress.org ● Polyglots, Support, and Meta teams sergeybiryukov.com @SergeyBiryukov
  • 3. Plugins and Themes for the Whole World ● Internationalization (i18n) — providing the ability to translate ● Localization (L10n) — translating to a particular language
  • 4. Plugins and Themes for the Whole World ● Over 100 languages ● More robust code ● Feedback ● It’s easy
  • 7. Introduction to gettext ● Text domain – 'my-plugin' ● Preparing the strings – <?php echo 'Title'; ?>→<?php _e( 'Title', 'my-plugin' ); ?> ● Language files – .pot, .po, .mo
  • 8. Text Domain ● Should match the plugin/theme slug (folder name): – wp-content/plugins/my-plugin→'my-plugin' – wp-content/themes/my-theme→'my-theme' ● Should be added to plugin/theme headers: – Plugin Name: My Plugin – Version: 1.0 – Text Domain: my-plugin
  • 9. Text Domain ● Loading the text domain – load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); – load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' );
  • 10. Text Domain ● Loading the text domain – load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); – load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' ); ● wp-content/languages (WordPress 4.6+)
  • 11. Preparing the Strings ● Regular strings: – __( 'Hello world!', 'my-plugin' ); – _e( 'Hello world!', 'my-plugin' ); ● Strings with context: – _x( 'Hello world!', 'post title', 'my-plugin' ); – _ex( 'Hello world!', 'post title', 'my-plugin' );
  • 12. Preparing the Strings ● Plural forms: – _n( '%d item', '%d items', $count, 'my-plugin' ); – _nx( '%d item', '%d items', $count, 'comments', 'my-plugin' ); ● If the number is not available yet: – _n_noop( '%d item', '%d items', 'my-plugin' ); – _nx_noop('%d item', '%d items', 'comments', 'my-plugin' );
  • 13. Preparing the Strings ● Escaping HTML tags: – esc_html__( 'Hello <em>world</em>!', 'my-plugin' ); – esc_html_e( 'Hello <em>world</em>!', 'my-plugin' ); – esc_html_x( 'Hello <em>world</em>!', 'post title', 'my-plugin' ); ● Escaping HTML attributes: – esc_attr__( 'Hello "world"!', 'my-plugin' ); – esc_attr_e( 'Hello "world"!', 'my-plugin' ); – esc_attr_x( 'Hello "world"!', 'post title', 'my-plugin' );
  • 14. Preparing the Strings ● Escaping HTML tags and attributes: – <option value="<?php esc_attr_e( 'value', 'my-plugin' ); ?>"> <?php esc_html_e( 'Option label', 'my-plugin' ); ?> </option> ● Same, in a longer notation: – <option value="<?php echo esc_attr( __( 'value', 'my-plugin' ) ); ?>"> <?php echo esc_html( __( 'Option label', 'my-plugin' ) ); ?> </option>
  • 15. _e() ≠ echo() ● Don’t use PHP variables, only simple strings: – _e( $string ); — don’t do that. ● Provide the ability to translate whole phrases, not separate words: – echo __( 'Hello' ) . ' ' . __( 'world!' ); — don’t do that either. ● Don’t forget the text domain: – _e( 'Hello world!', 'my-plugin' ); ● Remove unnecessary HTML markup from the strings: – _e( '<p>Hello world!</p>', 'my-plugin' );
  • 16. Context and Comments ● Context — same string, different translations: – _x( 'redirect', 'noun', 'my-plugin' ); – _x( 'redirect', 'verb', 'my-plugin' ); ● Comments — to explain placeholders in a string: – /* translators: %s: file name */ __( '%s was deleted.', 'my-plugin' );
  • 17. Plural Forms ● ??? – _e( "You have $count items.", 'my-plugin' ); – _e( 'You have ' . $count . ' items.', 'my-plugin' ); – printf( __( 'You have %d items.', 'my-plugin' ), $count ); – printf( _n( 'You have %d item.', 'You have %d items.', $count ), $count );
  • 18. Plural Forms ● Incorrect: – _e( "You have $count items.", 'my-plugin' ); – _e( 'You have ' . $count . ' items.', 'my-plugin' ); – printf( __( 'You have %d items.', 'my-plugin' ), $count ); ● Almost correct: – printf( _n( 'You have %d item.', 'You have %d items.', $count ), $count );
  • 19. Plural Forms ● Correct: – printf( _n( 'You have %d item.', 'You have %d items.', $count ), number_format_i18n( $count ) ); ● number_format_i18n() — for displaying numbers ● date_i18n() — for displaying dates
  • 20. Plural Forms ● If the number is not available: – $items_plural = _n_noop( 'You have %s item.', 'You have %s items', 'my-plugin' ); ● ... ● After it’s available: – printf( translate_nooped_plural( $items_plural, $count ), number_format_i18n( $count ) ); ● translate_nooped_plural() — for deferred translations of plural strings
  • 21. Plural Forms ● The first form is not necessarily used for 1 item: – printf( _n( 'Theme deleted.', '%d themes deleted.', $count ), number_format_i18n( $count ) ); ● Better: – if ( 1 === $count ) { _e( 'Theme deleted.' ); – } else { printf( _n( '%d theme deleted.', '%d themes deleted.', $count ), number_format_i18n( $count ) ); – }
  • 22. Language Files ● .pot (Portable Object Template) – Translation template, contains English strings only. ● .po (Portable Object) – Language file in a human-readable format. ● .mo (Machine Object) – Compiled language file in a machine-readable format.
  • 24. Plugin Changelog ● Version 1.5.6 – Added Russian translation. – That’s it! ● Version 1.5.6.1 – Fixed a typo in Russian translation.
  • 27. translate.wordpress.org ● GTE (General Translation Editor) — locale editors – Can check and approve all translations. ● PTE (Project Translation Editor) — project editors – Can approve translations for a particular project. ● Translators – Can suggest translations.
  • 28. If Someone Has Sent You Their Translation ● Ask them to create a WordPress.org account – They can be added as a Project Translation Editor. – They would be able to import the .po file themselves. – ...and continue translating in the future. ● Ask locale editors to import the files – No guarantee that the plugin will continue to be actively translated.
  • 29. If Someone Has Sent You Their Translation ● Once the translator has a WordPress.org account: – Go to the Polyglots team blog: https://make.wordpress.org/polyglots/ – Find the Polyglots Handbook link: https://make.wordpress.org/polyglots/handbook/ – On “Theme & Plugin Directories” page, find a post template for requesting new translation editors. – Submit your request to the Polyglots blog and wait for a reply.