When writing a WordPress plugin, programmers occasionally have strings that they want to mark for translation, but the same string can mean different things in different places.

For example you might want to refer to “Pounds” as a unit of weight, and “Pounds” as the shorthand for the British currency. In that case you can provide additional context that translators can use to determine which “pounds” you mean in case the translation is different.

So, while a simple use of a translated string includes only the string, and the text domain, and doesn’t require you to provide a context:

__('Pounds', 'plugin-domain');

If you wanted to provide context in different use cases, you can use the _x() function and provide the context as an extra argument:

_x('Pounds', 'Unit of weight', 'plugin-domain');
_x('Pounds', 'The British currency', 'plugin-domain');

Translators can provide different translations for each of these strings.

sw-wcontextIf you’re looking to provide an alternative string using the Say What string replacement plugin then you need to know the domain, and the context of the string you’re looking to translate. So – adding a replacement string with a context of “Unit of weight” as per this screenshow, would only replace the first string in our example – the currency string would remain unaffected.

If you wanted to replace the second string, then you’d add it as a second replacement, using “The British currency” as the context value.

Of course – if the string you’re trying to replace using the standard _() or _e() functions, and doesn’t have a specific context, you can just leave the text context field blank.

This entry was posted in .
Bookmark the permalink.