# SConstruct
# Copyright (C) 1999-2021 Eicke Godehardt

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


Import ('env install_dir prefix tar_file')

languages = ['cs', 'de', 'fr', 'hu']

pot = env.Command ('glosung.pot', ['#/src/about.c',
                                   '#/src/autostart.c',
                                   '#/src/collections.c',
                                   '#/src/download.c',
                                   '#/src/glosung.c',
                                   '#/src/losung.c',
                                   '#/src/parser.c',
                                   '#/src/settings.c',
                                   '#/src/util.c',
                                   '#/ui/add_language.glade',
                                   '#/ui/preferences.glade',
                                   '#/ui/warning_dialog.glade'],
          "xgettext --add-comments --keyword=_ --keyword=N_ --add-location --strict --output=$TARGET $SOURCES");
for lang in languages:
    po = env.Execute (action = "msgmerge --update --strict --verbose " + lang + ".po glosung.pot");
#    po = env.Command (lang + '.po',  'glosung.pot', "msgmerge --update --strict --verbose $TARGET $SOURCES");
#    env.Depends (po, pot)
    mo = env.Command (lang + '.mo', lang + '.po',
            "msgfmt --statistics --verbose --strict --check --output=$TARGET $SOURCES");
#    env.Depends (mo, po)
    env.InstallAs (target = install_dir + prefix + '/share/locale/' + lang + '/LC_MESSAGES/glosung.mo',
                  source = lang + '.mo')

if env['PLATFORM'] != 'win32':
	env.Tar (tar_file, ['SConscript',
                    'cs.po',
                    'de.po',
                    'fr.po',
                    'hu.po'])


#import glob

#Import ( 'environment' )

#sourceDirectory = Dir ( '.' ).srcnode ( ).abspath

#poFiles = [ file.replace ( sourceDirectory + '/' , '' ) for file in
#glob.glob ( sourceDirectory + '/*.po' ) ]
#compiledExtension = '.mo'

#for poFile in poFiles :
#    countryCode = poFile[:-3]
#    target = countryCode + compiledExtension
#    environment.Command ( target , poFile , "msgfmt -o $TARGET $SOURCES" )
#    environment.Alias ( 'build' , target )
#    installationDirectory = environment ['GNOMELOCALEDIR'] + '/' + countryCode + '/LC_MESSAGES/'
#    installed = installationDirectory + environment ['NAME'] + compiledExtension
#    environment.Alias ('install' , installed , environment.InstallAs (installed , target))
