From b121008a746797cc30622ecedead9aeee645964c Mon Sep 17 00:00:00 2001 From: Tomas Stary Date: Mon, 28 Mar 2016 02:04:15 +0100 Subject: [PATCH] Makefiles to create PO and POT translation files --- Makefile | 82 +++++++++++++++++++++++++++++++++++++++++++++++-- Makefile.gen | 33 ++++++++++++++++++++ Makefile.server | 5 +++ 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 Makefile.gen create mode 100644 Makefile.server diff --git a/Makefile b/Makefile index 37a1902d..4e353403 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,80 @@ -devserver: - python -m SimpleHTTPServer +# This is a Makefile to generate the PO files for automated +# translation. If you get through the trouble of creating PO file for +# your language, you will save a lot of hassles with editing plain html +# and repeated text, which also implies potential mistakes. + +# Please read the manual on the page: +# http://dev.man-online.org/man7/po4a/ + +# This Makefile only contains commands from the manual tested for the +# esd translation. + +# After the translation of the PO file has been finished, generate new +# files using: make -f Makefile.gen + +# flags for the po4a-getextize +PO4A_FLAGS=-M utf-8 -f xhtml +# list of source files for the translation +SRC=confirmation.html\ + index.html\ + infographic.html\ + mac.html\ + next_steps.html\ + windows.html\ + workshops.html + +############################################################ +# initialise the po template from English version, this is to be used, +# there is no translation for now, and you are going to build it from +# scratch. Then copy the file esd-temp.pot to your language file +# esd-$(lang).po such as esd-cs.po, and edit it in your favourite PO +# editor (such as poedit, or emacs with po-mode). + +# If you already have an old translation you can convert it to PO +# files as described bellow. +esd-temp.pot: $(foreach f,$(SRC),en/$f) + po4a-gettextize $(PO4A_FLAGS) $(foreach f,$+,-m $f) -p $@ + +############################################################ +# Convert existing translations into PO files. + +# NOTE: You need to make sure that your translated document is formaly +# correct xhtml (there might be accidental mistakes). +# Validate your document to find errors (e.g. https://validator.w3.org) + +# IMPORTANT: when you generate the PO files from the existing +# translation, the original files in the version *corresponding* to +# the translation have to be provided as a command line argument (with +# parameter -m). + +# for that specify the directory where the original files are placed +DIR=en +# and the list of files that were translated within the corresponding +# version +FILES=$(SRC) + +# The generation of the PO file is likely to go wrong, because of the +# mistakes which were introduced by the direct translation of the html +# files. In this case the po4a gives quite good error message with a +# reference in which file and line number to look at to find the +# mistake. Go to that file and try to correct the errors and then +# repeat the procedure. + +# Don't give it up translating PO files is nicer. + +# For more details and troubleshooting see: +# http://dev.man-online.org/man7/po4a/ +# in section: HOWTO convert a pre-existing translation to po4a? +esd-%.po.extract: $(foreach d,$(DIR) %,$(foreach f,$(FILES),$d/$f)) + po4a-gettextize $(PO4A_FLAGS) $(foreach f,$(FILES),-m $(DIR)/$f) $(foreach f,$(FILES),-l $*/$f) -p $@ + cp $@ `basename -s .extract $@` + +############################################################ +# update the PO translation after the original has changed. This will +# make a new PO file automaticaly reusing identical translations, but +# the strings will be made fuzzy and need to verified manualy. Strings +# that changed need to be translated again. +esd-%.po.update: esd-%.po $(foreach f,$(SRC),en/$f) + cp $< $@ + po4a-updatepo $(PO4A_FLAGS) $(foreach f,$(SRC),-m en/$f) -p $@ + cp $@ $< diff --git a/Makefile.gen b/Makefile.gen new file mode 100644 index 00000000..5fa73044 --- /dev/null +++ b/Makefile.gen @@ -0,0 +1,33 @@ +# this Makefile is used to generate the translated html files from the +# PO templates + +# usage: make -f Makefile.gen + +# flags for the po4a-getextize +PO4A_FLAGS=-M utf-8 -f xhtml +# list of source files for the translation +SRC=confirmation.html\ + index.html\ + infographic.html\ + mac.html\ + next_steps.html\ + windows.html\ + workshops.html + +# list of languages that use the PO files (add yours if you migrate to PO) +LANG=cs + +# default target +all: $(foreach l,$(LANG),$(foreach f,$(SRC),$l/$f)) + +# recipes for the individual pages in each language +# Czech +cs/%.html: esd-cs.po $(foreach f,$(SRC),en/$f) + -po4a-translate $(PO4A_FLAGS) -m en/$*.html -p $< -l $@ + +# French +fr/%.html: esd-fr.po $(foreach f,$(SRC),en/$f) + -po4a-translate $(PO4A_FLAGS) -m en/$*.html -p $< -l $@ + +# (copy the recipe for your language if you migrate to PO) + diff --git a/Makefile.server b/Makefile.server new file mode 100644 index 00000000..e4bad73d --- /dev/null +++ b/Makefile.server @@ -0,0 +1,5 @@ +devserver: + python -m SimpleHTTPServer + +devserver2: + python -m http.server --bind localhost 8888 > /dev/null 2>&1 & -- 2.25.1