MAKE YOUR THEMES AND PLUGINS
READY FOR TRANSLATION
Makarand Mane
WordPress Enthusiast, Freelancer
http://www.makarandmane.com
/mkrndmane
What is localization?:
• Localization describes the subsequent process of translating
an internationalized plugin.
• Localization is abbreviated as l10n (because there are 10
letters between the l and the n.)
• Internationalization is the process of developing your plugin
so it can easily be translated into other languages.
http://www.makarandmane.com
/mkrndmane
Why internationalization is important?:
• WordPress is used all over the world, it is a good idea to prepare a
WordPress plugin so that it can be easily translated into whatever
language is needed.
• As a developer, you may not have an easy time providing
localizations for all your users;
• You may not speak their language after all. However, any
developer can successfully internationalize a theme to allow others
to create a localization without the need to modify the source
code itself.
• https://codex.wordpress.org/I18n_for_WordPress_Developers
http://www.makarandmane.com
/mkrndmane
How you will translate this?:
// My plugin
<?php
echo '<h2>Hello world!</h2>';
?>
http://www.makarandmane.com
/mkrndmane
Understanding the Localization Framework:
• POT (Portable Object Template)
• PO (Portable Object)
• MO (Machine Object)
http://www.makarandmane.com
/mkrndmane
Loads translated strings of theme
• load_theme_textdomain( $domain, $path )
• load_theme_textdomain( 'yourtheme', templatepath.'/languages' );
http://www.makarandmane.com
/mkrndmane
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_theme_setup(){
load_theme_textdomain( 'my-theme', get_template_directory() .
'/languages' );
}
http://www.makarandmane.com
/mkrndmane
Loads translated strings of plugin
• load_plugin_textdomain( $domain, $abs_rel_path, $plugin_rel_path );
load_plugin_textdomain( 'wp-admin-motivation', false, dirname(
plugin_basename(__FILE__) ) . '/lang/' );
http://www.makarandmane.com
/mkrndmane
add_action( 'plugins_loaded', 'myplugin_load_textdomain' );
function myplugin_load_textdomain()
load_plugin_textdomain( 'my-plugin', false, basename( dirname(
__FILE__ ) ) . '/languages' );
}
http://www.makarandmane.com
/mkrndmane
WordPress function to use:
• __() function
• _e() function
• _n() function
http://www.makarandmane.com
/mkrndmane
<?php
echo '<h2>Hello world!</h2>';
?>
Will become
echo '<h2>' . __('Hello world!', 'yourtheme') . '</h2>';
http://www.makarandmane.com
/mkrndmane
//If you want to print result.
<?php
echo 'Hello world! ‘;
?>
Will become
_e('Hello world!', 'yourtheme');
http://www.makarandmane.com
/mkrndmane
//Retrieve the plural or single form based on the amount.
<?php _n( $single, $plural, $number, $domain ) ?>
<?php
$rating = '3';
echo sprintf( _n( '%s star', '%s stars', $rating, 'your_textdomain'
), $rating );
?>
http://www.makarandmane.com
/mkrndmane
Additional functions in WordPress:
• _x() function
• _ex()
• esc_html__()
• esc_html_e()
• https://codex.wordpress.org/I18n_for_WordPress_Developers
http://www.makarandmane.com
/mkrndmane
Add comments above your statement:
/* translators: Password reset email subject. 1: Site name */
$title = sprintf( __('[%s] Password Reset'), $blogname );
http://www.makarandmane.com
/mkrndmane
How to generate PO file using POedit:
• Demonstration provided with screenshots
http://www.makarandmane.com
/mkrndmane
Tools to create POT file:
• POedit
• Grunt tasks - grunt-po2mo
http://www.makarandmane.com
/mkrndmane
Online Tools to translate PO file:
• Transifex
• WebTranslateIt
• Poeditor
• Google Translator Toolkit
• GlotPress
http://www.makarandmane.com
/mkrndmane
WordPress plugins to do translate PO file:
• CodeStyling Localization
• Loco Translate
http://www.makarandmane.com
/mkrndmane
Thank you!!!
https://www.makarandmane.com
/mkrndmane
/ mkrndmane
/ in/makarandmane
mane.makarand@gmail.com

