#!/usr/bin/python3

DOMAIN = "mintdesktop"
PATH = "/usr/share/linuxmint/locale"

import os
import gettext
import subprocess
from mintcommon import additionalfiles

os.environ['LANGUAGE'] = "en_US.UTF-8"
gettext.install(DOMAIN, PATH)

prefix = "[Desktop Entry]\n"

suffix = """Exec=mintdesktop
Icon=user-desktop
Terminal=false
Type=Application
Encoding=UTF-8
Categories=GNOME;GTK;Settings;DesktopSettings;XFCE;X-XFCE-SettingsDialog;X-XFCE-PersonalSettings;
StartupNotify=false
OnlyShowIn=MATE;XFCE;
"""

additionalfiles.generate(DOMAIN, PATH, "usr/share/applications/mintdesktop.desktop", prefix, _("Desktop Settings"), _("Fine-tune desktop settings"), suffix)

locales = []
cur_dir = os.getcwd()
os.chdir("/usr/share/linuxmint/locale")
lines = subprocess.getoutput("find */LC_MESSAGES/mintdesktop.mo")
for line in lines.split("\n"):
    line = line.strip().split("/")[0]
    locales.append(line)
os.chdir(cur_dir)

for locale in locales:
    os.system("mkdir -p usr/share/help/%s/mintdesktop/" % locale)
    os.system("msgunfmt /usr/share/linuxmint/locale/%s/LC_MESSAGES/mintdesktop.mo > /tmp/%s.po" % (locale, locale))
    os.system("xml2po -p /tmp/%s.po -o usr/share/help/%s/mintdesktop/index.page usr/share/help/C/mintdesktop/index.page" % (locale, locale))
    os.system("xml2po -p /tmp/%s.po -o usr/share/help/%s/mintdesktop/wms.page usr/share/help/C/mintdesktop/wms.page" % (locale, locale))
    os.system("xml2po -p /tmp/%s.po -o usr/share/help/%s/mintdesktop/compositing.page usr/share/help/C/mintdesktop/compositing.page" % (locale, locale))
    os.system("cp usr/share/help/C/mintdesktop/legal.xml usr/share/help/%s/mintdesktop/" % locale)
