C
CodHubIV
Hello,
I'm writing some cross-platform software in C++, within it I have a
list of strings for various languages - My problem now is, how do I
determine the language setting of the person running the code so I can
present them information in the correct language? I'd rather not have
to resort to an entire framework just for this small function.
I tried "setlocale()" which always returns "C" on my Debian Lenny test
machine. I don't mind having slightly different functions for each OS
(I believe there are functions in the Windows API to determine
language, so that's taken care of), but I would like the Linux code to
work on all flavours of Linux, I see there's a "LANG" environmental
variable - Is this "safe" to rely on?
Code:
#include <iostream>
#include <locale.h>
int main()
{
// Get locale
char* value = setlocale(LC_ALL, NULL);
if (value == NULL)
std::cout << "NULL pointer returned" << "\n";
else
std::cout << "Value = \"" << value << "\"\n";
}
Result:
root@dev:./i18n
Value = "C"
Any help/advice from anyone who has tackled this before would be
appreciated...
Thanks,
I'm writing some cross-platform software in C++, within it I have a
list of strings for various languages - My problem now is, how do I
determine the language setting of the person running the code so I can
present them information in the correct language? I'd rather not have
to resort to an entire framework just for this small function.
I tried "setlocale()" which always returns "C" on my Debian Lenny test
machine. I don't mind having slightly different functions for each OS
(I believe there are functions in the Windows API to determine
language, so that's taken care of), but I would like the Linux code to
work on all flavours of Linux, I see there's a "LANG" environmental
variable - Is this "safe" to rely on?
Code:
#include <iostream>
#include <locale.h>
int main()
{
// Get locale
char* value = setlocale(LC_ALL, NULL);
if (value == NULL)
std::cout << "NULL pointer returned" << "\n";
else
std::cout << "Value = \"" << value << "\"\n";
}
Result:
root@dev:./i18n
Value = "C"
Any help/advice from anyone who has tackled this before would be
appreciated...
Thanks,