gettext and define

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

Moderator: Forum Moderators

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: 19
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 496 times
User avatar
octalot
General Code Maintainer
Posts: 777
Joined: July 17th, 2010, 7:40 pm
Location: Austria

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: 19
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: 506
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
User avatar
chee
Posts: 18
Joined: October 2nd, 2020, 8:30 am

Re: gettext and define

Post by chee »

Hello.
I have created some pots using wmlxgettext (for python3 ver= 2019.09.03.py3) included in the wesnoth package.
Currently, the specification seems to be that the root directory of each addon is scanned last.
However, many of the add-on pots seem to be scanned the root first. (e.g. _main.cfg seems to be scanned first).
Line 9 of autof.py, which comes with the current wmlxgettext, looks like this

Code: Select all

    for root, dirs, files in os.walk(pathdir, topdown=False):
If this last "False" is set to "True", the scan will start from the root.
I am not skilled enough to determine if there is any inconvenience in setting it to True, but if there is not, I would like to change it to True and run it.
Please let me know your opinion.
-------
chee / k.k
User avatar
octalot
General Code Maintainer
Posts: 777
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: gettext and define

Post by octalot »

I understand what you want to change, but not the reason why.

The list returned by autoscan will be sorted afterwards, unless the --no-sort-by-file option is given. The details of that are in #5989, #6322 and #6586.
User avatar
chee
Posts: 18
Joined: October 2nd, 2020, 8:30 am

Re: gettext and define

Post by chee »

octalot wrote: December 21st, 2022, 9:39 am I understand what you want to change, but not the reason why.

The list returned by autoscan will be sorted afterwards, unless the --no-sort-by-file option is given. The details of that are in #5989, #6322 and #6586.
Thank you for the guidance.
I seem to have been running a version of wmlxgettext before that discussion took place.
Using wmlxgetext, which comes with BfW 1.16.6, I have confirmed that the new options had been added. ( "--no-sort-by-file" )

By the way, this string of version would be better updated. It is one of the reasons for my misunderstanding.
Anyway, thank you very much.

Code: Select all

    parser.add_argument(
        '--version',
        action='version',
        version='wmlxgettext 2019.09.03.py3'
-------
chee / k.k
Post Reply