Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Intro to I18N in code
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Matthew Haines-Young
May 13, 2015
98
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Intro to I18N in code
Short introduction to writing code that can be easily translated in WordPress
Matthew Haines-Young
May 13, 2015
More Decks by Matthew Haines-Young
See All by Matthew Haines-Young
Building Sites with Gutenberg
mattheu
1
250
WordPress REST API - Writing Custom Endpoints
mattheu
0
99
Tips for writing secure code in WordPress
mattheu
1
140
Making shortcodes a piece of cake
mattheu
0
24k
Featured
See All Featured
Accessibility Awareness
sabderemane
1
140
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Everyday Curiosity
cassininazir
0
230
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
390
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Transcript
I18N Making your code translatable.
How translation it works. • Uses the gettext libraries. •
Wrap translatable strings in special gettext functions • Automated process - scans your code • Creates POT (Portable Objects Template) file with all translatable strings.
Note: Code is not executed when scanning for translatable strings.
Setup • Add the Text Domain to the theme/plugin header.
• This is a unique identifier. • Use dashes not underscores
__( 'string', 'text-domain' ) Basic translation function
_e( 'string', 'text-domain' ) Same, but outputs result.
Translate strings, not HTML
You cannot use variables in translatable strings. Translate placeholders and
use sprintf/printf
Don’t use variable for text domain.
Plurals • _n( $singular, $plural, $count, ‘text- domain’ ) •
1st param: the singular form of the string • 2nd param: the plural form of the string • 3rd param: the count.
_x( ‘string', 'context', 'text- domain' ); Disambiguation by context. Also
_ex. Same but outputs.
JavaScript • Use wp_localize_script to pass strings.
Resources • VIDEO: Rules for WordPress i18n - http://wordpress.tv/2014/02/26/ samuel-otto-wood-on-internationalization-plugins-and-themes-for-the-
whole-world/ • Otto on i18n - http://ottopress.com/2012/internationalization-youre- probably-doing-it-wrong/ • Plugin i18n - https://developer.wordpress.org/plugins/ internationalization/ • Theme i18n - https://developer.wordpress.org/themes/functionality/ internationalization/ • i18n quiz for developers: https://developer.wordpress.com/2015/04/23/ wordpress-developers-test-your-i18n-internationalization-knowledge/