Document home

Composite format strings and interpolated strings

Most applications use composite format or interpolated strings. They are used when making it possible to create strings that are dynamic. This means that you don't know the value use the string on compile time but the actual value depends on the parameters that appears on run time. The classic version of composite string is C's printf function. The basic idea of the function is to have a pattern that contains one or more placeholders for dynamic variables. The function takes the pattern and the variable amount of parameters and injects the parameter values into the placeholders of the pattern resulting a single strings where pattern and parameters are merged. For example

printf("Hello %s", name);

If name is "John" we will get "Hello John".

We can have any number of parameters as long as the placeholder count in the pattern matches the parameter count.

printf("Hello %s and %s", name1, name2); 

If name1 is "John" and name2 is "Jill" we will get "Hello John and Jill".

Composite format strings are also used with plurals and genders.

Each platform or programming language uses different format for patterns. The following table shows the most common pattern types and the patterns that Soluling can handle:

Platform Sample composite string
.NET Hello {0}, welcome to {1}
Angular Hello {{name}}, welcome to {{place}}

Hello %s, welcome to %s


Hello %s, welcome to %s


Hello %s, welcome to %s
Hello {0}, welcome to {1}

Objective C

Hello %s, welcome to %s


Hello {0:s}, welcome to {1:s}


Hello [0], welcome to [1]

As you can see there are several formats and this is why Soluling when scanning converts the platform specific format into platform independent format. No matter that is the source of the composite string the string appers in the same way in Soluling.

Translator does not need to know the native format syntax of each platfom. The grid shows placeholders visually such way that the placeholder is a single charcter. The transalator can move the placeholder within the string but the editor makes sure that the translation has the same amount of placeholders as in the original.

Some platforms such as Angular contains the variable name or expression inside the placeholder. In that case Soluling shows the varialbe name or expression instead of the index of the placeholder.

On some platforms (e.g. Angular) if the strings has two or more named placeholders Soluling includes also the index part.

This is because some platforms let you use an expression in the placeholder insread of a single variable. If you have an expression it is more likely to be changed than just a variable name. Adding index makes is possible to locate the right placeholder even in the case the expression has been changed.

Comment checker

Resource strings in general are harder to translate compared to UI strings. This is because there is no visual context but the translator need to figure out the meaning just be reading the strings value and if exist by reading the comment. Composite strings are even hard to translate because parts of the complete string are missing (i.e. placeholders). This is why it is very important to fill the gaps but providing a comment that explains the pattern and each placeholders in the pattern. The most convinient way to add comments is to add them to the source. Most platforms provide a way to add comments into resource strings. Use them. It is also quite easy to forget to add a comment. This is why Soluling contains a composite comment checker. It works when scanning and writes information about missing comments into the log files. The checker helps tp detect the resource strings that have no comments.