Add in generate Stringnames for lex entities and play back into templates
This commit is contained in:
37
sm2gen.py
37
sm2gen.py
@@ -377,23 +377,50 @@ if __name__ == "__main__":
|
||||
all_strings = all_strings + extracted_strings
|
||||
#Take out any duplicates
|
||||
all_strings = deduplicate_array(all_strings)
|
||||
# Now process them one by one into the lexical file
|
||||
lex_all = "";
|
||||
# '<prefix>_english-message' => 'English Message',
|
||||
string_lib = [] #Array of dicts
|
||||
for lex_message in all_strings:
|
||||
# If has a prefix - leave it for left hand side but delete it for the right
|
||||
# If has no prefix - add one for left hand side but and lkeave it for the right
|
||||
# If has no prefix - add one for left hand side but and leave it for the right
|
||||
# Map all spaces to "_" on left hand side
|
||||
# amd truncate it to max five words
|
||||
original_str = lex_message
|
||||
if lex_message.startswith(hl('prefix')):
|
||||
left_str = lex_message
|
||||
right_str = lex_message[len(hl('prefix'))+1:]
|
||||
else:
|
||||
left_str = hl('prefix')+"_"+lex_message
|
||||
right_str = lex_message
|
||||
lex_all += f"'{left_str}' => '{right_str}'\n"
|
||||
left_str = left_str.replace(" ","_")
|
||||
words = left_str.split('_')[:6]
|
||||
left_str = "_".join(words)
|
||||
next_lex_str = {"orig":original_str,"left":left_str,"right":right_str}
|
||||
string_lib.append(next_lex_str)
|
||||
print(string_lib)
|
||||
#And write it to lex file
|
||||
# Now process them one by one into the lexical file
|
||||
lex_all = "";
|
||||
for lex_str in string_lib:
|
||||
lex_all += f"\'{lex_str['left']}\' => \'{lex_str['right']}\',\n"
|
||||
print(f"Writing {lex_file}")
|
||||
with open( lex_file, 'w') as file:
|
||||
file.write(lex_all)
|
||||
|
||||
#and then play the strings back into the partials and the layout file
|
||||
for filename in all_files:
|
||||
with open(filename, 'r') as file:
|
||||
file_content = file.read()
|
||||
# Scan through
|
||||
for item in string_lib:
|
||||
original_str = item["orig"]
|
||||
left_str = item["left"]
|
||||
right_str = item["right"]
|
||||
|
||||
# Replace all occurrences of original string with left string in 'contents'
|
||||
file_content = file_content.replace(original_str, left_str)
|
||||
# and write it back
|
||||
with open(filename, 'w') as file:
|
||||
file.write(file_content)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user