Skip to content

Commit

Permalink
Fix missing languages not getting added to the last message
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jan 22, 2025
1 parent 17145bc commit 18c2e0f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions prelude.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,8 @@ common:
text: '**{0}** kullanıyor gibi görünüyorsunuz, ancak bu artık geçersiz. Bunun yerine **{1}** kullanmanız tavsiye edilir.'
- lang: uk_UA
text: 'Здається, ви використовуєте **{0}**, але його було замінено. Радимо використовувати **{1}** замість нього.'
- lang: zh_CN
text: '您似乎正在使用 **{0}**,但它已受到取代。推荐您使用 **{1}**。'
subs:
- 'xSE Plugin 0'
- 'xSE Plugin 1'
Expand Down
33 changes: 21 additions & 12 deletions scripts/import-translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ def insert_lang(lines, index, lang, raw_text, whitespace = None):
lines.insert(index, new_text_line)
lines.insert(index, new_lang_line)

def append_missing_languages(messages, lines, anchor, last_lang_index, expected_langs):
# Expected more languages than were found in the last anchor,
# need to go back and append the remaining expected languages.
print(f'Expected more languages for anchor {anchor}: {expected_langs}')

whitespace = get_whitespace(lines[last_lang_index])

for expected_lang in expected_langs:
print(f'Appending language {expected_lang} to anchor {anchor}')

insert_lang(lines, last_lang_index + 2, expected_lang, messages[anchor][expected_lang], whitespace)

last_lang_index += 2

return last_lang_index

messages_by_lang = {}
for f in os.scandir('translations'):
match = re.match(r'messages\.([^\.]+)\.yaml', f.name)
Expand Down Expand Up @@ -68,18 +84,7 @@ def insert_lang(lines, index, lang, raw_text, whitespace = None):
match = re.search(r' &([^\s]+)$', lines[index])
if match != None:
if expected_langs:
# Expected more languages than were found in the last anchor,
# need to go back and append the remaining expected languages.
print(f'Expected more languages for anchor {anchor}: {expected_langs}')

whitespace = get_whitespace(lines[last_lang_index])

for expected_lang in expected_langs:
print(f'Appending language {expected_lang} to anchor {anchor}')

insert_lang(lines, last_lang_index + 2, expected_lang, messages[anchor][expected_lang], whitespace)

last_lang_index += 2
last_lang_index = append_missing_languages(messages, lines, anchor, last_lang_index, expected_langs)

index += 2 * len(expected_langs)

Expand Down Expand Up @@ -117,5 +122,9 @@ def insert_lang(lines, index, lang, raw_text, whitespace = None):

index += 1

if expected_langs:
# The last anchor has missing languages, go back and add them.
append_missing_languages(messages, lines, anchor, last_lang_index, expected_langs)

with open('prelude.yaml', mode='w', encoding='utf8') as output:
output.writelines(lines)

0 comments on commit 18c2e0f

Please sign in to comment.