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

Building Multilingual WordPress Themes

Building Multilingual WordPress Themes

You’ve just built a great theme, but how can you get more people to use it? Why not turn it into a multilingual theme? All the steps you’ll need to follow to get your brand new theme internationalized and localized. You’ll learn about gettext, Poedit, POT files GlotPress, and more.

Level: Intermediate/Advanced designer, Beginner developer

Prerequisites: Good knowledge of WordPress themes.

Presented on April 27 at WordCamp Ottawa 2013.

Shannon Smith

April 27, 2013

More Decks by Shannon Smith

Other Decks in Technology


  1. What We’ll Cover ✤ Introduction ✤ Get a multilingual CMS

    ✤ Internationalize ✤ Localize ✤ After the Theme ✤ Closing
  2. Step -1: WordPress in Your Language 1.Install WordPress 2.Install Language

    Files http://codex.wordpress.org/ WordPress_in_Your_Language
  3. Help! I can’t find my language! 1.Download the WordPress Translation

    Files http://svn.automattic.com/wordpress-i18n/ 2.Translate Core Files 3.Install Language Files http://codex.wordpress.org/WordPress_in_Your_Language
  4. Internationalize “The first step is when the program's developers provide

    a mechanism and method for the eventual translation of the program and its interface to suit local preferences and languages for users worldwide.” http://codex.wordpress.org/Translating_WordPress
  5. GNU gettext Localization ❖ Text Domain ❖ Message-Level Translation ❖

    POT File http://codex.wordpress.org/Translating_WordPress http://www.gnu.org/software/gettext/gettext.html Photo:liza31337
  6. Define Text Domain // Make theme available for translation //

    Translations can be filed in the /languages/ directory load_theme_textdomain( 'your-theme', TEMPLATEPATH . '/languages' ); $locale = get_locale(); $locale_file = TEMPLATEPATH . "/languages/$locale.php"; if ( is_readable($locale_file) ) require_once($locale_file); http://codex.wordpress.org/Function_Reference/load_theme_textdomain
  7. Using the Text Domain <?php $translated_text = __( 'text', 'domain'

    ); ?> http://codex.wordpress.org/Function_Reference/load_theme_textdomain
  8. What is the difference? ❖ PHP echo statement: outputs whatever

    you tell it to the browser ❖ PHP return statement: returns a value from a function
  9. Simple Strings http://codex.wordpress.org/I18n_for_WordPress_Developers echo '<h2>' . __( 'Blog Options' )

    . '</h2>'; echo __( 'Using this option you will make a fortune!' ); _e( 'Using this option you will make a fortune!' );
  10. Disambiguation http://codex.wordpress.org/I18n_for_WordPress_Developers http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/ $string = _x( 'Buffalo', 'an animal', 'plugin-

    domain' ); $string = _x( 'Buffalo', 'a city in New York', 'plugin- domain' ); $string = _x( 'Buffalo', 'a verb meaning to confuse somebody', 'plugin-domain' ); /* translators: draft saved date format, see http:// php.net/date */ $draft_saved_date_format = __( 'g:i:s a' );
  11. Otto’s Unbreakable Laws of i18n http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/ ❖ Thou shalt not

    use PHP variables of any kind inside a translation function’s strings. ❖ Thou shalt always translate phrases and not words. ❖ Thou shalt disambiguate when needed. ❖ Thou shalt not put unnecessary HTML markup into the translated string.
  12. GNU gettext Files ❖ POT (Portable Object Template) files ❖

    PO (Portable Object) files ❖ MO (Machine Object) files http://codex.wordpress.org/Translating_WordPress
  13. POT (Portable Object Template) files ❖ only file required for

    i18n ❖ includes every message passed into a __() or _e() function http://codex.wordpress.org/Translating_WordPress
  14. Option B: WordPress-i18n Tools ❖ SVN the WordPress-i18n tools and

    run the makepot.php script http://codex.wordpress.org/User:Skippy/Creating_POT_Files php makepot.php wp-theme your-theme-directory ❖ Deprecated in favour of GlotPress
  15. Localize “The second step is the actual localization, the process

    by which the text on the page and other settings are translated and adapted to another language and culture, using the framework prescribed by the developers of the software.” http://codex.wordpress.org/Translating_WordPress
  16. GNU gettext Files ❖ POT (Portable Object Template) files ❖

    PO (Portable Object) files ❖ MO (Machine Object) files http://codex.wordpress.org/Translating_WordPress
  17. Everything after the Theme ✤ Plugins ✤ Widgets ✤ Language

    Switcher ✤ Translated Content ✤ Plugin (WPML) or WordPress Multisite