xgettext - extract translatable strings and update .pot - c++

I have inherited a sample.pot file. Now, I have added new messages in a1.c and a2.cpp. Is it possible for me to use xgettext and output the contents to same sample.pot instead of creating a new one? Eg:-
xgettext -d sample -s -o sample.pot a1.c
xgettext -d sample -s -o sample.pot a2.cpp
Is this preferred way to go in order to update the template such that old messages are also preserved? The other question is how do we distinguish translatable strings from normal strings in source code. I assume xgettext will pull all strings from mentioned source code file.
It would be great if anybody can share the correct approach..Thanks

Does the -j, --join-existing option ("join messages with existing file") not do what you need?
Note that you can specify more than one input file on the command line.
xgettext -d sample -s -j -o sample.pot a1.c a2.cpp

The simplest way to achieve this is:
xgettext -o sample.pot -s a1.c a2.cpp sample.pot
You don't need -j, --join-existing because xgettext accepts .po and .pot files as regular input files.
The option -j, --join-existing is rarely useful. In conjunction with -D, --directory it has the effect that the output file sample.pot used as an input file is not searched in the list of directories. If you use -l c, --language=c you need -j, --join-existing because sample.pot would otherwise be parsed as a C/C++ source file.
Besides, -o sample.pot, --output=sample.pot has exactly the same effect as -d sample, --default-domain=sample. You can safely omit one of them.

Related

CPP -D option for preprocessing of Fortran codes

I am trying to understand a makefile in which a Fortran code is used with cpp for preprocessing in the following manner,
cpp -P -traditional -DMPI -DLINUX -DX86_64 -DGFORTRAN -D'HEADER="testfile.h"' -D'ROOT_DIR="/home/Desktop"'...-D'FILE_DIR="/home/Desktop/MYFILES"' -I/usr/local/include file.F
I understood the usage of include directory but I am unable to understand the purpose of -D options (named as CPPFLAGS) listed here. I see that if I remove any of the -D option, my output is modified (I get only start and end of my program and no text in between).
Edit: I have a list of ifdef options and my makefile uses different subdirectories with -D option. What is it looking in those directories, Files in which the option is defined?
If I understand you correctly, you just want to figure out the meaning of -D.
gcc -D defines a macro to be used by the preprocessor.
the syntax is below:
$ gcc -Dname [options] [source files] [-o output file]
$ gcc -Dname=definition [options] [source files] [-o output file]
If you remove any -D, it means this macro isn't defined. So your output might be changed.

How can make my makefile overwrite a file?

descript: progam.cpp
g++ progam.cpp -o descript
./descript 2>output.txt | tee -a output.txt
From my understanding, first command compiles program.cpp and the second command sends the output to both terminal and a textfile.
Is there a way to adjust this so that I :
Use "make".Go through program prompts. Output is saved in output.txt
Use "./descript" or some command a second time and overwrite output.txt with new output
I'm fairly new to linux commands in general so anything would help.
It may be helpful to include a make clean function in your Makefile.
Example make clean function could include:
make clean:
rm -f output.txt
Then, insert the make clean at the beginning of your descript portion of the Makefile to auto-remove the previous output.

combining camlp4 and camlp5 in -pp string for ocamlopt?

I want to combine BOLT, SEXP and ocamlViz for a large project. The problem is, that SEXP and BOLT are using CamlP4 and ocamlviz is using camlp5. But how could I combine the calls to one chain for the -pp argument of ocamlc/ocamlopt?
Here is my call for actual project without ocamlviz:
ocamlopt.opt -c -I +dynlink -I +bolt -I +threads -I +lablgtk2 -I +extlib -I +pcre -I +netsys -I +netstring -I +json-wheel -I +num -I +nums -I +sexplib -I +zip -I +xml-light -I +xmlrpc-light -I +equeue -I +netclient -g -annot -p -thread -pp 'camlp4o /usr/lib/ocaml/bolt/bolt_pp.cmo -logger '\''foo.native'\'' -level DEBUG -- -I /usr/lib/ocaml/sexplib -I /usr/lib/ocaml/type-conv pa_type_conv.cmo pa_sexp_conv.cmo' -o foo.cmx foo.ml
It is impossible to preprocess source file by two different preprocessors simultaneously for obvious reasons, and using one after another is also impossible because the first one will not recognize the syntax intended for the second one. The solution is either to use different syntaxes in different source files or port ocamlviz to camlp4.
If you pass -printer OCaml to Camlp4, it will output the pre-processed O'Caml file in source format. You can then parse this file again with Camlp5 in another step.

difference between -h <name> and -o <outputfile> options in cc (C++)

I am building .so library and was wondering - what is the difference b/w -h and -o cc complier option (using the Sun Studio C++) ?
Aren't they are referring to the same thing - the name of the output file?
-o is the name of the file that will be written to disk by the compiler
-h is the name that will be recorded in ELF binaries that link against this file.
One common use is to provide library minor version numbers. For instance, if
you're creating the shared library libfoo, you might do:
cc -o libfoo.so.1.0 -h libfoo.so.1 *.o
ln -s libfoo.so.1.0 libfoo.so.1
ln -s libfoo.so libfoo.so.1
Then if you compile your hello world app and link against it with
cc -o hello -lfoo
the elf binary for hello will record a NEEDED entry for libfoo.so.1 (which you can
see by running elfdump -d hello ).
Then when you need to add new functions later, you could change the -o value to
libfoo.so.1.1 but leave the -h at libfoo.so.1 - all the programs you already built
with 1.0 still try to load libfoo.so.1 at runtime, so continue to work without being
rebuilt, but you'll see via ls that it's 1.1.
This is also sometimes used when building libraries in the same directory they're
used at runtime, if you don't have a separate installation directory or install
via a packaging system. To avoid crashing programs that are running when you
overwrite the library binary, and to avoid programs not being able to start when
you're in the middle of building, some Makefiles will do:
cc -o libfoo.so.1.new -h libfoo.so.1 *.o
rm libfoo.so.1 ; mv libfoo.so.1.new libfoo.so.1
(Makefiles built by the old Imake makefile generator from X commonly do this.)
They are referring to different names. Specifically, the -o option is the file's actual name - the one on the filesystem. The -h option sets the internal DT_SONAME in the final object file. This is the name by which the shared object is referenced internally by other modules. I believe it's the name that you also see when you run ldd on objects that link to it.
The -o option will name the output file while the -h option will set an intrinsic name inside the library. This intrinsic name has precedence over the file name when used by the dynamic loader and allows it to use predefined rules to peek the right library.
You can see what intrinsic name was recorded into a given library with that command:
elfdump -d xxx.so | grep SONAME
Have a look here for details:
http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter4-97194.html

Is there way to create empty .mo file template?

Is there way of creating empty .mo file? Usually when starting new project I get stuck with this when there's no need for translations yet.
I tried this with no luck:
msgfmt /dev/null --output-file foo.mo
Got it.
xgettext --force-po -f /dev/null -o foo.po
msgfmt foo.po --output-file foo.mo