gettext and define

Discuss and coordinate development of mainline and user-made content translations.

Moderators: Forum Moderators, Developers

Post Reply
Atanase
Posts: 7
Joined: June 17th, 2019, 1:50 pm
Location: Béarn (France)

gettext and define

Post by Atanase »

Hello,

I don't know if I am in the good subject. If not, thank you to move this post.

I am trying to translate a user's campaign. I use PoEdit and wmlxgettext, like everybody, to prepare my .pot file. But.......
Many unit's definitions use many "#define" and, if the opening tag [unit_type] is in the unit's file, the closing tags [/unit_type] is in the include. So wmlxgettext refuse to give me the original messages and stop on error, doing nothing.

I think that I am not the first to have this kind of problem.

Is somebody knowing a "pre-processor" which could give me a "result file" with the #define included ? Maybe a part of the official loader of the game ?

As I did not write programs from very long time, maybe 10 or 15 years, if I try to write it I will loose at least 2 or 3 weeks.

As may grand-mother said : Better 1 who knows than 2 who search. ;)

Thank you for your help.
Celui qui dans la vie, est parti de zéro pour n'arriver à rien dans l'existence n'a de merci à dire à personne.
Pierre Dac
oooo
Posts: 8
Joined: May 14th, 2014, 12:58 pm
Location: Japan

Re: gettext and define

Post by oooo »

I immediately noticed your problem when I read this subject ;)

I had suspected that the current version of wmlxgettext cannot handle WML sources which have some macros, same as the old perl version.

I'm not sure this is what you want, but I have a modified wmlxgettext. Its original version was included in 1.12.1, and written by perl.

I simply modified it to ignore errors. Maybe I also corrected some problems but I don't remember them.

It can create a pot file of LotI.
Attachments
wmlxgettext.zip
(3.9 KiB) Downloaded 197 times
User avatar
octalot
Developer
Posts: 494
Joined: July 17th, 2010, 7:40 pm

Re: gettext and define

Post by octalot »

Atanase wrote:
June 18th, 2019, 9:25 am
Is somebody knowing a "pre-processor" which could give me a "result file" with the #define included ? Maybe a part of the official loader of the game ?
Method 1: Use the --preprocess option to wesnoth, for example to output to a directory called "temp"

Code: Select all

wesnoth --preprocess Defense_of_Elensefar temp --preprocess-defines CAMPAIGN_DEFENSE_OF_ELENSEFAR,HARD
Method 2: If you have a search program that can search compressed files, there is a preprocessed version in Wesnoth's cache directory, but you'll need a search program to find out which file is yours. If the campaign has multiple difficulties there then will be one per difficulty, note that these are only created when you play on that difficulty.
Atanase
Posts: 7
Joined: June 17th, 2019, 1:50 pm
Location: Béarn (France)

Re: gettext and define

Post by Atanase »

Hello,

Thank you for your answers and also for your speed. ;)

I will try the two methods.

The oooo method seems good to see what must be done to play.
The octalot methods better to see what is really done when you play.
Celui qui dans la vie, est parti de zéro pour n'arriver à rien dans l'existence n'a de merci à dire à personne.
Pierre Dac
Atanase
Posts: 7
Joined: June 17th, 2019, 1:50 pm
Location: Béarn (France)

Re: gettext and define

Post by Atanase »

Hello,

Last news from the front :

The wmlxgettext from oooo work very fine. But...... Not for the lua files. :lol:

So I used the new to create a "special" file and merged it with the main.

Now I hope that I have really ALL the sentences.

Have a good night.
Celui qui dans la vie, est parti de zéro pour n'arriver à rien dans l'existence n'a de merci à dire à personne.
Pierre Dac
oooo
Posts: 8
Joined: May 14th, 2014, 12:58 pm
Location: Japan

Re: gettext and define

Post by oooo »

Atanase wrote:
June 18th, 2019, 9:20 pm
The wmlxgettext from oooo work very fine. But...... Not for the lua files. :lol:
Uhm, It seems to work fine to me, but I'm not quite sure because I recently don't play LotI.

I use the wmlxgettext with following command line which specifies all cfg and lua files explicitly.

Code: Select all

wmlxgettext --directory $DIR --domain $DOM --initialdomain $DOM `cd $DIR && find -name '*.cfg' -o -name '*.lua' | sort`
Atanase
Posts: 7
Joined: June 17th, 2019, 1:50 pm
Location: Béarn (France)

Re: gettext and define

Post by Atanase »

Hello,

No matter, I wrote a little shell script (only 4 lines with the #! /bin/sh) with a 'msgcat' and all is done.

It was just a ;)

Thank you again for your help.

Have a good day or night wherever you are.
Celui qui dans la vie, est parti de zéro pour n'arriver à rien dans l'existence n'a de merci à dire à personne.
Pierre Dac
User avatar
Nobun
Code Contributor
Posts: 129
Joined: May 4th, 2009, 9:28 pm
Location: Italy

Re: gettext and define

Post by Nobun »

Sorry, I am very late since I am not used to read a lot the wesnoth forum. I am the main developer and mantainer of the python wmlxgettex.

Wmlxgettext cannot parse macros.
Wmlxgettext reads WML and lua through regular expressions. This means that implementing a macro parser inside the code is very hard, error-prone and can introduce bugs. So I drop out the idea of parsing Macros.
Many unit's definitions use many "#define" and, if the opening tag [unit_type] is in the unit's file, the closing tags [/unit_type] is in the include. So wmlxgettext refuse to give me the original messages and stop on error, doing nothing.
This is absolutely normal. When the tag is closed inside a macro, the issue can be solved using a dedicated comment # wmlxgettext

Code: Select all

# wmlxgettext: [/unit_type]
The commented [/unit_type] will be parsed by wmlxgettext like an actual closing tag thank of the magic world "wmlxgettext" which will say that the following text must be parsed like an actual WML code. So, in your use case, you could write a code like this one:

Code: Select all

[unit_type]
{MY_MACRO_WHICH_CONTAIN_CLOSING_TAG}
# wmlxgettext: [/unit_type]
Here the doc page about the "# wmlxgettext" special comment, for a deeper explaination (in the example showed by the docs there is a closing tag without an opening one. In your situation you will simply apply the opposite case, but the logic is the same).

Ignoring errors, instead, is a bad solution. You can introduce issues that are not immediately visible which possibly makes your .pot file bugged (if not completely wrong and not working). So I would highly discourage to use that custom edit of perl wmlxgettext posted before, where error checking was eradicated.

I would suggest you to read the Wmlxgettext Documentation for End-Users which can clarify a lot of doubts, including this one. However if you have other questions or doubts related to wmlxgettext usage you can ask here and I will be happy to answer.
Diplounc
Posts: 2
Joined: August 3rd, 2020, 7:48 pm

Re: gettext and define

Post by Diplounc »

Hi, do you know if by changing the po files and re building the game, those changes will be added to the game? For examples if we add translations that are missing in One language, thanks a lot for any advice!
User avatar
GunChleoc
Translator
Posts: 497
Joined: September 28th, 2012, 7:35 am
Contact:

Re: gettext and define

Post by GunChleoc »

It should. Alternatively, you can use a tool like PoEdit or Virtaal to generate an mo file and stick it in the correct directory.

See https://wiki.wesnoth.org/GettextForTranslators
Post Reply