Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Intro to I18N in code
Search
Matthew Haines-Young
May 13, 2015
110
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
Transcript
13 slides
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/
More Decks by Matthew Haines-Young
See All by Matthew Haines-Young
Building Sites with Gutenberg
mattheu
1
280
WordPress REST API - Writing Custom Endpoints
mattheu
0
110
Tips for writing secure code in WordPress
mattheu
1
150
Making shortcodes a piece of cake
mattheu
0
24k
Featured
See All Featured
Speed Design
sergeychernyshev
33
2.3k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
2
4k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Thoughts on Productivity
jonyablonski
76
5.5k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
1
320
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
490
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
250
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
61k