:: Re: [DNG] Hopman, more configuratio…
Top Page
Delete this message
Reply to this message
Author: aitor_czr
Date:  
To: dng
Subject: Re: [DNG] Hopman, more configuration
H Didier,

On 4/5/19 13:18, Didier Kryn wrote:

>> Hi all, in particular Steve and Aitor who have tested the program.
>>
>>     Two new boolean parameters are now recognised in the config file:
>>
>>     Decorate = True means the window has border, title and buttons,
>> False means it has none of these.
>>
>>     Autohide = True means the window is automatically hidden when
>> there isn't any hotplug device; False means it remains visible.
>>
>>     Sending the signal SIGHUP now toggles the visibility of the window.
>>
>>         Didier


For testing the translations of your hopman project add the following
headers in the GTK2/hopman.c main function:

    #include <libintl.h>
    #include <locale.h>

You also need to add the following macro in those files containing
translations:

    #define _(STRING) gettext(STRING)

so that, you can use something like this in the begining of the
GTK"/hopman.c:

    setlocale (LC_ALL, "");
    bindtextdomain ("hopman", "/usr/share/locale");
    textdomain ("hopman");

    printf( _("Starting hopman...\n") );

The bindtextdomain function uses the following format:

bindtextdomain (const char *domain_name, const char *dir_name);

and the translations will be found in the
$dir_name/locale/$lang/LC_MESSAGES/project_name.mo,
once you have installed the application; otherwise, the directory should
be the po/ folder.
(have a look at your "/usr/share/locale/fr/LC_MESSAGES/" directory)

Lets create the template.pot file (we are located in the hotman/ directory):

$> xgettext --keyword=_ --language=C --add-comments --sort-output \
-o po/template.pot  \
annex/*.c GTK2/*.c watch/*.c \
annex/*.h GTK2/*.h watch/*.h hopman.h

A po/hello.pot template is created and should look like this:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-04 14:39+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@???>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: GTK2/hopman.c:46 GTK2/hopman.c:47
#, c-format
msgid "Starting hopman...\n"
msgstr ""


Now you can customize a bit the header of this template by replacing a
few default by proper values
of Project-Id-Version, Report-Msgid-Bugs-To, the charset, the first
author, etc...

So, now we have full template to start with, we can start to work on a
translation for this program.
Lets start with a French translation of it. We need to create a file
po/fr.po extracted from the template.

$> msginit --input=po/template.pot --locale=fr --output=po/fr.po

Have a look at the generated po/fr.po file and write the pertinent
translations in the msgstr "" lines.

You can test the program by the following way:

$> LANG=fr_FR ./GTK2/hopman

The new Makefile will update automatically the translations:

#     Copyright (C) 2019 Didier Kryn <kryn@???> -- See LICENSE
# 'make'           builds the executable
# 'make clean'     removes object files, keeps libraries and executable
# 'make install'   installs executable, default config file, icon and
launcher
# 'make cleanall'  removes everything but source files and installed files
# 'make uninstall' removes installed files
# You must be root to make install/uninstall

SWATCH_FUNC = `find swatch -name "*.c"``find swatch -name "*.h"`
ANNEX_FUNC = `find annex -name "*.c"``find annex -name "*.h"`
UI_FUNC_GTK2 = `find GTK2 -name "*.c"``find GTK2 -name "*.h"`

TRANSLATED_FILES=`find . -name "*.c"``find . -name "*.h"`
POFILES=`find po -name "*.po"`

INSTALLED_FILES = /usr/bin/hopman /usr/share/man/man8/hopman.8.gz \
/etc/default/hopmanrc /usr/share/pixmaps/hopman.png \
/usr/share/applications/hopman.desktop /usr/share/doc/hopman/copyright

.SUFFIXES:

all: GTK2/hopman

GTK2/hopman: $(UI_FUNC_GTK2) \
    watch/watch.a annex/annex.a
    make -C GTK2 hopman

po/*.mo: po/*.po
    msgfmt --output-file=$@ $<

po/*.po: po/*.pot
    msgmerge --update $@ $<

po/template.pot: $(TRANSLATED_FILES)
    xgettext -k_ -j -lC -c -s -o po/template.pot $(TRANSLATED_FILES)

watch/watch.a: $(WATCH_FUNC)
    make -C watch watch.a

annex/annex.a: $(ANNEX_FUNC)
    make -C annex annex.a

/usr/bin/hopman: GTK2/hopman
    cp $< $@

/usr/share/man/man8/hopman.8.gz: doc/man/man8/hopman
    gzip -c  $<   > $@

/etc/default/hopmanrc: annex/hopmanrc
    cp  $<  $@

/usr/share/pixmaps/hopman.png: icon/removable-media-32x32.png
    cp $<  $@

/usr/share/applications/hopman.desktop: hopman.desktop
    cp $<  $@

/usr/share/doc/hopman/copyright: LICENSE /usr/share/doc/hopman
    cp $<  $@

/usr/share/doc/hopman:
    mkdir $@

clean:
    make -C watch clean
    make -C annex clean
    make -C GTK2 clean
    @rm -vf $(wildcard doc/man/man8/*~)
    @rm -vf $(wildcard *~)

cleanall:
    make -C watch cleanall
    make -C annex cleanall
    make -C GTK2 cleanall
    @rm -vf $(wildcard doc/man/man8/*~)
    @rm -vf $(wildcard *~)

install: $(INSTALLED_FILES)
    for cat in $(POFILES); do \
      cat=`echo $${cat%.*}`; \
      lang=`echo $${cat#*/}`; \
      cp -av $$cat /usr/share/locale/$$lang/LC_MESSAGES/hopman.mo; \
    done

uninstall:
    @rm -vf $(INSTALLED_FILES)
    @rm -rvf /usr/share/doc/hopman
    for cat in $(POFILES); do \
      cat=`echo $$cat | sed 's/\.po$$//'`; \
      lang=`echo $$cat | cut -d "/" -f2`; \
      rm -f /usr/share/locale/$$lang/LC_MESSAGES/hopman.mo; \
    done

.PHONY: clean cleanall uninstall

Thanks for your attention,

Aitor.