Symbian
Symbian OS Library

FAQ-0047 Don't presuppose ways of joining text messages together

[Index][spacer] [Previous]



 

Classification: General Category: Development
Created: 01/12/98 Modified: 06/12/2001
Number: FAQ-0047
Platform: Not Applicable

Question:
Don't presuppose ways of joining text messages together

Answer:
Suppose you need to be able to generate a series of text messages
"First tick box not available", "Second tick box not available", and "Third tick box not available".

It's tempting to define a single resource

" tick box not available"

together with three shorter strings, "First", "Second", and "Third", and then use the Append( ) function to create the required combined string at run-time.

However, use of Append( ) like this should always be queried. It would disallow a foreign-language translation with the words placed in a different order, eg like

"Tick box the first is not available" (ie its literal equivalent in French, German, or whatever).

Better therefore to define a single resource

"%S tick box not available"

along with "First", "Second", and "Third", as before, and use the Format( ) function to create the required combined string at run-time.

That leaves translators free, if they wish, to alter the resource to the French/German/etc equivalent of

"Tick box %S not available"

Generalization:

You need to think even more generally that this: if your message, in English, were

"%S %S not available"

then the form of the word "available" would change between masculine and feminine in Latin-derived languages (but not Germanic ones).

Another example of Bad Practice is

"%d tag%S displayed"

where the second parameter could be "s" for the number being 0 or >=2, or could be blank for the number being 1. This falls right apart in most foreign languages which (a) don't implement plurals using 's' and (b) [in the case of Latin-derived ones] need to make "displayed" agree with the number as well. One solution here is to use three messages, for the 0, 1 and many cases.

AppendFormat() is also not good at coping with word order changes: its parameters are inserted into the string in a fixed order.

Generalized code review criterion: don't attempt to synthesize sentences using AppendFormat(), because it'll probably work differently in other languages.

Particular things to watch for are

- word order different

- gender may matter, and require agreement

- plurals formed differently, and may require agreement

Some languages have other surprises, but the above three considerations will catch nearly everything in all languages we're interested in - partially, because it produces a mind set which doesn't allow for possible problems to arise, and partially because, although the world's languages show very rich variations in structure, they are not arbitrarily complicated.