Jump to content

Replacements in phrases

Some phrases have values passed into them by the language system, so you will need to be able to identify these and ensure your translations still include the replacement value. There's a few types of replacement you'll see:

  • %s
    Simple string replacements
  • {internal.app=core&module=system&controller=register}
    URL replacements
  • {# [1:reply][?:replies]}
    Plural replacements

We'll cover plural replacements in-depth in the next step.


String replacements

Simple string replacements use a format determined by PHP's sprintf function. In this format, the special token %s is replaced with the value passed into the phrase:

My name is %s

becomes this when displayed:

My name is Rikki

Multiple values are sometimes passed into a phrase, and they are replaced in order. For example, if the values "Rikki" and "blue" were passed into a phrase, in that order, the language phrase:

My name is %s and my favorite color is %s

becomes this when displayed:

My name is Rikki and my favorite color is blue

However, since the order of the values passed in is determined by the PHP code in the suite and can't be changed by language authors, special syntax is required if you want to switch the order of any of the replacements (this is often necessary in other languages where sentence structure differs from English).

To swap the replacements, the %s token should be changed to %2$s - essentially inserting 2$ in the middle of the normal token, where 2 is the position of the parameter you want to use for this replacement. To take the example above, we could now do:

My favorite color is %2$s and my name is %1$s

which becomes:

My favorite color is blue and my name is Rikki

For more information, see the PHP.net sprintf documentation (bear in mind it is a technical document designed for developers).


URL replacements

Occasionally, links need to be built inside language phrases. Our language system supports this with special tags like this:


In this example, the internal. means the software knows it is a link to an internal page (i.e. a page within our software), with a URL string to the particular page. There can also be pre-defined external links, like so:


In this case, ad-custom-location is a pre-defined external URL in our software. When making your translations, be sure to include the links found in the original language phrase, since they often provide valuable extra information to users.

  Report Guide

  • Create New...