Jump to content

Search locale/translate.lua Tool


Recommended Posts

  • Premium

Hey, I'm looking for a script or tool that inserts/replaces the GAMEFORGE strings from locale.lua back into the original quest SAY strings, because I really don't want to work with locale/translate.lua and would like to have the quests back the way they used to be, and I don't want to have to change them all manually.

 

I'm grateful for any advice or help.

 

 

spacer.png

Link to comment
https://metin2.dev/topic/33994-search-localetranslatelua-tool/
Share on other sites

I tried with a hunting quest, it's working with gameforge strings at least. Anyway, probably won't work for every quest, i'll leave the debug for you guys.

 

"""
resolve_gameforge_refs.py

Usage:
    python resolve_gameforge_refs.py --quest path/to/name_of_quest.quest --translate path/to/translate.lua --out path/to/name_of_resolved_quest.quest
"""
import argparse
import re
from pathlib import Path

def parse_translate(path: Path) -> dict:
    text = path.read_text(encoding="utf-8", errors="ignore")
    assign_re = re.compile(r'^(gameforge(?:\.[A-Za-z0-9_]+)+)\s*=\s*(".*?")\s*$', re.M)
    mapping = {}
    for m in assign_re.finditer(text):
        key = m.group(1)
        val = m.group(2)
        mapping[key] = val
    return mapping

def extract_tokens(quest_text: str) -> list[str]:
    return sorted(set(re.findall(r'\bgameforge(?:\.[A-Za-z0-9_]+)+', quest_text)))

def replace_tokens(quest_text: str, mapping: dict) -> tuple[str, dict, list]:
    tokens = extract_tokens(quest_text)
    to_replace = {t: mapping[t] for t in tokens if t in mapping}
    missing = [t for t in tokens if t not in mapping]
    replaced = quest_text
    for key in sorted(to_replace.keys(), key=len, reverse=True):
        pattern = r'\b' + re.escape(key) + r'\b'
        replaced = re.sub(pattern, to_replace[key], replaced)
    return replaced, to_replace, missing

def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--quest", required=True, type=Path, help="Path to the quest file")
    ap.add_argument("--translate", required=True, type=Path, help="Path to translate.lua")
    ap.add_argument("--out", required=True, type=Path, help="Output path for resolved quest")
    args = ap.parse_args()

    quest_text = args.quest.read_text(encoding="utf-8", errors="ignore")
    mapping = parse_translate(args.translate)
    replaced_text, to_replace, missing = replace_tokens(quest_text, mapping)

    args.out.write_text(replaced_text, encoding="utf-8")
    print(f"Wrote: {args.out} ({args.out.stat().st_size} bytes)")
    print(f"Found {len(to_replace)} keys to replace out of {len(extract_tokens(quest_text))} tokens.")
    if missing:
        print("Missing keys (no translation found):")
        for k in missing:
            print("  -", k)

if __name__ == "__main__":
    main()

 

Edited by friendtm
  • Flame 1

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.