#!/bin/sh

# must be run before setup_gdm

set -eu

puavo_locale=$(puavo-conf puavo.l10n.locale)

{
  if [ -n "$puavo_locale" ]; then
    puavo_language_short_form=$(echo "$puavo_locale" | cut -c 1-2)
    echo "LANG=${puavo_locale}"
    echo "LANGUAGE=${puavo_language_short_form}"

    puavo_dconf_profile="user-${puavo_language_short_form}"
    if [ -e "/etc/dconf/profile/${puavo_dconf_profile}" ]; then
      echo "DCONF_PROFILE=${puavo_dconf_profile}"
    fi
  fi
} > /etc/locale.conf.tmp

if [ -s /etc/locale.conf.tmp ]; then
  mv /etc/locale.conf.tmp /etc/locale.conf
else
  rm -f /etc/locale.conf.tmp
fi
