From 2dcb03f3757bcc82efa0525ca67d0fa11dd60f2d Mon Sep 17 00:00:00 2001 From: lindsay stevens Date: Thu, 5 Sep 2024 01:12:26 +1000 Subject: [PATCH] chg: allow whitespace on either side of translation delimiter in header --- pyxform/xls2json.py | 4 ++-- tests/test_translations.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pyxform/xls2json.py b/pyxform/xls2json.py index 1bce494d..6bc7dabe 100644 --- a/pyxform/xls2json.py +++ b/pyxform/xls2json.py @@ -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 @@ -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]) diff --git a/tests/test_translations.py b/tests/test_translations.py index 32621689..1f891ef3 100644 --- a/tests/test_translations.py +++ b/tests/test_translations.py @@ -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