Making Slackware and Slackware Derivative Linux Distros Speak Your Language

By Caitlyn Martin
January 28, 2009 | Comments: 13

Slackware and some Linux distributions based on Slackware don't include GDM and don't have a graphical tool to set language and locale on the fly. However, if you're willing to edit one or two configuration files and install a few packages you can make Slackware speak your language, working in whatever language you are most comfortable with.

There are four variables that need to be set on almost any modern Linux distribution to fully localize a system:

LANG
LANGUAGE
LINGUAS
LC_ALL

LC_ALL is actually a meta-variable that sets a whole bunch of other variables which start with LC If your goal is to have everything set for what is normal in a given language and country you needn't worry about that. Setting only one or some of these variables results in a mixed language. I've seen how-to articles saying to just set LANG, for example. If the default language is English and you set LANG to es_MX (Spanish for Mexico) the net result is a Spanglish system which probably isn't what most people want.

Where you actually set the variables depends on two things. First, you need to decide if you want to change you system default language and locale or just make changes on a user-by user basis. Second, if you are changing for an individual user you need to know what the default shell is for that user. If you use more than one shell you may need to make the changes in more than one place.

The simpler approach is just changing the default language and locale for the system as a whole. On a vanilla Slackware system they are set in two files localed in /etc/profile.d lang.sh takes care of the default Bourne Again shell (bash) as well as the original Bourne shell (sh) commonly used in system scripts. lang.csh takes care of anyone using csh or tcsh. If you don't use either csh or tcsh on your system you can safely ignore that file.

If you look at /etc/profile.d/lang.sh in your favorite text editor you will see a section that looks like this:

# en_US is the Slackware default locale:
export LANG=en_US

If I wanted my system in Canadian French I could change this section as follows:

# en_US is the Slackware default locale:
export LANG=fr_CA
export LANGUAGE=fr_CA
export LINGUAS=fr_CA
export LC_ALL=fr_CA

You could optionally add .utf8 for Unicode support to each line. Some old applications don't handle Unicode properly. On the other hand, if you use a language that has non-Latin glyphs Unicode is pretty much mandatory. Some Slackware derivatives now use Unicode as part of their default setting even in English. If I'm setting up a system to work in Israeli Hebrew this section would read:

# en_US is the Slackware default locale:
export LANG=he_IL.utf8
export LANGUAGE=he_IL.utf8
export LINGUAS=he_IL.utf8
export LC_ALL=he_IL.utf8

If you're not sure what the language and locale codes are the command:

locale -av

will give you a detailed alphabetical list. It's a very long listing so you may want to pipe the output to more or redirect it to a file.

lang.csh is similar with the setenv command replacing the export command. A stock Slackware lang.csh file will have code that looks like:

# en_US is the Slackware default locale:
setenv LANG en_US

As in lang.sh you replace en_US with the language and locale you want and you include all four variables. Brazilian Portuguese with Unicode support looks like this:

# en_US is the Slackware default locale:
setenv LANG pt_BR.utf8
setenv LANGUAGE pt_BR.utf8
setenv LINGUAS pt_BR.utf8
setenv LC_ALL pt_BR.utf8

Changing language and locale on a user-by-user basis uses exactly the same code. Instead of placing the export commands above in /etc/profile.d/lang.sh you put them in ~/.bashrc ~/.cshrc is used instead of /etc/lang.csh

Once you have your variables set they will take effect at the next login. However you may still not get quite everything in your language of choice. If you use KDE you will also need to install the i18n package for your language. Slackware includes these packages in the repository under kdei. There is a separate i18n package for k3b (CD/DVD burning software) which contains translations for a wide variety of languages. If you use koffice the Slackware repository also includes l10n packages for each supported language. There is also a single glibc i18n package for all locales that I recommend for anyone using a language other than English.

The Slackware extra repository includes a variety of dictionaries for the GNU aspell spellchecker. Language packs and/or dictionaries for Mozilla products (Firefox, Thunderbird, Sunbird and Seamonkey) and for OpenOffice are not in the Slackware repository and have to be obtained from upstream or third party sources. Some Slackware derivatives either offer these packages or, in some cases, fully localized versions of the applications. Spelling dictionaries for spellcheckers other than aspell also aren't in the Slackware repository.

Once the packages for your language and locale are all installed everything should work the next time you launch the application or desktop environment.

If you're coming from a distribution like Ubuntu or Fedora this undoubtedly seems a bit complex. That's probably also true for users of a distro like Zenwalk, which is a Slackware derivative with GDM. If you're comfortable on the command line and with a text editor it really isn't all that difficult. If you're running Slackware it's pretty much assumed that you are either comfortable with the command line or would like to be.


You might also be interested in:

13 Comments

This seems fantastically useful :)
Thanks Caitlyn :) I think Wolvix does have some sort of graphical tool for this but the way you describe sound possibly easier and more rigorous. A chap in Wolvix seems to have fairly good english but i think would appreciate this so i'm just hoping it works for him :)

Thanks and regards from
Tom :)

Thank you for this very handy tutorial. It's greatly appreciated. Rather than log-in back and forth, one could simply "source" the system-wide or user's profile to reload the exported environment variables. i.e.

