Coding Guidelines/Internationalization

From wiki.zmanda.com
Revision as of 19:14, 30 May 2007 by Dustin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internationalization (i18n) means adding support for translations and other formatting differences to an application. Localization is the process of translating for a specific locale. As of this writing, Amanda has been internationalized, but not localized.

In Amanda, internationalization support has a few components.

Application Startup

Early in an application's initialization, it should include the following:

    setlocale(LC_MESSAGES, "C");
    textdomain("amanda"); 

Translatable Strings at Runtime

Strings which should be translated at runtime should be included in _(). When a local requiring translation is in use, this function will translate the string. It is important to note that the string in _() is statically parsed, so it cannot include any macros function invocations, variables, etc. It is usually used as the format argument to a printf-like function, under the assumption that the format specifiers ("%s", etc.) will remain in the same number and order through any translation. Examples:

dbprintf(_("syncpipe_get %s halting: Read error - %s\n"), procname, strerror(errno));
security_seterror(p->security_handle, _("error sending ACK: %s"), strerror(errno));

There is no need to translate strings containing no real text -- the use of _() in the following is unnecessary:

dbprintf(_("%s: %s"), program, error);

Translatable Strings at Compile Time

Strings that are statically compiled into the application (globals, static variables, etc.) cannot be translated by _(). Temporarily, we've decided to use T_() to mark such strings, but that is implemented only as a macro that passes its argument through directly. It's not clear what the final solution will be.