The source layout should conform to the one described in
gettext documentation. In particular, it should
contain a po
directory. There should be in this directory :
a file LINGUAS
describing available translations,
a file POTFILES
containing the listing of all files that
contain translatable strings,
a Makefile
to build the whole thing,
a set of PO file which contains translated strings for different languages.
During the build, the Makefile
should generate a file
your-domain.pot
that contains a template PO file that can be used
by translator.
Example 3.1. Makefile
for po
########################################################################## # Ocaml-gettext : example code # # # # Copyright (C) 2003, 2004, 2005 Sylvain Le Gall <sylvain@le-gall.net> # # # # You can redistribute this library and/or modify it under the terms of # # the GNU LGPL v2.1 with the OCaml static compilation exception. # # # # Contact: sylvain@le-gall.net # ########################################################################## OCAML_GETTEXT_PACKAGE = mydomain LINGUAS=$(shell cat LINGUAS) SOURCES=POTFILES OCAML_GETTEXT=ocaml-gettext OCAML_GETTEXT_EXTRACT_OPTIONS= OCAML_GETTEXT_COMPILE_OPTIONS= OCAML_GETTEXT_INSTALL_OPTIONS= OCAML_GETTEXT_MERGE_OPTIONS= BUILDPO=../build/share/locale/ POFILES=$(addsuffix .po,$(LINGUAS)) MOFILES=$(addsuffix .mo,$(LINGUAS)) POTFILE=$(OCAML_GETTEXT_PACKAGE).pot all: install-buildpo install: install-po uninstall: uninstall-po clean:: clean-po %.mo: %.po $(OCAML_GETTEXT) --action compile $(OCAML_GETTEXT_COMPILE_OPTIONS) \ --compile-output $@ $^ %.pot: $(SOURCES) $(OCAML_GETTEXT) --action extract $(OCAML_GETTEXT_EXTRACT_OPTIONS) \ --extract-pot $@ $^ %.po: $(POTFILE) $(OCAML_GETTEXT) --action merge $(OCAML_GETTEXT_MERGE_OPTIONS) \ --merge-pot $(POTFILE) $@ $(BUILDPO): mkdir -p $(BUILDPO) .PRECIOUS: $(POTFILE) install-buildpo: $(MOFILES) $(BUILDPO) $(OCAML_GETTEXT) --action install $(OCAML_GETTEXT_INSTALL_OPTIONS) \ --install-textdomain $(OCAML_GETTEXT_PACKAGE) \ --install-destdir $(BUILDPO) $(MOFILES) install-po: $(MOFILES) $(OCAML_GETTEXT) --action install $(OCAML_GETTEXT_INSTALL_OPTIONS) \ --install-textdomain $(OCAML_GETTEXT_PACKAGE) \ --install-destdir $(PODIR) $(MOFILES) uninstall-po: $(OCAML_GETTEXT) --action uninstall $(OCAML_GETTEXT_INSTALL_OPTIONS) \ --uninstall-textdomain $(OCAML_GETTEXT_PACKAGE) \ --uninstall-orgdir $(PODIR) $(MOFILES) clean-po: -$(OCAML_GETTEXT) --action uninstall $(OCAML_GETTEXT_INSTALL_OPTIONS) \ --uninstall-textdomain $(OCAML_GETTEXT_PACKAGE) \ --uninstall-orgdir $(BUILDPO) $(MOFILES) -$(RM) $(MOFILES)
To build programs and libraries with ocaml-gettext, the preferred way is to use ocamlfind. There are five findlib packages:
gettext.base: the base package of ocaml-gettext. It contains the top level type required to compile any library,
gettext.extension
[5]
: a package used to extend ocaml-gettext. It is reserved for very
particular functions ( such as creating a new realize
function ),
gettext.extract[5]: a package that enables to create special camlp4 program ( such as ocaml-xgettext ),
gettext-stub: an implementation of ocaml-gettext using gettext,
gettext-camomile: an implementation of ocaml-gettext using camomile. It is a pure ocaml implementation.
In order to link an application or a library using ocaml-gettext, you should link with one of : gettext.base, gettext-camomile or gettext-stub.
Example 3.4. Makefile
########################################################################## # Ocaml-gettext : example code # # # # Copyright (C) 2003, 2004, 2005 Sylvain Le Gall <sylvain@le-gall.net> # # # # You can redistribute this library and/or modify it under the terms of # # the GNU LGPL v2.1 with the OCaml static compilation exception. # # # # Contact: sylvain@le-gall.net # ########################################################################## all: program clean: $(RM) *.cmi *.cmo program program: programGettext.ml program.ml ocamlfind ocamlc -package "gettext-camomile lablgtk2.init" -linkpkg \ -I ../library -I ../gui -o $@ library.cma gui.cma $^
[5] This feature is described here for your information only. Since it belongs to low level implementation of ocaml-gettext, it should not be used.