Use of #define statements with translatable strings

Christian Stimming christian at cstimming.de
Sun Mar 31 17:41:02 EDT 2013


Am Sonntag, 31. März 2013, 14:22:24 schrieb Alex Aycinena:
> 
> #define CUT_TRANSACTION_LABEL         N_("Cu_t Transaction")
> #define COPY_TRANSACTION_LABEL        N_("_Copy Transaction")
> ...
> #define CUT_SPLIT_LABEL               N_("Cu_t Split")
> #define COPY_SPLIT_LABEL              N_("_Copy Split")
> ...
> 
> 
> Can anyone help me out here? I'm not sure how to proceed.

For the translation to work, two steps need to work correctly:

1. The strings must be marked in the source for extraction by the external 
tool "xgettext", which copies them from the *.c files to the *.po files (with 
gnucash.pot as intermediate template). This is a compile-time step.

2. At runtime, the English strings must be passed through the function 
gettext( ).

To get a string to be extracted (step #1), you must mark the strings by any of 
the macros mentioned in the gettext documentation - either N_( ), or _( ), or 
S_( ) or whatever other macro exists. However, the macro must go around the 
real string, not around any macro names. In your case, this is done correctly.

To get a string to be passed through gettext( ) at runtime, the strings can 
either be enclosed by _( ), which expands at compile time to a call to 
gettext( ). Alternatively, the const char* pointers from the strings can be 
passed through gettext( ) or _( ) manually at some later point.

In your case, I don't know where you're using those macros. If they are used 
in a place where the strings are expected in already translated form, N_( ) 
was wrong and you need to use _( ) instead. Alternatively, you can also use 
_(CUT_SPLIT_LABEL) in the places where you need the translated string, and 
CUT_SPLIT_LABEL where you need the not-yet-translated static string. Depends 
on the context.

Regards,

Christian



More information about the gnucash-devel mailing list