Change LightDM's language (and its greeters)

Published: Mon, 20 Mar 2017
Modified: Fri, 13 Oct 2017

In: Linux

Tags: lightdm

Translations: bs

I found myself in a situation where I needed LightDM (and its greeters) to use a language other than the one defined globally by the LANG environment variable. Searching the internet didn't yield any results, so I was forced to achieve it with an ugly hack.

The workaround solution consisted of overwriting the globally set language's (in my case English) translation file with my desired language's one. I copied the /usr/share/locale/bs/LC_MESSAGES/lightdm-gtk-greeter.mo file into /usr/share/locale/en/LC_MESSAGES/lightdm-gtk-greeter.mo.

That's far from an ideal solution, so I kept searching for something beter until I realized that I could do it another way.

Systemd way

This is a slightly hacky way. See below for a better solution

I am starting LightDM as a systemd service. Systemd is able to pass environment variables to services and that's exactly what can help us. All we have to do is edit LightDM's service file and add the ENVIRONMENT="LANG=bs_BA.UTF-8" in there.

Systemd offers a convenient way to edit service files with systemctl edit lightdm. It will automatically create an override file for the service. Alternatively, you can do it manually, by creating the appropriately named directory and override file in /etc/systemd/system/.

Here's how my file looks like:

$ cat /etc/systemd/system/lightdm.service.d/override.conf 
[Service]
Environment=
Environment="LANG=bs_BA.UTF-8"

I have a blank Environment line because it clears an already set Environment option. This might not be necessary because there might not be an already exported Environment file in the actual LightDM service, but I reckon it won't hurt. If it does conflict or have any unwanted effects, please let me know in the comments.

LightDM greeter way

Running your greeter with a different language is better than running LightDM, since it seems that the session inherits the variable from LightDM which can lead to ugliness down the road.

Create a new desktop file in the directory where LightDM sources the available greeters, usually in /usr/share/xgreeters. Then just modify the Exec= line to start lightdm-gtk-greeter with a different language using environment variables. After that modify your lightdm.conf file and specify your new greeter to be used with the greeter-session= option.

[Desktop Entry]
Name=LightDM GTK+ Greeter
Comment=This runs the GTK+ greeter, it should only be run from LightDM
Exec=env LANGUAGE=bs lightdm-gtk-greeter
Type=Application
X-Ubuntu-Gettext-Domain=lightdm