Internationalization Best Practices

This article is part of the WordPress guide. Read the introduction.

There are a couple of important rules you have to keep in mind when internationalizing your strings.

Internationalize Entire Sentences & Paragraphs

In most languages, word order is different than in English. It is important to make it possible for translators to structure sentences naturally. This means internationalizing the entire sentence instead of only parts of it.

Think back to our “Reading time: 1 min” example. We wrapped the entire sentence in __() and sprintf(), which later allowed us to change the order of those variables. We wouldn’t be able to do that if we just concatenated this sentence from individually translated strings.

Some languages might require a different order of sentences in a paragraph. A general rule of thumb is to split your i18n at paragraphs (one __() call per paragraph of text).

Assume Strings Can Double In Length When Translated

Some languages require twice as many words to express the same idea. If you can, try to test your layout for such a possibility.

Use The Same Phrases In The Same Forms

Try to benefit from the fact that the translator only has to translate an original phrase once for it to be used in multiple places. For example, try not to do that:

PHP
__( 'Posts', 'my-theme' );
__( 'Posts:', 'my-theme' );

If you do, the translator will have to translate “Posts” and “Posts:” separately.

Do Not Include URLs

If you include a URL in the original string, a malicious translator could make it a different URL. There’s a good chance you wouldn’t notice until it was too late. For that reason, you should always include URLs as placeholders (%s) using sprintf.