diff --git a/en_US.ISO8859-1/books/developers-handbook/l10n/chapter.sgml b/en_US.ISO8859-1/books/developers-handbook/l10n/chapter.sgml index 686eb49f63..c849284e27 100644 --- a/en_US.ISO8859-1/books/developers-handbook/l10n/chapter.sgml +++ b/en_US.ISO8859-1/books/developers-handbook/l10n/chapter.sgml @@ -221,6 +221,60 @@ printf(getstr(1)); #ifndef WITHOUT_NLS catclose(catalog); #endif + + + Reducing Strings to Localize + + There is a good way of reducing the strings that + need to be localized by using libc + error messages. This is also useful to just avoid duplication + and provide consistent error messages for the common errors + that can be encountered by a great many of programs. + + First, here is an example that does not use + libc error messages: + + +#include <err.h> +... +if (!S_ISDIR(st.st_mode)) + err(1, "argument is not a directory"); + + + This can be transformed to print an error message by + reading errno and printing an error message + accordingly: + + +#include <err.h> +#include <errno.h> +... +if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; + err(1, NULL); +} + + + In this example, the custom string is eliminated, thus + translators will have less work when localizing the program + and users will see the usual Not a directory + error message when they encounter this error. This message + will probably seem more familiar to them. Please note that + it was necessary to include errno.h in order to directly + access errno. + + It is worth to note that there are cases when + errno is set automatically by a preceding + call, so it is not necessary to set it explicitly: + + +#include <err.h> +... +if ((p = malloc(size)) == NULL) + err(1, NULL); + +