Skip to content

Commit 919a1b8

Browse files
committed
Overwritte add/remove method for other json parsers
1 parent 8648716 commit 919a1b8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

openformats/formats/json.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import re
88
from itertools import count
9+
from typing import Tuple
910

1011
import six
1112

@@ -729,6 +730,14 @@ def _copy_until_and_remove_section(self, pos):
729730
self.transcriber.remove_section()
730731

731732

733+
def add_strings_to_template(
734+
self, template: str, stringset: list[OpenString]
735+
) -> str:
736+
"""
737+
Adds strings to the template that are not in the template currently.
738+
"""
739+
return template
740+
732741
class StructuredJsonHandler(JsonHandler):
733742
"""Handler that preserves certain keys for internal usage, while
734743
keeping the flexibility and functionality of the original JsonHandler. It
@@ -1116,6 +1125,21 @@ def _copy_until_and_remove_section(self, pos):
11161125
# Unlike the JSON format, do not remove the remaining section of the
11171126
# template
11181127

1128+
def remove_strings_from_template(
1129+
self, template: str, stringset: list[OpenString]
1130+
) -> str:
1131+
"""
1132+
Removes strings from the template that are not in the stringset.
1133+
"""
1134+
return template
1135+
1136+
def add_strings_to_template(
1137+
self, template: str, stringset: list[OpenString]
1138+
) -> str:
1139+
"""
1140+
Adds strings to the template that are not in the template currently.
1141+
"""
1142+
return template
11191143

11201144
class ChromeI18nHandler(JsonHandler):
11211145
"""Responsible for CHROME files, based on the JsonHandler."""
@@ -1197,6 +1221,22 @@ def validate_content(self, content):
11971221
except ValueError as e:
11981222
raise ParseError(six.text_type(e))
11991223

1224+
def remove_strings_from_template(
1225+
self, template: str, stringset: list[OpenString]
1226+
) -> str:
1227+
"""
1228+
Removes strings from the template that are not in the stringset.
1229+
"""
1230+
return template
1231+
1232+
def add_strings_to_template(
1233+
self, template: str, stringset: list[OpenString]
1234+
) -> str:
1235+
"""
1236+
Adds strings to the template that are not in the template currently.
1237+
"""
1238+
return template
1239+
12001240

12011241
class ChromeI18nHandlerV3(Handler):
12021242
"""New version of chrome-json handler.
@@ -1417,6 +1457,22 @@ def compile(self, template, stringset, **kwargs):
14171457

14181458
return compiled
14191459

1460+
def remove_strings_from_template(
1461+
self, template: str, stringset: list[OpenString]
1462+
) -> str:
1463+
"""
1464+
Removes strings from the template that are not in the stringset.
1465+
"""
1466+
return template
1467+
1468+
def add_strings_to_template(
1469+
self, template: str, stringset: list[OpenString]
1470+
) -> str:
1471+
"""
1472+
Adds strings to the template that are not in the template currently.
1473+
"""
1474+
return template
1475+
14201476
@staticmethod
14211477
def escape(string):
14221478
return escape(string)

0 commit comments

Comments
 (0)