Change LightDM's language (and its greeters)

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

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.