MAKE YOUR THEMES AND PLUGINS READY FOR TRANSLATION

  • 1.
    MAKE YOUR THEMESAND PLUGINS READY FOR TRANSLATION Makarand Mane WordPress Enthusiast, Freelancer http://www.makarandmane.com /mkrndmane
  • 2.
    What is localization?: •Localization describes the subsequent process of translating an internationalized plugin. • Localization is abbreviated as l10n (because there are 10 letters between the l and the n.) • Internationalization is the process of developing your plugin so it can easily be translated into other languages. http://www.makarandmane.com /mkrndmane
  • 3.
    Why internationalization isimportant?: • WordPress is used all over the world, it is a good idea to prepare a WordPress plugin so that it can be easily translated into whatever language is needed. • As a developer, you may not have an easy time providing localizations for all your users; • You may not speak their language after all. However, any developer can successfully internationalize a theme to allow others to create a localization without the need to modify the source code itself. • https://codex.wordpress.org/I18n_for_WordPress_Developers http://www.makarandmane.com /mkrndmane
  • 4.
    How you willtranslate this?: // My plugin <?php echo '<h2>Hello world!</h2>'; ?> http://www.makarandmane.com /mkrndmane
  • 5.
    Understanding the LocalizationFramework: • POT (Portable Object Template) • PO (Portable Object) • MO (Machine Object) http://www.makarandmane.com /mkrndmane
  • 6.
    Loads translated stringsof theme • load_theme_textdomain( $domain, $path ) • load_theme_textdomain( 'yourtheme', templatepath.'/languages' ); http://www.makarandmane.com /mkrndmane
  • 7.
    add_action( 'after_setup_theme', 'my_theme_setup'); function my_theme_setup(){ load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' ); } http://www.makarandmane.com /mkrndmane
  • 8.
    Loads translated stringsof plugin • load_plugin_textdomain( $domain, $abs_rel_path, $plugin_rel_path ); load_plugin_textdomain( 'wp-admin-motivation', false, dirname( plugin_basename(__FILE__) ) . '/lang/' ); http://www.makarandmane.com /mkrndmane
  • 9.
    add_action( 'plugins_loaded', 'myplugin_load_textdomain'); function myplugin_load_textdomain() load_plugin_textdomain( 'my-plugin', false, basename( dirname( __FILE__ ) ) . '/languages' ); } http://www.makarandmane.com /mkrndmane
  • 10.
    WordPress function touse: • __() function • _e() function • _n() function http://www.makarandmane.com /mkrndmane
  • 11.
    <?php echo '<h2>Hello world!</h2>'; ?> Willbecome echo '<h2>' . __('Hello world!', 'yourtheme') . '</h2>'; http://www.makarandmane.com /mkrndmane
  • 12.
    //If you wantto print result. <?php echo 'Hello world! ‘; ?> Will become _e('Hello world!', 'yourtheme'); http://www.makarandmane.com /mkrndmane
  • 13.
    //Retrieve the pluralor single form based on the amount. <?php _n( $single, $plural, $number, $domain ) ?> <?php $rating = '3'; echo sprintf( _n( '%s star', '%s stars', $rating, 'your_textdomain' ), $rating ); ?> http://www.makarandmane.com /mkrndmane
  • 14.
    Additional functions inWordPress: • _x() function • _ex() • esc_html__() • esc_html_e() • https://codex.wordpress.org/I18n_for_WordPress_Developers http://www.makarandmane.com /mkrndmane
  • 15.
    Add comments aboveyour statement: /* translators: Password reset email subject. 1: Site name */ $title = sprintf( __('[%s] Password Reset'), $blogname ); http://www.makarandmane.com /mkrndmane
  • 16.
    How to generatePO file using POedit: • Demonstration provided with screenshots http://www.makarandmane.com /mkrndmane
  • 27.
    Tools to createPOT file: • POedit • Grunt tasks - grunt-po2mo http://www.makarandmane.com /mkrndmane
  • 28.
    Online Tools totranslate PO file: • Transifex • WebTranslateIt • Poeditor • Google Translator Toolkit • GlotPress http://www.makarandmane.com /mkrndmane
  • 29.
    WordPress plugins todo translate PO file: • CodeStyling Localization • Loco Translate http://www.makarandmane.com /mkrndmane
  • 30.

Editor's Notes

  • #2 How may developers? Non developers? Do you developed any plugin or theme. Knows and don’t know translation. Polyglots? WordPress translation day?
  • #4 Once you make them translation ready, people from regional community can translate it to there language.
  • #5 How you will translate it
  • #13 Add _x _n