$> source /etc/profile.d/lang.sh
$> source ~user/.bashrc


Thank you

Very good. Thank you
One problem though.
I used your article to change to Hebrew. Works fine & allows me to copy files with Hebrew file-names from a SAMBA share to an external hdd and preserve the Hebrew. I wrote a script (bash) to do this. Strangely, when I run the script via cron, it doesnt copy the Hebrew files. I put "env" in the script and it didnt show me any of the variable you mentioned. It's as though the changes to lang.sh dont work for files run under cron.

Do you have any ideas?

Thanks

Arieh

Shalom, Arieh,

One thing comes to mind immediately. Are you running the script from the root crontab? If so it is very possible, even likely, that you've changed your user language/locale default but have not done for root.

Slackware ships Matt Dillon's dcron, which is a bit simpler than most other cron implementations. The quote below is from crontab(1):

Unlike other crond/crontabs, this crontab does not try to do everything under the sun. Frankly, a shell script is much more able to manipulate the environment then cron and I see no particular reason to use the user's shell (from his password entry) to run cron commands when this requires special casing of non-user crontabs, such as those for UUCP. When a crontab command is run, this crontab runs it with /bin/sh and sets up only three environment variables: USER, HOME, and SHELL.

Thanks, Caitlyn!
Your article seems pretty straight-forward, still I think I missed something. I want Slackware to be all in English, but since I'm brazilian, I want to be able to write in Portuguese, considering cedilla and hyphenization.
All the system reverts to portuguese if I edit /etc/profile.d/lang.sh and change the entry:
export LANG=en_US to export LANG=pt_BR
but I still can't type cedilla and hyphenization.
So, can I leave LANG=en_US and set the other variables to pt_BR?
Thanks in advance,
Gustavo

@Robby Workman: Thanks for the information. I learned something new about Slackware today.

I would think the best solution for Arieh, then, is to install vixie-cron to replace dcron. That would give him the additional capabilities he needs.

@Gustavo: This article is for changing the environment to a different language which is different from what you want to do. What it sounds like you want is to be able to use a Portuguese keymap in addition. To do that in Slackware you will need to edit your /etc/X11/xorg.conf file.

Find a section that looks like:

Section "InputDevice"
Identifier  "Keyboard0"
Driver      "kbd"
Option  "XkbLayout"  "us"    ## KEYBOARD_MAP!
Option  "XkbModel"  ""    ## KEYBOARD_MODEL!
Option  "Xkbvariant"  ""    ## KEYBOARD_VARIANT!
EndSection

That is set for US English. If you add a comma after the us and the correct code for a Brazilian Portuguese keyboard then you will be able to switch back and forth with the panel applet included with KDE or Xfce. If you want a Brazilian keyboard map full time you can replace the US and just have a single entry.

That should solve the problem for you.

i want to be able to change between typing languages in my slackware derivative ( vector ) .

i should change xorg conf like this : ??

Option "XkbLayout" "us,el_GR" ## KEYBOARD_MAP!

and how i will switch between these two language? ( shortcut ? )

@Hlekat: I'm not at all sure you have the correct code for a Greek keymap. el_GR is the correct language/locale coding but keymap codings can be different. You'll need to check that.

What version of Vector Linux are you running? With VL 6.0 or 5.9 you can choose the keymapping using an applet provided with Xfce. Just add the keyboard switching applet to the panel and you can toggle back and forth with a click. If you are running VL 6.0 Deluxe or VL 5.9.x SOHO then KDE has a similar panel plasmoid. There is also a GNOME panel applet if you installed GNOME from the VL 6.0 repository.

I hope this helps.

I think replacing dcron with vixiecron is overkill and *much* more prone to trouble. As with Slackware in general, instead of trying to turn it into something that it isn't, work with what it is in the way it's intended.

Set the relevant environment variables inside the script that's being run by crontab - it's that simple. If that's too much typing, you could even do ". /etc/profile.d/lang.sh" at the top of it and all should be well.

@Robby Workman: Just curious, but why is vixie-cron "prone to trouble"? It is the standard in most distros and it is very much a mature product. I use a Slackware derivative that includes it by default and it has been rock solid for me.

I can't answer that question, as that's not what I wrote.
I wrote "I think replacing dcron with vixiecron is ... prone to trouble." The important term in that is "replacing."

I'm not averse to replacing parts of Slackware *IF* one actually *needs* the replacement, but that's not the case here at all. arieh doesn't need a different cron daemon at all - he simply needs to understand that dcron's design requires him to add one more line of text to his script.

The bigger point is this: I've seen countless examples of users who have royally screwed their systems (whether Slackware or otherwise) by trying to replace parts of it with something unsupported; therefore, I'm not at all fond of suggesting that one do so unless there's a legitimate need for it.

Dillon's cron is not usefull for laptops. not care about env variables (MAILTO), always write and delete mail file in /var/spool/cron even not output of cron jobs and prevent hdd sleep. i switch dillon's cron to vixie cron in slackware.

News Topics

Recommended for You

Got a Question?