SlideShare a Scribd company logo
1 of 37
How to Make Multilingual
Plugins and Themes
John P Bloch ● 2016-02-20 ● WordCamp Miami
About Me
John P Bloch
Lead Web Engineer at 10up
10up is hiring
Tell them I sent you
Seriously, we’re always hiring
@johnpbloch
john.bloch@10up.com
Assumptions
& Definitions
Assumptions
• You can write PHP
• You are writing plugins or themes for distribution on the
wordpress.org repositories
Definitions
Internationalization
The process of making your
code translatable at all.
Abbreviated as i18n
Localization
The process of using translated
text in internationalized code.
Abbreviated as l10n
Definitions
Internationalization
The process of making your
code translatable at all.
Abbreviated as i18n
Localization
The process of using translated
text in internationalized code.
Abbreviated as l10n
Why should you care?
Why should you care?
• Empathy
• More than half of all new WordPress installations are in languages
other than English
Why should you care?
• Empathy
• Grow your potential user-base
• Potentially make more money
• Make more of an impact in the world
How to Internationalize Code
Text Domains
A text domain is a namespace for your code’s translations
Text domains need to be unique within plugins or themes
Use your plugin or theme slug
Text Domains – Loading Themes
load_theme_textdomain(
$textdomain,
$path // where your translations are
)
Run on after_setup_theme action
$path needs to be an absolute path
load_plugin_textdomain(
$textdomain,
false, // deprecated
$path // where translation files are
)
Run on plugins_loaded action
$path is relative to wp-content/plugins
Text Domains – Loading Plugins
Plugin and Theme Headers
Plugins and themes have two
special headers:
Text Domain
Domain Path
Basic Translation Functions
__( $text, $textdomain )
_e( $text, $textdomain )
_n(
$singular,
$plural,
$count,
$textdomain
)
Basic Translation Functions
$draft_count = get_my_drafts_count();
printf( _n(
'I have one draft.',
'I have %s drafts.',
$draft_count,
'my-textdomain'
), $draft_count );
Basic Translation Functions
$draft_count = get_my_drafts_count();
if( 1 === $draft_count ) {
_e( 'I have one post.', 'my-textdomain' );
} else {
printf( __(
'I have %s drafts.',
'my-textdomain'
), $draft_count );
}
Basic Translation Functions
_x( $text, $context, $textdomain )
_ex( $text, $context, $textdomain )
_nx(
$singular,
$plural,
$count,
$context,
$textdomain
)
Basic Translation Functions
You can also leave longer comments for the translators
printf(
/* translators: The placeholder is the
current user’s first name */
__( 'Hello, %s!', 'my-textdomain' ),
$current_user->first_name
);
Advanced Translation Functions
number_format_i18n(
$number,
$decimals = 0
)
1234567.89
1,234,567.89
1.234.567,89
Advanced Translation Functions
date_i18n(
$format,
$timestamp = false,
$gmt = false
)
'F j Y'
'February 20 2016'
'Febbraio 20 2016'
Advanced Translation Functions
Homework
Look up these translation
functions:
wp_localize_script()
esc_html__()
esc_html_e()
esc_html_x()
esc_attr__()
esc_attr_e()
esc_attr_x()
Final Steps
Final Steps
• Generate .pot file
• Official repositories provide web tools
• Publish .pot file
• Usually packaged with plugin or theme in the languages directory
• Add translation files to your plugin or theme
• Or don’t. Plugins have language packs now.
Gotchas
Gotchas
• Line breaks
• Empty strings
• Formatted strings vs. interpolation
_e( "You live in $state", 'my-plugin' );
#: my-plugin.php:23
msgid "You live in $state"
msgstr ""
$state = 'Florida';
// Lookup is "You live in Florida"
printf(
__( 'You live in %s', 'my-plugin' ),
$state
);
Gotchas
• Line breaks
• Empty strings
• Formatted strings vs. interpolation
• Word order and position
printf(
__( 'Hi %s, you live in %s', 'my-plugin' ),
$user_name, $state
);
printf(
__(
'Hi %1$s, you live in %2$s',
'my-plugin‘
),
$user_name, $state
);
Best Practices
Best Practices
• Use decent English style
• Avoid slang and abbreviations
• Keep text together
• Break at paragraphs
• Use formatted strings instead of
concatenation
• Translate phrases not words
• No unnecessary HTML
• Make no assumptions about
the translated text
• Length
• Word order
• Direction
• Punctuation
• Avoid translating URLs that
don’t have alternate
languages available
Tools
• Pig Latin (http://w.org/plugins/piglatin/)
• WP i18n Tools (develop.svn.wordpress.org/trunk/tools/i18n/)
• PoEdit (https://poedit.net/)
• GlotPress (http://blog.glotpress.org/)
• Translate WordPress (https://translate.wordpress.org)
Questions?
Twitter: @johnpbloch
Website: https://johnpbloch.com
Email: john.bloch@10up.com

More Related Content

What's hot

Tools to help you join the self publishing revolution
Tools to help you join the self publishing revolutionTools to help you join the self publishing revolution
Tools to help you join the self publishing revolution
saturdayplace
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 

What's hot (20)

Php
PhpPhp
Php
 
Leveling Up Your Multilingual WordPress site
Leveling Up Your Multilingual WordPress siteLeveling Up Your Multilingual WordPress site
Leveling Up Your Multilingual WordPress site
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
International SEO
International SEOInternational SEO
International SEO
 
Phpwebdevelping
PhpwebdevelpingPhpwebdevelping
Phpwebdevelping
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Tools to help you join the self publishing revolution
Tools to help you join the self publishing revolutionTools to help you join the self publishing revolution
Tools to help you join the self publishing revolution
 
Artisan Perfumery or Being Led by the Nose [P.D.F_book]@@
 Artisan Perfumery or Being Led by the Nose [P.D.F_book]@@ Artisan Perfumery or Being Led by the Nose [P.D.F_book]@@
Artisan Perfumery or Being Led by the Nose [P.D.F_book]@@
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
Php unit i
Php unit iPhp unit i
Php unit i
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
Translating WordPress themes and plugins WordCamp Bhopal 2015
Translating WordPress themes and plugins WordCamp Bhopal 2015Translating WordPress themes and plugins WordCamp Bhopal 2015
Translating WordPress themes and plugins WordCamp Bhopal 2015
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
EPUB vs. WEB: A Cautionary Tale - ebookcraft 2016 - Tzviya Siegman & Dave Cramer
EPUB vs. WEB: A Cautionary Tale - ebookcraft 2016 - Tzviya Siegman & Dave CramerEPUB vs. WEB: A Cautionary Tale - ebookcraft 2016 - Tzviya Siegman & Dave Cramer
EPUB vs. WEB: A Cautionary Tale - ebookcraft 2016 - Tzviya Siegman & Dave Cramer
 

Viewers also liked

Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...
Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...
Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...
tommasobovo
 
黃賜護國台灣神
黃賜護國台灣神黃賜護國台灣神
黃賜護國台灣神
dress
 
Flight by sherman alexie slidesahre
Flight by sherman alexie  slidesahreFlight by sherman alexie  slidesahre
Flight by sherman alexie slidesahre
lilianasuarez
 

Viewers also liked (12)

Carte
CarteCarte
Carte
 
Ppt clase 2
Ppt clase 2Ppt clase 2
Ppt clase 2
 
Lezione Università degli Studi di Firenze Facoltà di Architettura
Lezione Università degli Studi di Firenze Facoltà di ArchitetturaLezione Università degli Studi di Firenze Facoltà di Architettura
Lezione Università degli Studi di Firenze Facoltà di Architettura
 
Ensayo Transición Escolar
Ensayo Transición EscolarEnsayo Transición Escolar
Ensayo Transición Escolar
 
Adrian km y andres
Adrian km y andresAdrian km y andres
Adrian km y andres
 
Designer: la figura del designer in Italia
Designer: la figura del designer in ItaliaDesigner: la figura del designer in Italia
Designer: la figura del designer in Italia
 
Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...
Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...
Lezione sull'editoria di giornali e riviste presso Istituto Europeo di Design...
 
Aziende: le fabbriche produttrici del design
Aziende: le fabbriche produttrici del designAziende: le fabbriche produttrici del design
Aziende: le fabbriche produttrici del design
 
黃賜護國台灣神
黃賜護國台灣神黃賜護國台灣神
黃賜護國台灣神
 
Pharasal verbs presentation
Pharasal verbs presentationPharasal verbs presentation
Pharasal verbs presentation
 
THE USE OF PRESENT PERFECT
THE USE OF PRESENT PERFECTTHE USE OF PRESENT PERFECT
THE USE OF PRESENT PERFECT
 
Flight by sherman alexie slidesahre
Flight by sherman alexie  slidesahreFlight by sherman alexie  slidesahre
Flight by sherman alexie slidesahre
 

Similar to Writing Multilingual Plugins and Themes - WCMIA 2016

I18n
I18nI18n
I18n
soon
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
drperl
 

Similar to Writing Multilingual Plugins and Themes - WCMIA 2016 (20)

WCRI 2015 I18N L10N
WCRI 2015 I18N L10NWCRI 2015 I18N L10N
WCRI 2015 I18N L10N
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 
Php
PhpPhp
Php
 
Php Tutorial | Introduction Demo | Basics
 Php Tutorial | Introduction Demo | Basics Php Tutorial | Introduction Demo | Basics
Php Tutorial | Introduction Demo | Basics
 
Learning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For BeginnersLearning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For Beginners
 
Php My SQL Tutorial | beginning
Php My SQL Tutorial | beginningPhp My SQL Tutorial | beginning
Php My SQL Tutorial | beginning
 
WordPress Theme & Plugin i18n & L10n
WordPress Theme & Plugin i18n & L10nWordPress Theme & Plugin i18n & L10n
WordPress Theme & Plugin i18n & L10n
 
Php Vs Phyton
Php Vs PhytonPhp Vs Phyton
Php Vs Phyton
 
09 Oo Php Register
09 Oo Php Register09 Oo Php Register
09 Oo Php Register
 
LAB PHP Consolidated.ppt
LAB PHP Consolidated.pptLAB PHP Consolidated.ppt
LAB PHP Consolidated.ppt
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
I18n
I18nI18n
I18n
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
MAKE YOUR THEMES AND PLUGINS READY FOR TRANSLATION
MAKE YOUR THEMES AND PLUGINS READY FOR TRANSLATIONMAKE YOUR THEMES AND PLUGINS READY FOR TRANSLATION
MAKE YOUR THEMES AND PLUGINS READY FOR TRANSLATION
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
php 1
php 1php 1
php 1
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Writing Multilingual Plugins and Themes - WCMIA 2016

Editor's Notes

  1. I18n also works for institutionalization lol Internationalization is all about potential Localization is realization of that potential
  2. Less than half of new WordPress installations are in English Exercise in empathy coming up
  3. WP community is so inclusive. Alienating that many people is contrary to the community values
  4. All translations need to use your text domain so that WP knows where to look for translations
  5. Tells WP where to find translations for your text domain
  6. Tells WP where to find translations for your text domain
  7. Domain path is relative to your plugin or theme’s root directory
  8. Number format i18n has a second argument which is how many decimal points to keep Always returns a string, not an integer or float
  9. First argument is the date format, second is timestamp (defaults to now) third is whether to use GMT Date formats should always be run through translation! There is no standard date format across most languages.
  10. Only unix line endings Never try to translate an empty string
  11. Always use %s, never anything else. PHP type coercion will take care of it for you.
  12. Only unix line endings Never try to translate an empty string
  13. You can’t depend on word order staying the same. Use positional formatting
  14. Sometimes HTML is unavoidable. There’s no great way to solve this. Just keep in mind that translators aren’t necessarily going to know HTML