Best Practices
Last updated
Last updated
This content is available to you thanks to the contribution of following people:
When translating into other languages, interpolation causes real problems. Fundamentally, what interpolation does is concatenate pieces of text. English sentences split into sentence fragments and programmatically constructed at runtime are difficult and sometimes impossible to translate, unless you have implemented multilingual grammar rules, which is rare.
Use interpolation sparingly to minimize issues with localization. Interpolation cannot be avoided for values that can only be known at runtime, such as:
Time stamps
User-inputted data
Suppose you want to use interpolation to replace the value for {paymentType}
in the following key
wherein {paymentType}
could be 'credit card' or 'PayPal account'.
In German the spelling of the word "the" preceding {paymentType}
must change depending on which value is passed.
The result is some runtime strings will be broken
// -> "Alle Beträge werden dem Kreditkarte fßr dieses Konto in Rechnung gestellt." <- 'dem Kreditkarte' should be 'der Kreditkarte'
// -> "Alle Beträge werden dem PayPal-Konto fßr dieses Konto in Rechnung gestellt." <- 'dem PayPal-Konto' is correct
This is just one simple example of a very complex localization problem.
Use two separate fully self-contained strings instead: