import unicodedata
from tkinter import *
def normalize(text):
text = text.lower()
text = unicodedata.normalize('NFD', text)
text = ''.join(c for c in text if unicodedata.category(c) != 'Mn')
text = text.replace("ç", "c").replace("ã", "an").replace("õ", "on")
text = text.replace("á", "a").replace("é", "e").replace("í", "i")
text = text.replace("ó", "o").replace("ú", "u")
return text
# Mapeamento fonético (resumido, pode expandir mais)
katakana_map = {
"a": "ア", "i": "イ", "u": "ウ", "e": "エ", "o": "オ",
"ão": "アン", "on": "オン", "om": "オン",
"nh": "ニャ", "lh": "リャ", "ch": "チ",
"qu": "ク", "gu": "グ",
"jo": "ジョ", "ja": "ジャ", "ju": "ジュ", "je": "ジェ", "ji": "ジ",
"ti": "チ", "tu": "トゥ", "di": "ジ", "gi": "ジ",
"ka": "カ", "ki": "キ", "ku": "ク", "ke": "ケ", "ko": "コ",
"sa": "サ", "shi": "シ", "su": "ス", "se": "セ", "so": "ソ",
"ta": "タ", "te": "テ", "to": "ト",
"na": "ナ", "ni": "ニ", "nu": "ヌ", "ne": "ネ", "no": "ノ",
"ma": "マ", "mi": "ミ", "mu": "ム", "me": "メ", "mo": "モ",
"ra": "ラ", "ri": "リ", "ru": "ル", "re": "レ", "ro": "ロ",
"n": "ン",
}
def to_katakana(name):
name = normalize(name)
result = ""
i = 0
while i < len(name):
if i + 2 < len(name) and name[i:i+3] in katakana_map:
result += katakana_map[name[i:i+3]]
i += 3
elif i + 1 < len(name) and name[i:i+2] in katakana_map:
result += katakana_map[name[i:i+2]]
i += 2
elif name[i] in katakana_map:
result += katakana_map[name[i]]
i += 1
elif name[i] == " ":
result += " "
i += 1
else:
i += 1
return result
# GUI
root = Tk()
root.geometry("700x380")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Converter nome para japonês")
titulo = Label(text="Converter nome para japonês",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.13, rely=0.05)
texto_sub1 = Label(text="Nome:",
font=("Arial", 22, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.28)
Nome = StringVar()
Nome_entrada = Entry(textvariable=Nome,
font=("Arial", 14, "bold"),
bg="white", fg="blue", justify='center')
Nome_entrada.place(relx=0.4, rely=0.3, relwidth=0.4)
def limpar():
Nome_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
nome = Nome.get()
mensagem = f"{nome} → {to_katakana(nome)}"
resultado_texto.config(text=mensagem, font=("Arial", 18, "bold"))
def copiar():
texto = resultado_texto.cget("text")
if texto:
root.clipboard_clear()
root.clipboard_append(texto)
root.update()
but1 = Button(text="Converter", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, rely=0.55, relwidth=0.2, relheight=0.12)
but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.3, rely=0.55, relwidth=0.2, relheight=0.12)
but_copiar = Button(text="Copiar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=copiar)
but_copiar.place(relx=0.55, rely=0.55, relwidth=0.2, relheight=0.12)
but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.8, rely=0.55, relwidth=0.15, relheight=0.12)
resultado_texto = Label(text="", font=("Arial", 18, "bold"), bg="#cfe2f3", fg="black")
resultado_texto.place(relx=0.05, rely=0.73, relwidth=0.9, relheight=0.2)
root.mainloop()