From b410feddd2d93d1a843266c79ebd0caed3364acc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 25 Sep 2025 12:43:59 +0000 Subject: [PATCH] Fix language selection issue - now shows language menu on first run Co-authored-by: longzheng268 <38132402+longzheng268@users.noreply.github.com> --- i18n.py | 3 +++ lang_config.py | 4 ++++ menu.py | 13 ++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/i18n.py b/i18n.py index e0b48a1..63bfbc3 100644 --- a/i18n.py +++ b/i18n.py @@ -16,6 +16,7 @@ TRANSLATIONS = { 'Install permanent SSH', 'Install firmware (from directory "firmware")', '{{{ Other functions }}}', + 'Change language', '[[ Reboot device ]]', 'Exit' ], @@ -52,6 +53,7 @@ TRANSLATIONS = { '安装永久SSH', '安装固件 (从 "firmware" 目录)', '{{{ 其他功能 }}}', + '更改语言', '[[ 重启设备 ]]', '退出' ], @@ -88,6 +90,7 @@ TRANSLATIONS = { 'Установить постоянный SSH', 'Установить прошивку (из папки "firmware")', '{{{ Другие функции }}}', + 'Изменить язык', '[[ Перезагрузить устройство ]]', 'Выход' ], diff --git a/lang_config.py b/lang_config.py index f0fea7f..726ebf7 100644 --- a/lang_config.py +++ b/lang_config.py @@ -28,6 +28,10 @@ def save_config(config): def get_language(): """Get current language setting""" config = load_config() + # Return None if no config file exists or no language is set + # This will trigger the language selection menu + if not os.path.exists(CONFIG_FILE) or 'language' not in config: + return None return config.get('language', 'en') def set_language(lang): diff --git a/menu.py b/menu.py index 0f7a92e..139d15f 100644 --- a/menu.py +++ b/menu.py @@ -16,7 +16,7 @@ gw = gateway.Gateway(detect_device = False, detect_ssh = False) # Check for language preference or show language menu current_lang = lang_config.get_language() -if current_lang not in i18n.get_supported_languages(): +if current_lang is None or current_lang not in i18n.get_supported_languages(): current_lang = lang_config.show_language_menu() def get_header(delim, suffix = ''): @@ -35,7 +35,7 @@ def menu1_show(): if i == 1: # IP address item needs formatting print(' {} - {}'.format(i, item.format(gw.ip_addr))) else: - print(' {} - {}'.format(i if i <= 9 else 0, item)) + print(' {} - {}'.format(i if i <= 10 else 0, item)) def menu1_process(id): if id == 1: @@ -49,7 +49,8 @@ def menu1_process(id): if id == 6: return "install_ssh.py" if id == 7: return "install_fw.py" if id == 8: return "__menu2" - if id == 9: return "reboot.py" + if id == 9: return "__change_language" + if id == 10: return "reboot.py" if id == 0: sys.exit(0) return None @@ -127,6 +128,12 @@ def menu(): if cmd == '__menu2': level = 2 continue + if cmd == '__change_language': + # Show language menu and restart with new language + global current_lang + current_lang = lang_config.show_language_menu() + level = 1 + continue #print("cmd2 =", cmd) if isinstance(cmd, str): result = subprocess.run([sys.executable, cmd])