Browse Source

Fix i18n string parsing for non-ascii characters (#266)

pull/267/head
Jonathan Wright 2 years ago
committed by GitHub
parent
commit
3fada8d4d7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      find_missing_i18n_strings.py

8
find_missing_i18n_strings.py

@ -3,7 +3,7 @@ import os
import json import json
# Open the json file and load its contents into a dictionary # Open the json file and load its contents into a dictionary
with open('i18n/en.json', 'r') as f: with open('i18n/en.json', 'r', encoding='utf-8') as f:
en = json.load(f) en = json.load(f)
# Create a copy of the en dictionary's keys and convert it to a set for better performance # Create a copy of the en dictionary's keys and convert it to a set for better performance
@ -18,7 +18,7 @@ for folder, dirs, files in os.walk(rootdir):
for file in files: for file in files:
if file.endswith('.html'): if file.endswith('.html'):
fullpath = os.path.join(folder, file) fullpath = os.path.join(folder, file)
with open(fullpath, 'r') as f: with open(fullpath, 'r', encoding='utf-8') as f:
for line in f: for line in f:
m = re.findall('{{\s+?i18n\s+?(?:"|`)(.*?)(?:"|`)\s+?}}', line, re.DOTALL) m = re.findall('{{\s+?i18n\s+?(?:"|`)(.*?)(?:"|`)\s+?}}', line, re.DOTALL)
if m: if m:
@ -42,5 +42,5 @@ if error or unused_keys:
else: else:
print("No unused keys found.") print("No unused keys found.")
with open('i18n/en.json', 'w') as f: with open('i18n/en.json', 'w', encoding='utf-8') as f:
json.dump(en, f, indent=3) json.dump(en, f, indent=3, ensure_ascii=False)

Loading…
Cancel
Save