summaryrefslogtreecommitdiff
path: root/ledit
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2024-06-15 19:42:51 -0300
committerJesusaves <cpntb1@ymail.com>2024-06-15 19:42:51 -0300
commit258a61b0a725c440ba82a1e27da676206086be9f (patch)
tree20a38ecfa1e5074a773cdc378cadcf56840c7661 /ledit
parenta9f234e7c2ab5c6768766682bb7eda06f5817810 (diff)
downloadtools-258a61b0a725c440ba82a1e27da676206086be9f.tar.gz
tools-258a61b0a725c440ba82a1e27da676206086be9f.tar.bz2
tools-258a61b0a725c440ba82a1e27da676206086be9f.tar.xz
tools-258a61b0a725c440ba82a1e27da676206086be9f.zip
Add helper tool for my own translations
Diffstat (limited to 'ledit')
-rw-r--r--ledit/_img.py5
-rw-r--r--ledit/favicon.pngbin0 -> 1010 bytes
-rwxr-xr-xledit/ledit.py241
3 files changed, 246 insertions, 0 deletions
diff --git a/ledit/_img.py b/ledit/_img.py
new file mode 100644
index 0000000..3fc6286
--- /dev/null
+++ b/ledit/_img.py
@@ -0,0 +1,5 @@
+## This contains the base64 abstractions of the PNG assets
+## Used on Windows build or as a fallback
+
+__favicon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QUWCgE3c9cz+gAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAANaSURBVFjDxVddSFNhGH62vOhirhaKHHE/sCETt/wZU5RJFEUITiIoQ0xCxIugbrpW+oGEbrzoopvqpkism0hChAhC0Vwsjbk8yKT9yI42YaUiGNTpIt+P7+zPbW75wjg7H+ec9/me732e7/2AQw7VQV62aTVyqvHFze2sv1tykOSjQ30AgGA0xsbHp32AGJSzBaE6aHI+CMj4tA8zYjArJtT5MsDPmu5NleUAALfLnvV31LnO3KbVyK1WE0tGQfd07T3dkLZG+DiSS/JHd2+i4thRbGz8hMf/DZu//8BccSLp2R9bO/j4NQR92XHsbu3c/r77605BGPj0+QtEMYQbl88AAM6dNAMAHr58z34UV7s7YbUa0XfhVEYm1LnMXhRDcLvsEPQG3L91DYLeAAAMEF2XVlYBAM7GOhS8CFuaHYr7RBBUnM9evGHPZGIhZwCzc96kMQIRjMbY7IuiAqvV+M9oAEiRsOLKJw9I8eIAEMUQY0HQGxgbqVgp6F5A2ieDIRbcLjvT/cTUvGLmV7s7mXKevv6Q1hVLstlsRof6mNMFozFYBB0CUpwBSQw+eV6bESUe7nfDVFnOiowkFpDisAg61JirksYTk9OyZV0DNq1GfvfqHnyeMVZcUiSMial5BKMxlry9rQGmynL248Ekzny4352bDCuM1fAveNEx0MNA1JirWJW3tzUkvcPvDc7GOjgb65hxtTQ70Go1pQSRsQbWQ8sKegHAIuiS9E9SdLvsCgOi5FIkDLfLjhkxuD8Di5vbKntTF2rrHaziiXYAjGq+Lvj/FkHHnl1aWcXsnJe5YyoWStK1VPamLrnValIkDkhxRVHSzFMFKaX3+kVUGKv3Rp8nsZBWBaSATBYr6A2QImF2peD9gOoJAJznm4DH49mpoGOgR9Fi8VUuRcIsISWnZwNSHG6XnW1OeVkxrwIyHurz+FaMB8Jvwzxb/gUvausdKNOV4uylwSRHVKViwOcZY7SV6UoxNPiENZm0PCS9xI6YPIKWjtwyXZOqSlcDPs8Yk2Eict4pFe34Xl+QCCpTh6zK5tCR7uVESdGGRQa2HlpWsFfwk9F+y1db74B/wYsrAw/SAlCjiEFL+F/DptXIsvhWXpsckdcmR+T9zgaqYoHI56B6KPEXAZ3lb1FYu4cAAAAASUVORK5CYII="
+
diff --git a/ledit/favicon.png b/ledit/favicon.png
new file mode 100644
index 0000000..2539039
--- /dev/null
+++ b/ledit/favicon.png
Binary files differ
diff --git a/ledit/ledit.py b/ledit/ledit.py
new file mode 100755
index 0000000..ce9b256
--- /dev/null
+++ b/ledit/ledit.py
@@ -0,0 +1,241 @@
+#!/usr/bin/python3
+#####################################
+## (C) Jesusalva, 2018-2024
+## Published under the MIT License
+## Usage: ./ledit.py in.py pt_BR
+#####################################
+
+import requests, json, traceback, subprocess, sys, time, os, uuid, base64
+import zipfile, shutil, webbrowser
+import polib
+from googletrans import Translator
+import tkinter as tk
+from tkinter.messagebox import showinfo, showerror, askyesno
+from functools import partial
+
+## Prepare some basic stuff
+execute=subprocess.call
+sleep = time.sleep
+
+class HoverButton(tk.Button):
+ def enter(self, e):
+ self["background"] = self["activebackground"]
+ def exit(self, e):
+ self["background"] = self.defaultBackground
+
+ def __init__(self, **kw):
+ tk.Button.__init__(self, **kw)
+ self.defaultBackground = self["background"]
+ self.bind("<Enter>", self.enter)
+ self.bind("<Leave>", self.exit)
+
+## IF Then Else (IFTE)
+def ifte(ifs, then, elses):
+ if (ifs):
+ return then
+ else:
+ return elses
+
+# Search for array[?][key]==search in an array of dicts
+# Returns the index, or returns -1
+def dl_search_idx(array, key, search):
+ try:
+ r=next((i for i, item in enumerate(array) if item[key] == search), None)
+ except:
+ traceback.print_exc()
+ r=-1
+ return ifte(r is None, -1, r)
+
+## Open a game website
+def open_url(link, *etc):
+ webbrowser.open_new(link)
+ return
+
+## Only meaningful on Linux, or base things
+ttl=Translator()
+os.environ["APPIMAGELAUNCHER_DISABLE"]="1"
+
+## Retrieve file name
+if len(sys.argv) >= 2:
+ fn = sys.argv[1]
+else:
+ fn = "in.po"
+
+## Retrieve language
+if len(sys.argv) >= 3:
+ ln = sys.argv[2]
+else:
+ ln = "pt_BR"
+
+## Open the PO file and report current completion
+print("Opening \"%s\"...", fn)
+po=polib.pofile(fn)
+cnt=0
+print("Current progress: "+str(po.percent_translated())+"%")
+
+## Define the scopes, they should be completed in order
+scope_list=[("Nard Ship", "npc/002-", "npc/000-"),
+ ("Candor", "npc/005-", "npc/006-2"),
+ ("Databases", "db/", "npc/functions", "npc/items", "npc/config", "npc/craft", "npc/016-"),
+ ("Tonori", "npc/003-", "npc/004-", "npc/007-"),
+ ("Hurnscald", "npc/012-", "npc/013-", "npc/014-", "npc/015-"),
+ ("Halinarzo", "npc/009-", "npc/010-", "npc/011-"),
+ ("Land Fire", "npc/017-", "npc/018-"),
+ ("M Academy", "npc/027-", "npc/magic"),
+ ("Kaizei", "npc/019-", "npc/020-", "npc/021-", "npc/022-"),
+ ("Frostia", "npc/023-", "npc/024-", "npc/001-7"),
+ ("Events", "npc/001-", "npc/006-", "npc/030-"),
+ ("Fortress", "npc/025-", "npc/026-", "npc/029-"),
+ ("Special", "npc/031-", "npc/032-", "npc/033-", "npc/034-", "npc/soren"),
+ ("Kamelot", "npc/042-", "npc/guilds"),
+ ("System", "npc/boss", "npc/botcheck", "npc/commands", "npc/dev", "npc/sec_pri", "npc/test", "conf/")]
+ #("Other...")]
+
+
+#################################################################################
+polist=[]; current=""
+def _setHome(_hom):
+ global polist, po, current
+ _home = _hom.get()
+ print("Loading %s" % _home)
+ polist=[]
+ entry =[]
+ for s in scope_list:
+ if s[0] == _home:
+ entry=s
+ break
+ if entry == []:
+ return
+ #entry.remove(0) ## <- You can't remove something from a tuple
+
+ for e in po.untranslated_entries():
+ # e.msgid -> English text
+ # e.msgstr -> Translated text
+ # e.comment -> code information
+ # e.occurrences -> array of tuples where it shows at
+ for o in e.occurrences:
+ if e in polist:
+ break
+ for fp in entry:
+ if o[0].startswith(fp):
+ polist.append(e)
+ break
+ print("Domain changed!")
+ current=_home
+ _build_screen(destroy=True)
+ return
+
+## Save the translation to the po file
+def save(widget):
+ global polist, po, cnt
+ translated=widget.get("1.0", "end")
+ translated=translated.replace('\r','')
+ if translated.endswith("\n"):
+ translated=translated[:-1]
+ print("»" + translated)
+ polist[0].msgstr=translated
+ polist.pop(0)
+ po.save()
+ cnt+=1
+ _build_screen(destroy=True)
+ return
+
+#################################################################################
+## Build Tkinter interface
+root=tk.Tk()
+root.title("Moubootaur Legends l'edit")
+
+## Initialize the icon
+try:
+ _favicon = tk.PhotoImage(file = "favicon.png")
+except:
+ from _img import __favicon
+ _favicon = tk.PhotoImage(data = __favicon)
+
+root.iconphoto(True, _favicon)
+canva=None
+
+## Core function for the screen
+def _build_screen(destroy=False):
+ global canva, ttl, ln
+ if destroy:
+ canva.destroy()
+ canva = tk.Canvas(root, width=600, height=600, bg="#0c3251")
+ canva.pack()
+
+ ## Prompt to select a domain
+ if not len(polist):
+ label2 = tk.Label(root, text='Work Domain:', bg="#0c3251", fg="#fff")
+ label2.config(font=('helvetica', 12))
+ canva.create_window(50, 50, window=label2)
+
+ ## Domain selection core
+ ## It's partly ommited when translating
+ _home = tk.StringVar()
+ if current != "":
+ _home.set(current)
+ else:
+ _home.set("-- Set a domain --")
+ lista = []
+ for s in scope_list:
+ lista.append(s[0])
+ drop = tk.OptionMenu(canva, _home, *lista)
+ drop.config(bg="#cc6600", fg="#fff") # 0c3251
+ drop["menu"].config(bg="#cc6600", fg="#fff") # 0c3251
+ if not len(polist):
+ canva.create_window(220, 150, window=drop)
+ else:
+ canva.create_window(220, 550, window=drop)
+
+ hosav = HoverButton(text="→", command=partial(_setHome, _home), bg="#cc6600", fg="#fff", activebackground="#ee9933")
+ if not len(polist):
+ canva.create_window(375, 150, window=hosav)
+ else:
+ canva.create_window(375, 550, window=hosav)
+
+ ## Iterate over polist and pick the first entry if possible
+ if len(polist):
+ e=polist[0]
+ ## Add the original text
+ label1 = tk.Text(root, state="normal", width=50, height=3, background="#0c2241", foreground="#fff", wrap="word")
+ #label1.config(font=('helvetica', 14))
+ label1.insert("end", e.msgid)
+ label1["state"]="disabled"
+ canva.create_window(220, 40, window=label1)
+
+ ## Add the translation text
+ entry1 = tk.Text(root, state="normal", width=50, height=3, background="#0c2241", foreground="#fff", wrap="word")
+ try:
+ entry1.insert("end", ttl.translate(str(e.msgid), src='en', dest='pt_BR').text)
+ except:
+ traceback.print_exc()
+ pass
+ #entry1.config(font=('helvetica', 14), bg="#ccc")
+ canva.create_window(220, 120, window=entry1)
+
+ ## Add the text comment (original text)
+ label3=tk.Text(root, state="normal", width=62, height=4, background="#0c3251", foreground="#fff", wrap="word")
+ try:
+ label3.insert("end", e.comment)
+ except:
+ label3.insert("end", "--")
+ label3.config(font=('monospace', 10))
+ label3["state"]="disabled"
+ canva.create_window(300, 300, window=label3)
+
+ ## Report where the original text is
+ label4 = tk.Label(root, text=e.occurrences, bg="#0c3251", fg="#fff", width=62)
+ label4.config(font=('helvetica', 14))
+ canva.create_window(300, 362, window=label4)
+
+ button1 = HoverButton(text='Save', command=partial(save, entry1), bg="#cc6600", fg="#fff", activebackground="#ee9933")
+ canva.create_window(300, 500, window=button1)
+ return
+
+# Perpetual loop
+_build_screen()
+root.mainloop()
+print("\033[33;1mThanks for translating!\033[0m")
+print("Translated %d entries" % cnt)
+print("Final progress: "+str(po.percent_translated())+"%")
+