-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to write strings from translations to prelude.yaml
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import math | ||
import re | ||
import os | ||
|
||
import yaml | ||
|
||
messages = {} | ||
for f in os.scandir('translations'): | ||
match = re.match(r'messages\.([^\.]+)\.yaml', f.name) | ||
if match: | ||
lang = match.group(1) | ||
with open(f.path, encoding='utf8') as input: | ||
messages[lang] = yaml.safe_load(input) | ||
|
||
lines = [] | ||
with open('prelude.yaml', encoding='utf8') as input: | ||
lines = input.readlines() | ||
|
||
anchor = None | ||
lang = None | ||
for index, line in enumerate(lines): | ||
match = re.search(r' &([^\s]+)$', line) | ||
if match != None: | ||
anchor = match.group(1) | ||
lang = None | ||
text = None | ||
continue | ||
|
||
match = re.search(r'- lang: ([a-zA-Z_]+)', line) | ||
if match != None: | ||
lang = match.group(1) | ||
text = None | ||
continue | ||
|
||
match = re.search(r' text: \'(.+)\'', line) | ||
if match != None and anchor and lang: | ||
# Replace line with a new line for this message | ||
message = yaml.dump(messages[lang][anchor], width=math.inf, allow_unicode=True, default_style="'") | ||
|
||
lines[index] = re.sub(r' text: \'.+\'', f' text: {message.strip()}', line) | ||
|
||
|
||
with open('prelude.yaml', mode='w', encoding='utf8') as output: | ||
output.writelines(lines) |