Skip to content

Commit

Permalink
chg: allow whitespace on either side of translation delimiter in head…
Browse files Browse the repository at this point in the history
…er (#718)
  • Loading branch information
lindsay-stevens authored Sep 4, 2024
1 parent f6285f9 commit 66283b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def dealias_and_group_headers(
header = header.lower()

if use_double_colons:
tokens = header.split(group_delimiter)
tokens = [t.strip() for t in header.split(group_delimiter)]

# else:
# We do the initial parse using single colons
Expand All @@ -152,7 +152,7 @@ def dealias_and_group_headers(
# break if there is something like media:image:english
# so maybe a better backwards compatibility hack
# is to join any jr token with the next token
tokens = header.split(":")
tokens = [t.strip() for t in header.split(":")]
if "jr" in tokens:
jr_idx = tokens.index("jr")
tokens[jr_idx] = ":".join(tokens[jr_idx : jr_idx + 2])
Expand Down
23 changes: 23 additions & 0 deletions tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ def test_double_colon_translations(self):
warnings_count=0,
)

def test_spaces_adjacent_to_translation_delimiter(self):
"""Should trim whitespace either side of double-colon '::' delimiter."""
md = """
| survey |
| | type | name | label::French (fr) | constraint | constraint_message::French (fr) | constraint_message :: English (en) |
| | text | q1 | Q1 | string-length(.) > 5 | Trop court! | Too short! |
"""
self.assertPyxformXform(
md=md,
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:itext/x:translation[@lang='French (fr)']
/x:text[@id='/test_name/q1:jr:constraintMsg']
/x:value[not(@form) and text()='Trop court!']
""",
"""
/h:html/h:head/x:model/x:itext/x:translation[@lang='English (en)']
/x:text[@id='/test_name/q1:jr:constraintMsg']
/x:value[not(@form) and text()='Too short!']
""",
],
)

def test_missing_media_itext(self):
"""Test missing media itext translation
Expand Down

0 comments on commit 66283b6

Please sign in to comment.