Naoko Hamamoto's Weblog

« Creator runs out of... | Main | Creator demo on how... »

20060217 Friday February 17, 2006

Changing system locale on the fly

I am new to globalization. Our organization (Globalization) is responsible for product localization and internationalization. Prior to joining this group, I was in development and backline support for various software product lines within Sun.

I have faced internationalization/localization issues throughout my career, but I did not really have a deep understanding of them. Now that I have joined this organization, I have to come to realize that there are a lot of cool stuff to learn! Some of these topics may be trivial to globalization gurus, but they may be of some interest to others. If you want to learn more about globalization, read on!

In globalization, we need to always switch back and forth between different locales, especially when we test products.

On Solaris, the common way is to relogin and select a different locale, assuming that the necessary font packages are already installed on the system. What about if you want to change the locale on a terminal window on the fly? You can use a command called locale to check the current setting.

Examples:

Using C (Posix)
% locale
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=

Using ja (EUC)
% locale
LANG=ja
LC_CTYPE="ja"
LC_NUMERIC="ja"
LC_TIME="ja"
LC_COLLATE="ja"
LC_MONETARY="ja"
LC_MESSAGES="ja"
LC_ALL=

You can change these environment variables to change the locale setting for that window.

On Windows, there is a command called chcp. When you type chcp, it tells you what the active console code page is. If you want to change it, simply add the code page for that locale.

Examples:

This is the active console code for U.S. English.

This is the active console code for Japanese.

I also learned from my colleague, Yuko, who is the Creator localization lead as well as my valuable resource on localization and Creator, that there are a couple of batch files on Japanese Windows. If you type us, it executes chcp 437 and if you type jp, it executes chcp 932. Pretty handy! Thanks Yuko!

Posted by naoko ( Feb 17 2006, 03:33:41 PM PST ) Permalink Comments [3]

Trackback URL: http://blogs.sun.com/naoko/entry/changing_system_locale
Comments:

Yep, i18n is hard :-) You might also be interested in the ever-useful <tt>nl_langinfo(3C)</tt> library function on Solaris, which you can use to find out the default codeset. For example :

#include <langinfo.h>
#include <locale.h>
#include <stdio.h>

int main(char* args){
 setlocale(LC_ALL,"");
 printf("%s\n",nl_langinfo(CODESET));
}

timf@maranello[517] /opt/SUNWspro/bin/cc -o codeset codeset.c
timf@maranello[518] locale
LANG=C
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_ALL=en_US.UTF-8
timf@maranello[519] ./codeset
UTF-8
timf@maranello[520] export LC_ALL=ja_JP.PCK
timf@maranello[521] ./codeset
PCK
timf@maranello[522] export LC_ALL=ja_JP.eucJP
timf@maranello[523] ./codeset
eucJP
timf@maranello[524] export LC_ALL=C
timf@maranello[525] ./codeset
646

Posted by Tim Foster on February 18, 2006 at 01:16 PM PST #

Hi Tim, thanks for your post. Ah, good to know! --Naoko

Posted by naoko on February 21, 2006 at 11:35 AM PST #

The locale command can be used to get the same information as the following:
$ env LC_ALL=ja_JP.PCK locale code_set_name
PCK
$ env LC_ALL=ja locale code_set_name
eucJP

Posted by muffin on July 19, 2007 at 02:38 PM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.