[erlang-questions] erlang-gttext only looking for ?TXT macros?

Dmitrii Dimandt dmitriid@REDACTED
Tue May 12 16:14:09 CEST 2009


On May 12, 2009, at 1:47 PM, Torbjorn Tornkvist wrote:

> Dmitrii Dimandt wrote:
>> This is a very strange behavior I've observed in gettext.
>>
>> From the tutorial:
>> In order to create the initial PO file, run the Makefile in the
>> directory, that the directories that should be processed, i.e where
>> there are code containing ?TXT macros.
>>
>> And that's all gettext processes — ?TXT macros. Does it mean that I
>> have to only use ?TXT macros and then go through the code and change
>> them to ?TXT2, ?FTXT etc manually?
>
> Well, the ?TXT macros (and friends) expands into a call to
> gettext:key2str/N which then the parse_transform looks for
> and uses to extract the string.
>
> All strings are collected into a temporary dets table.
> When all files has been processed, the dets table is traveresed
> and a PO-file is produced. This PO-file, which contains your
> strings in your default language, is then intended to be translated.
>
> The actual processing can be controlled via your Makefiles by setting
> up the correct evironment variables, removing the necessarey beam  
> files
> and recompile your code.
>
> I guess you are using the jungerl version ?
>

I believe I got downloaded the version from here:
http://github.com/noss/erlang-gettext/tree/master


Actually i got to the matter of things in a way. I guess my mail got  
lost on the way (or I hit Reply instead of Reply all :) ):

Here's a repost:

-- start quote --

Ok, I've gotten to the bottom of this. Sort of...

?TXT2("other string", "en")

turns into something like

{call,39,
               {remote,39,{atom,39,gettext},{atom,39,key2str}},
               [{string,39,"other string"},{string,39,"en"}]}

which somehow doesn't get matched by pt/3 in gettext_compile.erl

Weird...

This is an ad-hoc solution that will definitely fail somewhere down  
the road.

In gettext_compile.erl find the following function:

pt([H|T], Opts, Func) when is_tuple(H) ->
    ?debug( "--- 3 --- ~p~n",[H]),
    [while(size(H), H, Opts, Func) | pt(T, Opts, Func)];

change it to:

pt([H|T], Opts, Func) when is_tuple(H) ->
    ?debug( "--- 3 --- ~p~n",[H]),
	case H of
		{call, _, _, _} ->
			[pt(H, Opts, Func) | pt(T, Opts, Func)];
		_ ->
			[while(size(H), H, Opts, Func) | pt(T, Opts, Func)]
	end;

This way pt/3 will not miss the function call to key2str/2. Hopefully...

-- end quote --


After these modifications I got erlang-gettext to generate the  
initial .po file.


> Perhaps I should upload the version we are using (at Kreditor) to
> github? (I strongly prefer github nowadays)
>

Hmm.. If it differs significantly from jungerl version, it would be  
nice to have a look at it :)



> --Tobbe
>
>>
>> Is there a way to make erlang_gettext process these macros as well?
>>
>> BTW. To all those working with erlang_gettext source code. Put this
>> line before to_list functions in gettext_compile module:
>>
>> to_list({Module, _Parameters}) -> atom_to_list(Module);
>>
>> This will handle parametrised modules declared as
>> -module(some_module, [Param])
>>
>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list