4. Assumptions
• You can write PHP
• You are writing plugins or themes for distribution on the
wordpress.org repositories
5. 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
6. 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
13. 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
14. 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
21. 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
);
26. 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.
29. _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"
35. 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
I18n also works for institutionalization lol
Internationalization is all about potential
Localization is realization of that potential
Less than half of new WordPress installations are in English
Exercise in empathy coming up
WP community is so inclusive. Alienating that many people is contrary to the community values
All translations need to use your text domain so that WP knows where to look for translations
Tells WP where to find translations for your text domain
Tells WP where to find translations for your text domain
Domain path is relative to your plugin or theme’s root directory
Number format i18n has a second argument which is how many decimal points to keep
Always returns a string, not an integer or float
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.
Only unix line endings
Never try to translate an empty string
Always use %s, never anything else. PHP type coercion will take care of it for you.
Only unix line endings
Never try to translate an empty string
You can’t depend on word order staying the same. Use positional formatting
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