Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wmlxgettext does not recognize plural strings in some contexts #3469

Closed
CelticMinstrel opened this issue Aug 16, 2018 · 6 comments
Closed

wmlxgettext does not recognize plural strings in some contexts #3469

CelticMinstrel opened this issue Aug 16, 2018 · 6 comments
Labels
Bug Issues involving unexpected behavior. Low Priority Issues that will cause no meaningful problems if left unaddressed. WML Tools Issues involving WML maintenance tools.
Milestone

Comments

@CelticMinstrel
Copy link
Member

I had a line similar to the following:

local var = wesnoth.format(_("one thing","$count things",count), {count = count})

When I ran wmlxgettext, the string was not gathered. Adding a space before the underscore allowed wmlxgettext to recognize it.

@CelticMinstrel CelticMinstrel added Bug Issues involving unexpected behavior. WML Tools Issues involving WML maintenance tools. Low Priority Issues that will cause no meaningful problems if left unaddressed. labels Aug 16, 2018
@AncientLich
Copy link
Contributor

AncientLich commented Aug 17, 2018

It was intentional that wmlxgettext requires a space before the underscore (_), but I never figured this particular usage case.

The explaination why wmlxgettext can't recognize it without space:
The underscore symbol could be a part of a variable name (example: variable_name, var_) and I also though that sytuations like
something_ ("one thing", "$count things",count)
shouldn't be recognized as a valid translatable string

since wmlxgettext uses regular expressions in order to parse lua/wml code it is necessary to define some clear rules in order to avoid possible unwanted behaviors.

So... what should I consider a valid translatable, other than
_ at the beginning of the line
_ preceded by space and other things (like: something = _ "translatable string")
also
[ I figure: _ preceded by parenthesis and other things.... like something(_ "translatable string") ]
other cases?

@CelticMinstrel
Copy link
Member Author

You could just say _ at the beginning of a line or preceded by [^a-zA-Z0-9], couldn't you? That said, the cases you listed are probably enough (I doubt people would use translatable strings as a table key, so no need to account for square brackets).

@jostephd
Copy link
Member

I think you want to exclude not A-Za-z0-9 but A-Za-z0-9_. You can also do r'\b_\b' to match _ only as a whole word.

@AncientLich
Copy link
Contributor

boundaries seems a very good suggestion. It would make the current regex also simplier, I will follow your suggestion (testing if regex will create or not new bugs... since the regex chain is complex a test is always mandatory before committing any change)

@CelticMinstrel
Copy link
Member Author

By the way, while I have your attention @AncientLich - is it correct that all the wmlxgettext code (apart from the main file) is gathered into that single pywmlx directory?

@AncientLich
Copy link
Contributor

Exactly. pywmlx directory contains all the code of wmlxgettext (imported in main file with 'import pywmlx').
The reason of this choice is that, splitting code in more files with a specific target can make easier to fix or improve the code.

Note:
Committed bugfix (very short change): #3481
I did some test and it seems it works fine. You are welcome to test it too :)

sevu pushed a commit that referenced this issue Sep 9, 2018
…text (#3481)

* bugfix: #3469

* wmlxgettext: removed a debug comment forgotten on the previous bugfix

[ci skip]
@sevu sevu added this to the 1.14.5 milestone Sep 14, 2018
jostephd pushed a commit to jostephd/wesnoth that referenced this issue Oct 6, 2018
…ome context (wesnoth#3481)

* bugfix: wesnoth#3469

* wmlxgettext: removed a debug comment forgotten on the previous bugfix
jostephd pushed a commit to jostephd/wesnoth that referenced this issue Oct 7, 2018
…ome context (wesnoth#3481)

* bugfix: wesnoth#3469

* wmlxgettext: removed a debug comment forgotten on the previous bugfix

(cherry-picked from commit 4b79c26)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues involving unexpected behavior. Low Priority Issues that will cause no meaningful problems if left unaddressed. WML Tools Issues involving WML maintenance tools.
Projects
None yet
Development

No branches or pull requests

4 participants