Skip to content

Commit

Permalink
Update text checker & fix en + pt translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Iapetus-11 committed Jul 16, 2024
1 parent 6de48ba commit e72182b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
1 change: 0 additions & 1 deletion bot/data/text/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,6 @@
"This enchantment book is applied automatically as long as it remains in your inventory, and also transfers to all new pickaxes. This enchantment book does not stack."
]
},

"Luck Potion": {
"description": [
"> When used with the `{prefix}chug Luck Potion` command you will experience the effects listed below for `4 minutes and 30 seconds`.",
Expand Down
4 changes: 2 additions & 2 deletions bot/data/text/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -2504,8 +2504,8 @@
"Luck Potion": {
"description": [
"> Quando usada com o comando `{prefix}chug Luck Potion`, você irá experienciar os efeitos listados abaixo por `4 minutos e 30 segundos`.",
"Aumentar significativamente as chances de:\n- Obter espaços de cofre extras ao executar comandos de economia.\n- Encontrar itens colecionáveis ​​da mineração.",
"Diminuir significativamente as chances de:\n- Pescar lixo (em vez de itens colecionáveis ​​ou peixes).\n- Perder abelhas ao usar o comando `{prefix}honey`.\n- Encontrar isca de pesca ao esvaziar a `{prefix}trashcan`."
"Aumentar significativamente as chances de:\n- Obter espaços de cofre extras ao executar comandos de economia.\n- Encontrar itens colecionáveis da mineração.\n- Encontrar isca de pesca ao esvaziar a `{prefix}trashcan`.",
"Diminuir significativamente as chances de:\n- Pescar lixo (em vez de itens colecionáveis ou peixes).\n- Perder abelhas ao usar o comando `{prefix}honey`."
],
"quoted": false
},
Expand Down
40 changes: 33 additions & 7 deletions scripts/check_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import json
import os
import re
import sys
from collections import Counter
from typing import Any

from common.utils.setup import load_data

DEFAULT_TRANSLATION = "en"
FORMAT_BRACES_REGEX = re.compile(r"\{[^}]*\}", re.RegexFlag.MULTILINE)


def check_obj(keys: list[Any], obj: Any, against: Any, against_name: str) -> bool:
error = False
Expand Down Expand Up @@ -35,26 +40,47 @@ def check_obj(keys: list[Any], obj: Any, against: Any, against_name: str) -> boo
)
error = True

if isinstance(obj, str):
obj_matches = Counter(FORMAT_BRACES_REGEX.findall(obj))
against_matches = Counter(FORMAT_BRACES_REGEX.findall(against))
matches_diff = {
k: obj_matches.get(k, 0) - against_matches.get(k, 0)
for k in set(obj_matches.keys()) | set(against_matches.keys())
}

formatted_diff = ", ".join([
f"{key}.{diff:+}" for key, diff in matches_diff.items() if diff
])

if obj_matches != against_matches:
print(
f"MISMATCHED FORMAT VARIABLES ({against_name}): {'.'.join(map(str, keys))} "
f"=> {formatted_diff}"
)

return error


def run():
with open("bot/data/text/en.json", "r", encoding="utf8") as f:
en_data = json.load(f)["en"]
with open(f"bot/data/text/{DEFAULT_TRANSLATION}.json", "r", encoding="utf8") as f:
en_data = json.load(f)[DEFAULT_TRANSLATION]

data_file = load_data()

error = False

for filename in os.listdir("bot/data/text"):
lang = filename.removesuffix(".json")
if lang == DEFAULT_TRANSLATION:
continue

if lang in data_file.disabled_translations:
continue

with open(f"bot/data/text/{filename}", "r", encoding="utf8") as f:
lang = filename.replace(".json", "")
data = json.load(f)[lang]

if lang in data_file.disabled_translations:
continue

error |= check_obj([lang], en_data, data, lang)
error |= check_obj([lang], en_data, data, lang)

if error:
sys.exit(1)
Expand Down

0 comments on commit e72182b

Please sign in to comment.