Keith's Blog

Internationalization

My latest struggle and triumph at work involved internationalization.

Throught my code, were lines like this
LOG( "Transfered " << bytes << " to server");

Which won't translate into foreign languages well because the variable bytes might need to go in a different place in the sentence, and a translator would see strings like "Transfered " and " to server", which would be hard to translate without proper context.

And so I came up with the simple idea to use format specifiers. I used the syntax from C#, and now the log line looks like this.
LOG( "Transfered {0} bytes to server", bytes );

Now a translator would see the string "Transfered {0} bytes to server", which would be much easier to translate. As an added bonus, you can reuse the parameters ( "{0}.{1} {0}.{2}" ), and you can put them out of order (" {3}-{2}-{1} "). Although it wasn't hard to write, I'm proud of it anyway.


0 Comments:

Post a Comment

<< Home