Simplifying Foreign Translation Using Hash-tables

Origin Technology Fellow White Paper #7

Zachary Booth Simpson
30 March 1999

(c)2002 ZBS. http://www.mine-control.com/zack
Please sign my guestbo0k if you find this work useful.

Observations

Proposal

I propose a standardized solution to the static string translation problem. Instead of assigning arbitrary resource numbers, the strings in the original language (typically English) are used as hash keys to lookup the accompanying foreign string. Although this adds slightly to the string lookup time, this is usually not an issue since strings are so often associated with human-speed UI as noted above.

A macro is used to add the appropriate translation lookup. This macro simply wraps around the existing strings ensuring that the code is still readable and that there is only one copy of the string. For example: printf( XLAT("This is a string") );

Strings which need to extracted but which exist in static tables where a function call is illegal are marked with another macro: "XLATDEF". This is actually a null macro which serves only to mark the string. Large blocks of strings can be all marked with XLATDEF by placing a magic-code comment like "//{XLATDEF" and "//}XLATDEF".

Notes can be passed to the translators be simply inserting a special comment that begins with: "//XLAT:". These will be automatically extracted by the extractor tool and placed in the file next to the appropriate string.

String parameter reorganization is handled by a special version of vsprintf which allows arguments to have an assigned ordering. For example (using the example above):
XLATprintf("Ich möchte %2!d! Äpfel %1!s!",count,verb)

This causes the %d and the %s to be reversed. If no special numbering is given, it is assumed that the ordering has not changed and the translation functionality is transparent.

Technical Details

Thanks To

Tony Bratton: Directory of Technology at Digital Anvil