Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need the cs_CZ.ISO8859-2 locale to exist on Ubuntu 12.04 so a specific unit test can pass. The test makes the following call:

std::locale("cs_CZ.ISO8859-2")

On my OS X Lion install, this locale does exist, so the call to std::locale should work:

$ locale -a | grep cs
cs_CZ
cs_CZ.ISO8859-2
cs_CZ.UTF-8
$

However, on my Ubuntu 12.04 install, there is only a UTF8 variant, and no ISO8859-2 version of the cs_CZ locale, despite having installed language-pack-cs:

$ dpkg -l | grep language-pack-cs
ii  language-pack-cs                       1:12.04+20120417                        translation updates for language Czech
ii  language-pack-cs-base                  1:12.04+20120417                        translations for language Czech
$ locale -a | grep cs_
cs_CZ.utf8
$

The unit test fails on this machine. Running the unit test under strace shows that it really is looking for the ISO8859-2 variant and not finding it anywhere:

open("/usr/lib/locale/cs_CZ.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs_CZ.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs_CZ/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs_CZ.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs_CZ.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs_CZ/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

I know absolutely nothing about locales, i18n, etc. However, I would like to get this test passing, and changing the test is not an option. If anyone can offer any insight into how to make this locale exist on Ubuntu 12.04 I would appreciate it greatly.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The steps below work on Arch Linux (not sure about Ubuntu).

  1. Edit file /etc/locale.gen,
  2. add line cs_CZ ISO-8859-2,
  3. run sudo locale-gen to generate locale files.

After that std::locale("cs_CZ.ISO8859-2") should work fine.

share|improve this answer
2  
This doesn't work exactly on Ubuntu, but it got me started down the right path so I'll accept your answer. The right way to do this on Ubuntu was to add cs_CZ.ISO-8859-2 ISO-8859-2 to /var/lib/locales/supported.d/cs –  acm May 15 '12 at 16:23
1  
Actually, it looks like adding that string to /var/lib/locales/supported.d/local works as well, and may be more officially the correct way. Anyway, for ubuntu it looks like calling sudo dpkg-reconfigure locales will take care of calling locale-gen. –  acm May 15 '12 at 17:13
1  
Seems that both ways (editing /etc/locale.gen and sudo dpkg-reconfigure locales) work under Debian too (wiki.debian.org/Locale). –  hluk May 15 '12 at 17:35

Ubuntu has tweaked the locale-gen utility. Call it with the names of the locales you want to generate.

locale-gen cs_CZ.ISO8859-2
share|improve this answer
    
This runs without error, but doesn't seem to have any effect. The desired locale does not show up on the list from locale -a after running the above. –  acm May 16 '12 at 15:26
    
@SamuliKärkkäinen The new locale is available immediately, the terminal has nothing to do with the locale. It's possible that your terminal emulator offers encodings based on available locales, in which case it may or may not give you a choice to change the encoding at runtime, and even if it does it may only allow choosing between locales that were available when the terminal emulator started. –  Gilles Oct 2 '13 at 10:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.