How to escape the single quote character in i18n translation strings?

How should I properly escape the single quote character in a translation string? I’m using it as an apostrophe. For example:

__( '404. This isn't the page you're looking for.', 'textdomain' );

I believe there are a few approaches but which is the proper way?

Approach 1: Using the backslash:

__( '404. This isn\'t the page you\'re looking for.', 'textdomain' );

Approach 2: Using the character entity:

__( '404. This isn't the page you're looking for.', 'textdomain' );

1
1

Use the first option. translated strings are supposed to be “raw”, and escaped only by the calling function. In addition many will not understand what ' mean and how to translate it without looking at the actual page which can be annoying.

Leave a Comment