[この回答はLinuxプラットフォームのみを対象としています]
最初に知っておくべきことは、ロケール設定ファイルのほとんどの場所にあるパスが次の場所から取得できることですlocaledef --help。
$ localedef --help | tail -n 5
System's directory for character maps : /usr/share/i18n/charmaps
                       repertoire maps: /usr/share/i18n/repertoiremaps
                       locale path    : /usr/lib/locale:/usr/share/i18n
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>
最後を見る/usr/share/i18n?これは、xx_XX.UTF-8構成ファイルの場所です。
$ ls /usr/share/i18n/locales/zh_*
/usr/share/i18n/locales/zh_CN  /usr/share/i18n/locales/zh_HK  /usr/share/i18n/locales/zh_SG  /usr/share/i18n/locales/zh_TW
それで ?それらをアーカイブバイナリにコンパイルする必要があります。方法の1つ、たとえば/usr/share/i18n/locales/en_LOVE、私が持っていると仮定すると、それをコンパイルリストに追加でき/etc/locale-genます。
$ tail -1 /etc/locale.gen 
en_LOVE.UTF-8 UTF-8
そしてそれをバイナリにコンパイルしますsudo locale-gen:
$ sudo locale-gen 
Generating locales (this might take a while)...
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  ...
  en_LOVE.UTF-8... done
Generation complete.
そして、これでシステムのデフォルトのロケールをdesired LANG、LC_ALL... etcで更新しますupdate-locale:
sudo update-locale LANG=en_LOVE.UTF-8
update-locale実際には、/etc/default/localeセットアップ時に環境変数を設定するためにシステムからソースを取得するこのファイルを更新することも意味します。
$ head /etc/default/locale 
#  File generated by update-locale
LANG=en_LOVE.UTF-8
LC_NUMERIC="en_US.UTF-8"
...
ただし、有効にするために再起動したくない場合があるので、現在のシェルセッションの環境変数をソースにするだけです。
$ . /etc/default/locale
いかがsudo dpkg-reconfigure localesですか?それをいじってみると、このコマンドは基本的にGUIとして機能し、上記の手順を簡略化することがわかります。つまり、編集/etc/locale.gen-> sudo locale-gen->sudo update-locale LANG=en_LOVE.UTF-8
Pythonの場合、/etc/locale.genそのロケール候補を含み、locale.genコンパイルされる限り、setlocale(category, locale)throwsなしで動作するはずlocale.Error: unsupoorted locale settingです。ファイルを確認することで、に設定する正しい文字列en_US.UTF-8/ en_US/....etcを確認し、コメントを外して必要に応じてコンパイルできます。そのファイルにドットがない場合は、正しい文字列がandであることを意味します。setlocale()/etc/locale.genzh_CN GB2312zh_CNzh_CN.GB2312