0

According to ISO C and POSIX error messages returned by strerror() family should be locale specific. While in my example (Mac OS X 10.10.5 / clang / c11) they are not. I checked several platforms and all of them behave in the same way.

I have checked locales by 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;
}

Show:

Error message : No such file or directory
ptomato
  • 56,175
  • 13
  • 112
  • 165
Ariel
  • 668
  • 8
  • 16

1 Answers1

1

I don't see a requirement in the Standard that error messages have translations for nonstandard locales. Further, this manpage says that the error message string is selected (emphasis mine):

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

That said, I notice that I can change the locale to fr_FR.UTF-8 on my system, generating the following error message for your code:

Error message : Aucun fichier ou dossier de ce type

If you want error messages in Hebrew, you may have to code for them by hand. Keep in mind that many feel that error messages should not be translated; here is a SO question with a discussion of this topic.

Community
  • 1
  • 1
ad absurdum
  • 19,498
  • 5
  • 37
  • 60
  • I tried several locales including yours but no one works. What is your system? I checked a few online compilers and no one shows localised output. – Ariel Mar 26 '17 at 21:01
  • I am using Linux Mint. You can try any of the locales shown by `locale -a`. You may need to install a new locale; on Mint I can go into the Software Manager to install language-packs. `language-pack-fr-base` contains several French locales, `fr_FR.utf-8` among them. I also tried a German locale (`de_DE.utf-8`) that worked and gave German error messages. But I installed `language-pack-he-base` for the `he_IL.utf-8` locale (which I can see with `locale -a`), and, as you found, my error messages were stlll in English. – ad absurdum Mar 26 '17 at 21:24