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 appear on run time. The classic version of the 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 string where pattern and parameters are merged. For example

printf("Hello %s", name);

If the 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 a 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 a platform-independent format. No matter that is the source of the composite string, the string appears in the same way in Soluling.

nslators do not need to know the native format syntax of each platform. The grid shows placeholders visually such a way that the placeholder is a single item. The translator can move the placeholder within the string, but the editor makes sure that the translation has the same placeholders as in the original.

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

If such as string has two or more named placeholders, Soluling also includes the index part.

This is because some platforms let you use an expression in the placeholder instead of a single variable. If you have an expression, it is more likely to be changed than just a variable name. Adding an index makes it 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 needs to figure out the meaning just by reading the value of the string and if existing 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 to provide a comment that explains the pattern and each placeholder in the pattern. The most convenient 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.