in this script. add an option to keep log of the translated text in a file. create an option in the window option submenu to toggle this option, and an option to set the log file name.

def load_settings():
    # Load settings from json file
    try:
        with open('settings.json', 'r') as settings_file:
            settings_data = json.load(settings_file)
    except FileNotFoundError:
        settings_data = {}

    return settings_data

def save_settings(key, value):
    # Save settings to the json file
    settings_data = load_settings()
    settings_data[key] = value
    with open('settings.json', 'w') as settings_file:
        json.dump(settings_data, settings_file)

def translate_text(text_to_translate, prompt_template):
    prompt = prompt_template.format(text_to_translate=text_to_translate)
    completion = openai.ChatCompletion.create(
        model="gpt-3.5-turbo-0301",
        temperature=1,
        messages=[
            {
                "role": "user",
                "content": f"{prompt}",
            }
        ],
    )
    translated_text = (
        completion["choices"][0]
        .get("message")
        .get("content")
        .encode("utf8")
        .decode()
    )

    return translated_text

def update_display(display, text):
    display.delete(1.0, tk.END)
    display.insert(tk.END, text)

def clipboard_monitor():
    global prompt_text
    old_clipboard = ""

    while True:
        if not pause_monitoring:
            new_clipboard = pyperclip.paste()

            # Remove line breaks from new_clipboard
            # new_clipboard = new_clipboard.replace('\n', '').replace('\r', '')

            # Compare new_clipboard with old_clipboard to detect changes
            if new_clipboard != old_clipboard and new_clipboard.strip() != untranslated_textbox.get(1.0, tk.END).strip():
                old_clipboard = new_clipboard
                if new_clipboard in translated_dict:
                    translated_text = translated_dict[new_clipboard]
                else:
                    try:
                        prompt_text = prompt_textbox.get(1.0, tk.END).strip()
                        translated_text = translate_text(new_clipboard, prompt_text)
                    except Exception as e:
                        root.after(0, create_error_window, f"Connection Error: {e}")
                        continue

                    translated_dict[new_clipboard] = translated_text

                update_display(untranslated_textbox, new_clipboard)
                update_display(translated_textbox, translated_text)

        time.sleep(1)

def save():
    global prompt_logfile
    global prompt_text
    prompt_text = prompt_textbox.get(1.0, tk.END).strip()
    try:
        with open(prompt_logfile, "w", encoding="utf-8") as f:
            f.write(prompt_text)
    except FileNotFoundError as e:
        save_as()

def save_as():
    global prompt_logfile
    global prompt_text
    prompt_text = prompt_textbox.get(1.0, tk.END).strip()
    prompt_logfile = filedialog.asksaveasfilename(initialdir=os.getcwd(),
                                                title="Save Prompt As",
                                                defaultextension=".txt", 
                                                filetypes=(("Text files", ".txt"), ("All files", ".")))
    if not prompt_logfile:
        return
    save_settings("prompt_logfile", prompt_logfile)
    with open(prompt_logfile, "w", encoding="utf-8") as f:
        f.write(prompt_text)

root = tk.Tk()
root.title("Clipboard Translator")
root.geometry("400x200")

settings_data = load_settings()
openai.api_base = settings_data.get("api_base", "https://api.openai.com/v1")
openai.api_key = settings_data.get("api_key", "")
prompt_logfile = settings_data.get("prompt_logfile", "")
always_on_top = settings_data.get("always_on_top", False)
window_opacity = settings_data.get("window_opacity", 1.0)
font_settings = settings_data.get("font_settings", {"family": "Courier", "size": 10, "color": "black"})
prompt_logfile, prompt_text = open_prompt_file(prompt_logfile)

menu_bar = Menu(root)

# Add Options menu
options_menu = Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="Options", menu=options_menu)
options_menu.add_command(label="Set OpenAI API", command=set_openai_api)

prompt_menu = Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="Prompt", menu=prompt_menu)
prompt_menu.add_command(label="Save", command=save)
prompt_menu.add_command(label="Save As", command=save_as)

root.config(menu=menu_bar)

paned_window = tk.PanedWindow(root, sashrelief="groove", sashwidth=5, orient="horizontal")
paned_window.pack(expand=True, fill="both")
untranslated_textbox = tk.Text(paned_window, wrap="word")
paned_window.add(untranslated_textbox)
translated_textbox = tk.Text(paned_window, wrap="word")
paned_window.add(translated_textbox)
prompt_textbox = tk.Text(paned_window, wrap="word")
paned_window.add(prompt_textbox)
update_display(prompt_textbox, prompt_text)

copy_button = tk.Button(root, text="Copy", command=copy_untranslated)
copy_button.place(relx=0, rely=1, anchor="sw")
retranslate_button = tk.Button(root, text="Retranslate", command=retranslate_text)
retranslate_button.place(relx=0.1, rely=1, anchor="sw")
toggle_button = tk.Button(root, text="Hide", command=toggle_translated, relief=tk.RAISED)
toggle_button.place(relx=0.5, rely=1, anchor="s")
pause_button = tk.Button(root, text="Pause", command=toggle_pause_monitoring, relief=tk.RAISED)
pause_button.place(relx=1, rely=1, anchor="se")

if __name__ == "__main__":
    exe_mode = getattr(sys, 'frozen', False)
    if exe_mode:
        sys.stderr = open("error_log.txt", "w")
    clipboard_monitor_thread = threading.Thread(target=clipboard_monitor)
    clipboard_monitor_thread.start()
    root.mainloop()

    if exe_mode:
        sys.stderr.close()