I'm unable to set UTF-16, or any form thereof, as locale on my Linux box. The sample code for this:
#include <iostream>
#include <string.h>
#include <locale.h>
using namespace std;
int main()
{
char *ret = std::setlocale(LC_ALL, "en_US.utf16");
if (ret) {
cout << ret << endl;
}
return 0;
}
The output doesn't print the locale set, which means that desired locale was not set.
The list of supported locales on the box does not include any form of UTF-16 encoding. I checked this via locale -a
$ uname -a
Linux developer.com 2.6.32-279.1.1.el6.x86_64 #1 SMP Tue Jul 10 11:24:23 CDT 2012 x86_64 x86_64 x86_64 GNU/Linux
Does something need to be installed to use UTF-16 on the box?
To change the value of a locale which is already set, we can edit the . bashrc profile of the use who needs the new locale. $ locale LANG=en_IN. utf8 LANGUAGE=en_US LC_CTYPE="en_IN.
To enable UTF-8 mode, use ". UTF8" as the code page when using setlocale . For example, setlocale(LC_ALL, ". UTF8") will use the current default Windows ANSI code page (ACP) for the locale and UTF-8 for the code page.
The setlocale() function is used to set or query the program's current locale. If locale is not NULL, the program's current locale is modified according to the arguments. The argument category determines which parts of the program's current locale should be modified.
Locales customize programs to your language and country. When you installed Ubuntu, you answered some simple questions such as specifying your country and language. Ubuntu used the answers to those questions, in part, to choose a suitable locale for your installation.
You wont be able to set UTF-16 as locale in Linux as UTF-16 is not ASCII compatible. C strings are Null terminated and as UTF-16 can contain embedded nul
characters, that wont work. You need to stick to UTF-8.
If you want to generate more locales than your system currently has, have a look at /etc/locale.gen
, edit this file, then run (as root) the command locale-gen
to generate the newly inserted locales. But beware: even here you wont be able to generate UTF-16!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With