Re: Lenny upgrade-advisor
- To: Franklin PIAT <fpiat@bigfoot.com>
- Cc: debian-i18n@lists.debian.org
- Subject: Re: Lenny upgrade-advisor
- From: Vincent Danjean <vdanjean.ml@free.fr>
- Date: Tue, 14 Oct 2008 13:12:05 +0200
- Message-id: <[🔎] 48F47E85.3010907@free.fr>
- In-reply-to: <53059.195.182.17.33.1223977628.squirrel@www.klabs.be>
- References: <zSllKuU2.1220948171.5724070.alex@localhost> <1223934762.5077.37.camel@solid.paris.klabs.be> <48F46532.7040103@free.fr> <53059.195.182.17.33.1223977628.squirrel@www.klabs.be>
[I CC to debian-i18n@lists.debian.org in case someone has better
recommendations to do]
Franklin PIAT wrote:
> Vincent,
>
> Vincent Danjean wrote:
>> Franklin PIAT wrote:
>>> I have re-worked upgrade-advisor to make it pluggable.
> [..]
>>> + Testing/Feedback is welcome
>> Did you consider i18n ?
>> gettext exists as a shell program (and you can easily provide
>> a function that does nothing in case gettext is not installed)
>
> Do you know any package that use this feature ?
> That would help me implement it the right way.
I use this kind of thing for a website in SPIP (mix of HTML, php and
pseudo-HTML language). There is two parts to consider:
1) extract original text to create the POT file
2) use gettext to get the correct translation
Of cause, between 1 and 2, you have to translate, compile translations (po->mo)
install translations in the correct place, ... but all of this is very standard.
In the po/ directory of my website, I have:
======
all:
@echo "use 'make file.po' to update the po file from the pot file if needed"
%.po: LIG-spip.pot
msgmerge --verbose --update $@ $<
touch $@
update: $(wildcard *.po)
======
And in the main Makefile (in ./):
======
GETTEXT_DOMAIN=Project_name
LANGAGES=fr de
locale/%/LC_MESSAGES/$(GETTEXT_DOMAIN).mo: po/%.po
mkdir -p locale/$*/LC_MESSAGES
msgfmt --check -D po --output-file=$@ $*.po
translations: po/$(GETTEXT_DOMAIN).pot $(foreach lang,$(LANGAGES),locale/$(lang)/LC_MESSAGES/$(GETTEXT_DOMAIN).mo)
po/$(GETTEXT_DOMAIN).pot: [All source files]
complex scripts to extract info in a pot file as gettext does not know SPIP dialect
======
As shell scripts are managed by xgettext, I think that a simple command
to create the pot file should be enough. Something as (not tested):
XGETTEXT=xgettext \
--msgid-bugs-address=project@email \
--from-code=UTF-8 \
--copyright-holder=PROJECT_NAME \
--sort-by-file
po/$(GETTEXT_DOMAIN).pot: [all script files]
$(XGETTEXT) --output-dir=po --default-domain $(GETTEXT_DOMAIN) --language Shell $^
sed -i po/$(GETTEXT_DOMAIN).po -e 's,^"Content-Type: text/plain; charset=CHARSET\\n"$$,"Content-Type: text/plain; charset=UTF-8\\n",'
@if test -f $@ ; then \
REP="$$(grep '^"POT-Creation-Date: [0-9 :+-]*\\n"$$' $@ | sed -e 's/\\/\\\\/g' )" ; \
sed -i po/$(GETTEXT_DOMAIN).po -e 's,^"POT-Creation-Date: [0-9 :+-]*\\n"$$,'"$$REP"',' ; \
fi
@REP="$$(grep '^"POT-Creation-Date: [0-9 :+-]*\\n"$$' po/$(GETTEXT_DOMAIN).po | sed -e 's/\\/\\\\/g' )" ; \
if ! diff -u $@ po/$(GETTEXT_DOMAIN).po ; then \
mv po/$(GETTEXT_DOMAIN).po $@ ;\
sed -i $@ -e 's,^"POT-Creation-Date: [0-9 :+-]*\\n"$$,'$$REP',' ;\
echo "********************" ;\
echo "$@ has been modified. Translations probably need to be updated" ; \
echo "********************" ;\
$(MAKE) -C po update ;\
else \
mv po/$(GETTEXT_DOMAIN).po $@ ;\
fi
Note that all file manipulation to avoid to change the file if it is the
same (but the date) is perhaps due to #496282 (now fixed in testing but I did not recheck
my Makefiles (and they must work on older system anyway))
Of course, in your scripts, you need to call gettext. Some idea (not tested at all):
======
MYGETTEXT=''
# This function must be called 'gettext'
# so that xgettext find the string to translate
gettext() {
if test -n "MYGETTEXT"; then
if test -x "$(which gettext)" ; then
MYGETTEXT="$(which gettext) -d Project_name -s"
else
MYGETTEXT="echo"
fi
fi
$MYGETTEXT "$1"
}
# gettext is a replacement for echo
gettext coucou
BASEDIR=www.debian.org
#Wrong: $BASEDIR never interpreted by the shell
ARG="$(gettext '$BASEDIR/file.en.html')"
echo "$ARG"
#Wrong: $BASEDIR interpreted before gettext called
#but xgettext cannot extract it:
ARG="$(gettext "$BASEDIR/file.en.html")"
echo "$ARG"
#Right: $BASEDIR not interpreted before gettext called but after (translators
#must keep $BASEDIR in their translation)
#xgettext can extract the message:
ARG="$(eval echo "$(gettext '$BASEDIR/file.en.html')")"
echo "$ARG"
======
Regards,
Vincent
> Thanks
>
> Franklin
>
--
Vincent Danjean Adresse: Laboratoire d'Informatique de Grenoble
Téléphone: +33 4 76 61 20 11 ENSIMAG - antenne de Montbonnot
Fax: +33 4 76 61 20 99 ZIRST 51, avenue Jean Kuntzmann
Email: Vincent.Danjean@imag.fr 38330 Montbonnot Saint Martin
Reply to: