Skip to content

Commit

Permalink
wmlxgettext: support double quotes in raw strings (fixes #4484)
Browse files Browse the repository at this point in the history
This adds support for _<<map="{maps/01_First_Map.map}">>, as used in the
editor file format documentation.

This doesn't require another .pot update, because both the workaround in
3d77d36 and this fix generate the same string in the .pot file. However, it
does change the string that the Wesnoth executable looks for so that it matches
the .pot file's contents.

Cherry picked from commit c30c30a, and
additionally reverted commit 3d77d36.
  • Loading branch information
stevecotton committed Jan 16, 2021
1 parent 3f8a995 commit 75f7cb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -13,6 +13,8 @@
### Translations
* Updated translations: Catalan, Chinese (Traditional), French, Portuguese (Brazil),
Spanish
### Miscellaneous and Bug Fixes
* Added support to wmlxgettext for double-quote characters in translatable raw strings

## Version 1.14.15
### Add-ons client
Expand Down
9 changes: 7 additions & 2 deletions data/tools/pywmlx/state/machine.py
Expand Up @@ -248,11 +248,13 @@ def store(self):


class PendingWmlString:
def __init__(self, lineno, wmlstring, ismultiline, istranslatable):
def __init__(self, lineno, wmlstring, ismultiline, istranslatable, israw):
"""The israw argument indicates a << >> delimited string"""
self.lineno = lineno
self.wmlstring = wmlstring.replace('\\', r'\\')
self.ismultiline = ismultiline
self.istranslatable = istranslatable
self.israw = israw

def addline(self, value):
self.wmlstring = self.wmlstring + '\n' + value.replace('\\', r'\\')
Expand All @@ -275,7 +277,10 @@ def store(self):
# so, using "if errcode != 1"
# we will add the translatable string ONLY if it is NOT empty
_linenosub += 1
self.wmlstring = re.sub('""', r'\"', self.wmlstring)
if self.israw:
self.wmlstring = re.sub('"', r'\"', self.wmlstring)
else:
self.wmlstring = re.sub('""', r'\"', self.wmlstring)
pywmlx.nodemanip.addNodeSentence(self.wmlstring,
ismultiline=self.ismultiline,
lineno=self.lineno,
Expand Down
4 changes: 2 additions & 2 deletions data/tools/pywmlx/state/wml_states.py
Expand Up @@ -169,7 +169,7 @@ def run(self, xline, lineno, match):
'please report a bug if you encounter this error message')
pywmlx.state.machine._pending_wmlstring = (
pywmlx.state.machine.PendingWmlString(
lineno, loc_string, loc_multiline, loc_translatable
lineno, loc_string, loc_multiline, loc_translatable, israw=True
)
)
return (xline, _nextstate)
Expand Down Expand Up @@ -249,7 +249,7 @@ def run(self, xline, lineno, match):
xline = xline [ match.end(): ]
pywmlx.state.machine._pending_wmlstring = (
pywmlx.state.machine.PendingWmlString(
lineno, match.group(2), loc_multiline, loc_translatable
lineno, match.group(2), loc_multiline, loc_translatable, israw=False
)
)
return (xline, _nextstate)
Expand Down

0 comments on commit 75f7cb1

Please sign in to comment.