libc 是否显示国际错误消息?

Does libc show international error messages?

根据 ISO C 和 POSIX,strerror() 系列返回的错误消息应该是特定于语言环境的。在我的示例中 (Mac OS X 10.10.5 / clang / c11) 它们不是。我检查了几个平台,它们的行为方式都相同。

我已经通过 locale -a 检查了语言环境。

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#include <locale.h>

#include <string.h>

int main(int argc, const char * argv[]) 
{
    setlocale(LC_MESSAGES, "he_IL.UTF-8");

    errno = 0;
    // Generate unique filename.
    FILE *file = fopen(tmpnam((char[L_tmpnam]){0}), "rb");

    if (file) {
        // Do something useful. 
        fclose(file);
    }
    else {
        fprintf(stderr, "Error message : %s\n", strerror(errno));
    }

    return EXIT_SUCCESS;
}

显示:

Error message : No such file or directory

我在标准中没有看到 要求 错误消息具有针对非标准语言环境的翻译。此外,this manpage 表示选择了错误消息字符串(强调我的):

possibly using the LC_MESSAGES part of the current locale to select the appropriate language.

也就是说,我注意到我可以在我的系统上将区域设置更改为 fr_FR.UTF-8,从而为您的代码生成以下错误消息:

Error message : Aucun fichier ou dossier de ce type

如果您需要希伯来语的错误消息,您可能需要手动编写代码。请记住,许多人认为不应翻译错误消息; here is a SO question 对此主题进行了讨论。