in scripts/translations/base_string_script.py [0:0]
def ProcessFile(self, file_name):
"""
Process and write a file of string resources.
:param file_name: path to the file to process.
:return: None.
"""
lines = []
state = self.STATE_SEARCHING
curr_tag = []
pending_process_type = None
with open(file_name, 'r') as myfile:
data = myfile.read()
for line in data.split('\n'):
# Searching for a new tag
if state == self.STATE_SEARCHING:
if self.START_STR in line:
state = self.STATE_IN_STR
elif self.START_PLUR in line:
state = self.STATE_IN_PLUR
else:
lines.append(line)
# Inside of a string tag
if state == self.STATE_IN_STR:
curr_tag.append(line)
if self.END_STR in line:
pending_process_type = self.TYPE_STR
# Inside of a plurals tag
if state == self.STATE_IN_PLUR:
curr_tag.append(line)
if self.END_PLUR in line:
pending_process_type = self.TYPE_PLUR
# Some processing needs doing
if pending_process_type:
# Do processing
lines += self.ProcessTag(curr_tag, pending_process_type)
# Reset processing state
pending_process_type = None
state = self.STATE_SEARCHING
curr_tag = []
# Write back to the file
self.WriteFile(file_name, '\n'.join(lines))