Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Added special character replacement in the Script #38

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Scribe-i18n/Scripts/convert_jsons_to_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
import os
import json


def replace_special_characters(string):
string = string.replace("'", "\\'")
string = string.replace("&", "&")
string = string.replace("<", "&lt;")
string = string.replace(">", "&gt;")
return string

directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
dir_list = os.listdir(directory)
languages = sorted(
Expand All @@ -30,6 +38,7 @@
json_data = json.loads(json_data)

for key, value in json_data.items():
value = replace_special_characters(value)
xml_file.write(f' <string name="{key}">{value}</string>\n')

xml_file.write('</resources>\n')
Expand Down
10 changes: 10 additions & 0 deletions Scribe-i18n/Scripts/convert_strings_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
import json
import re

def unescape_special_characters(string):
string = string.replace("&gt;", ">")
string = string.replace("&lt;", "<")
string = string.replace("&amp;", "&")
string = string.replace("\\'", "'")
return string



directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
dir_list = os.listdir(directory)
languages = sorted(
Expand All @@ -23,6 +32,7 @@
content = file.read()
matches = regex.findall(content)
result = dict(matches)
result = {key: unescape_special_characters(value) for key, value in result.items()}
with open(os.path.join(directory,f'{lang}.json'), 'w',encoding='utf-8') as file:
json.dump(result, file, indent=4,ensure_ascii=False)

Expand Down
Loading