By default, Berkeley DB messages are comprised of a message number followed by message text in English. For example:
It is possible to build Berkeley DB with stripped messages. When messages are stripped, the message text is removed from the library, leaving behind only the message number. When building a stripped library, there is no message text available so localization will not work.
If localization is enabled, the translated message is substituted for the original message text.
To output messages in a language other than the default English, follow the steps below:
Provide an i18n component containing a localization function used to translate messages, and translation files that map existing messages to localized messages. The localization function can be added to the current Berkeley DB project, or as a dynamic library that is called at run time.
Add the name of the localization function as the prefix for “(msg)” when is defined in
build_unix/db_int.in
on *nux, or inbuild_windows/db_int.h
on Windows.Within your application code, use or DB->set_errcall() to print the messages.
Note that Berkeley DB supports only UTF-8 for its message text. If your localization requires UTF-16 Unicode, the UTF-16 characters must be converted to UTF-8 Unicode by your localization function. If necessary, the error reporting function you specify to or DB->set_errcall() can be used to revert the UTF-8 Unicode back to the UTF-16 Unicode.
The following example walks you through providing localization support for a single Berkeley DB error message:
Write and compile your localization functions: Note that the “es”, “de_CH” and “root” tags are used as the locale name in
ures_open()
.Also notice that because
ures_getStringByKey()
returns UTF-16 Unicode, its output is converted to UTF-8 usingucnv_fromUChars()
.Rebuild Berkeley DB, making sure to specify the
HAVE_LOCALIZATION
compile option.Specify the error callback.
The result of this is if you input an incorrect recno and reach the error 1002, the message “BDB1002 illegale Rekordzahl von 0” is output.