Skip to content

Commit

Permalink
1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
3093FengMing committed Feb 20, 2024
1 parent 601745d commit ace2525
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## World Translation Extractor Modified (WTEM) 1.3
## World Translation Extractor Modified (WTEM) 1.4
Forked by [WorldTranslationExtractor](https://github.com/5uso/AmuletScripts/blob/main/WorldTranslationExtractor.py)

### Information
Expand Down
2 changes: 1 addition & 1 deletion README_zh_cn.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 存档翻译提取器 (WTEM) 1.3
## 存档翻译提取器魔改版 (WTEM) 1.4
World Translation Extractor Modified

Forked by [WorldTranslationExtractor](https://github.com/5uso/AmuletScripts/blob/main/WorldTranslationExtractor.py)
Expand Down
27 changes: 13 additions & 14 deletions WorldTranslationExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def match_text(match, escaped=False, dupe=False):
rel_lang[rk] = plain
print(f'[text] put key: {rk}: {rel_lang[rk]}')
if dupe:
return f'\\"translate\\":\\"{rev_lang[plain]}\\"' if escaped else f'"translate":"{rev_lang[plain]}"'
return f'\\"translate\\":\\"{rk}\\"' if escaped else f'"translate":"{rk}"'
return f'\\"translate\\":\\"{rk}\\"' if escaped else f'"translate":"{rk}"'
return f'\\"translate\\":\\"{rev_lang[plain]}\\"' if escaped else f'"translate":"{rev_lang[plain]}"'


def match_plain_text(match, dupe=False):
Expand All @@ -94,7 +94,7 @@ def match_plain_text(match, dupe=False):
return f'{{"translate":"empty"}}'
rel_lang[rk] = plain
print(f'[plain] put key: {rk}: {rel_lang[rk]}')
if dupe:
if not dupe:
return f'{{"translate":"{rev_lang[plain]}"}}'
return f'{{"translate":"{rk}"}}'

Expand All @@ -108,7 +108,7 @@ def match_contents(match, dupe=False):
return f'"contents":{{"translate":"empty"}}'
rel_lang[rk] = plain
print(f'[contents] put key: {rk}: {rel_lang[rk]}')
if dupe:
if not dupe:
return f'"contents":{{"translate":"{rev_lang[plain]}"}}'
return f'"contents":{{"translate":"{rk}"}}'

Expand All @@ -123,7 +123,7 @@ def match_bossbar(match, dupe=False):
return f'bossbar set {name} name {{"translate":"empty"}}'
rel_lang[rk] = plain
print(f'[bossbar1] put key: {rk}: {rel_lang[rk]}')
if dupe:
if not dupe:
return f'bossbar set {name} name {{"translate":"{rev_lang[plain]}"}}'
return f'bossbar set {name} name {{"translate":"{rk}"}}'

Expand All @@ -138,7 +138,7 @@ def match_bossbar2(match, dupe=False):
return f'bossbar add {name} {{"translate":"empty"}}'
rel_lang[rk] = plain
print(f'[bossbar2] put key: {rk}: {rel_lang[rk]}')
if dupe:
if not dupe:
return f'bossbar add {name} {{"translate":"{rev_lang[plain]}"}}'
return f'bossbar add {name} {{"translate":"{rk}"}}'

Expand Down Expand Up @@ -186,19 +186,20 @@ def handle_item(item):
pass

try:
title = item['tag']['title']
title = str(item['tag']['title'])
if "display" not in item['tag']:
item['tag']['display'] = n.TAG_Compound()
if "Name" not in item['tag']['display']:
# TODO remember to sync it when match_text changed
rk = f"item.{id}.{item_counts[id]}.title.1"
rel_lang[rk] = title
print(f'[json] put key: {rk}: {rel_lang[rk]}')
print(f'[json book title] put key: {rk}: {rel_lang[rk]}')
if title not in rev_lang:
rev_lang[title] = rk
if cfg_dupe["items_title"] or cfg_dupe["items_all"]:
item['tag']['display']['Name'] = n.TAG_String(f'{{"translate":"{rev_lang[title]}","italic":false}}')
else:
item['tag']['display']['Name'] = n.TAG_String(f'{{"translate":"{rk}","italic":false}}')
else:
item['tag']['display']['Name'] = n.TAG_String(f'{{"translate":"{rev_lang[title]}","italic":false}}')
changed = True
except KeyError:
pass
Expand Down Expand Up @@ -297,13 +298,11 @@ def handle_sign(sign):
if 'front_text' in sign.keys():
for i in range(len(sign['front_text']['messages'])):
set_key(f"block.sign.{block_counts['sign']}.front_text{i + 1}")
sign['front_text']['messages'][i] = replace_component(sign['front_text']['messages'][i],
cfg_dupe["signs"])
sign['front_text']['messages'][i] = replace_component(sign['front_text']['messages'][i], cfg_dupe["signs"])
if 'back_text' in sign.keys():
for i in range(len(sign['back_text']['messages'])):
set_key(f"block.sign.{block_counts['sign']}.back_text{i + 1}")
sign['back_text']['messages'][i] = replace_component(sign['back_text']['messages'][i],
cfg_dupe["signs"])
sign['back_text']['messages'][i] = replace_component(sign['back_text']['messages'][i], cfg_dupe["signs"])

if translation_cnt != len(rel_lang):
block_counts["sign"] += 1
Expand Down

0 comments on commit ace2525

Please sign in to comment.