diff --git a/openformats/formats/yaml/utils.py b/openformats/formats/yaml/utils.py index 1cfcb7c0..89b91443 100644 --- a/openformats/formats/yaml/utils.py +++ b/openformats/formats/yaml/utils.py @@ -222,6 +222,8 @@ def construct_mapping(self, node, deep=True): and self._is_custom_tag(value_node.tag) ): tag = six.text_type(value_node.tag) + # remove the exclamation mark from the tag + tag = tag[1:] if tag.startswith('!') else tag value = Node(value, start, end, style, tag) pairs.append((key, value)) @@ -350,7 +352,7 @@ def generate_yaml_dict(self, stringset): ) else: self._insert_translation_in_dict( - yaml_dict, keys, flags, se.string, tag=se.context, + yaml_dict, keys, flags, se.string, tag='!'+se.context if se.context else se.context, ) return yaml_dict diff --git a/openformats/formats/yaml/yaml.py b/openformats/formats/yaml/yaml.py index b6d3bd5f..87168276 100644 --- a/openformats/formats/yaml/yaml.py +++ b/openformats/formats/yaml/yaml.py @@ -404,7 +404,8 @@ def _compile_from_template(self, template, stringset, **kwargs): # it and apply a space afterwards so it doesn't get merged with the # string if string.context: - transcriber.add(string.context) + # add an exclamation mark to the context to make it a tag + transcriber.add('!'+string.context) transcriber.add(' ') transcriber.add(translation) transcriber.skip(len(string.template_replacement)) diff --git a/openformats/tests/formats/yaml/files/1_tpl.yml b/openformats/tests/formats/yaml/files/1_tpl.yml index f9931de2..3c917397 100644 --- a/openformats/tests/formats/yaml/files/1_tpl.yml +++ b/openformats/tests/formats/yaml/files/1_tpl.yml @@ -65,8 +65,8 @@ alias_key: - ddc3cfcedcf1686d9e3ba6b99a0d091b_tr # Custom tags -foo: 3e4000f6f4cd8bb27db6fb82e1b50bb4_tr # Should treat as string and ignore leading spaces -bar: 75ce597a505a4faf6369b66b885926c8_tr # Also a string +foo: 023503fb466f78932b77209b6581156e_tr # Should treat as string and ignore leading spaces +bar: fac8140a2ec031af14bc758e73f59017_tr # Also a string hello: b0ed9cf22c0a5186d1c5b483a910dd33_tr # Translatable number: !!int 123 # Should ignore bin: !!binary aGVsbG8= # Should ignore diff --git a/openformats/tests/formats/yaml/test_yaml.py b/openformats/tests/formats/yaml/test_yaml.py index d547796b..cec516ec 100644 --- a/openformats/tests/formats/yaml/test_yaml.py +++ b/openformats/tests/formats/yaml/test_yaml.py @@ -144,7 +144,7 @@ def test_openstring_attributes(self): self.assertEqual(test_string.flags, '') content_string = strings[1] - self.assertEqual(content_string.context, '!tag') + self.assertEqual(content_string.context, 'tag') self.assertEqual(content_string.flags, "'") def test_parse_duplicate_keys(self):