The Linux Page

Invalid locale on Ubuntu

My compamy creates many software and some are translated. Up to here, nothing serious.

Now compiling can be a problem as older versions of msgfmt do not like the BOF character at the start of text files. It has to be clean UTF-8, but no BOF.

Anyway... Now I compiled and I need to test the results. So I need to run in French, Spanish, etc.

The normal way under Unix is to do this:

   LANG=es program-name options

Although the name of the language can be a bit more complicated such as es_ES.ISO-8859-1.

For some reasons, when I tried that under Ubuntu it just did not work.

What you can do to test is this:

   LANG=fr locale

That way, the locale is set to French and then the locale tool tells you what the complete locale setup by showing it in your console. If you get an error, then it failed. It can fail because you do not have the French locale information or somehow the French information fails to install.

To force the installation of a language, you need to use the localedef function:

   sudo localedef -c -f iso885915 -i en_GB en_GB.iso885915
   sudo localedef -c -f iso88591 -i en_US en_US.ISO-8859-1
   sudo localedef -c -f iso88591 -i es_ES es_ES.iso88591

The sudo is necessary because the output is saved in a directory that is protected (only for root to access in write access).

The -c option forces the conversion of the source file with totally invalid characters/variables to anyway be compiled and saved. You could also look into fixing the files (duh!) and post the fixed file on some Ubuntu or Debian bug tracker.

The rest is used to generate the files as expected.

Now, when I tried that with the French language it failed and even the -c option was not enough. That one, I really had to edit the address field where I replaced the <U00F8> entries with a 'u' letter (I think that's a u, but frankly it does not matter at all to me!)

Now that fixed the problem at once!