Where does Cygwin set the locale ($LANG env var)?

4

3

I know that I can use the locale tool and the export LANG=... to set my locale on Cygwin.

However, even I don't have %LANG% defined on Windows, when I run bash --login, I notice $LANG is already affected to fr_CH.UTF-8 where I want it to be en_US.UTF-8.

$LANG is set before /etc/lang.sh and even before /etc/profile.

Where is it defined? How can I properly change it?

nowox

Posted 2015-01-14T12:25:54.050

Reputation: 1 779

Answers

7

Where does Cygwin set the locale ($LANG env var)?

At application startup, the application's locale is set to the default "C" or "POSIX" locale. Under Cygwin 1.7.2 and later, this locale defaults to the ASCII character set on the application level.

...

How to set the locale

Assume that you've set one of the aforementioned environment variables to some valid POSIX locale value, other than "C" and "POSIX". Assume further that you're living in Japan. You might want to use the language code "ja" and the territory "JP", thus setting, say, LANG to "ja_JP".

You didn't set a character set, so what will Cygwin use now? Starting with Cygwin 1.7.2, the default character set is determined by the default Windows ANSI codepage for this language and territory. Cygwin uses a character set which is the typical Unix-equivalent to the Windows ANSI codepage.

You don't want to use the default character set? In that case you have to specify the charset explicitly. For instance, assume you're from Japan and don't want to use the japanese default charset EUC-JP, but the Windows default charset SJIS.

What you can do, for instance, is to set the LANG variable in the mintty Cygwin Terminal in the "Text" section of its "Options" dialog.

enter image description here

If you're starting your Cygwin session via a batch file or a shortcut to a batch file, you can also just set LANG there:

  @echo off

  C:
  chdir C:\cygwin\bin
  set LANG=ja_JP.SJIS
  bash --login -i

Source Chapter 2. Setting Up Cygwin - Internationalization

DavidPostill

Posted 2015-01-14T12:25:54.050

Reputation: 118 938