$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Intro to I18N in code
Search
Matthew Haines-Young
May 13, 2015
0
76
Intro to I18N in code
Short introduction to writing code that can be easily translated in WordPress
Matthew Haines-Young
May 13, 2015
Tweet
Share
More Decks by Matthew Haines-Young
See All by Matthew Haines-Young
Building Sites with Gutenberg
mattheu
1
210
WordPress REST API - Writing Custom Endpoints
mattheu
0
84
Tips for writing secure code in WordPress
mattheu
1
120
Making shortcodes a piece of cake
mattheu
0
24k
Featured
See All Featured
Writing Fast Ruby
sferik
627
61k
The Invisible Side of Design
smashingmag
298
50k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Practical Orchestrator
shlominoach
186
10k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Adopting Sorbet at Scale
ufuk
73
9.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Raft: Consensus for Rubyists
vanstee
136
6.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
760
Thoughts on Productivity
jonyablonski
67
4.3k
4 Signs Your Business is Dying
shpigford
181
21k
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/