@@ -17,6 +17,7 @@ import (
1717 "github.com/toeirei/keymaster/internal/model"
1818
1919 tea "github.com/charmbracelet/bubbletea"
20+ "github.com/spf13/viper"
2021)
2122
2223// viewState represents which part of the UI is currently active.
@@ -263,6 +264,23 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
263264 i18n .T ("menu.view_audit_log" ),
264265 i18n .T ("menu.view_accounts_by_tag" ),
265266 }
267+ // Save the new language setting
268+ viper .Set ("language" , i18n .GetLang ())
269+ if err := viper .WriteConfig (); err != nil {
270+ // This is not a fatal error, so we just note it.
271+ // The language will still change for the current session.
272+ m .err = fmt .Errorf ("could not save language setting: %w" , err )
273+ }
274+ // Re-initialize models that depend on i18n strings
275+ m .menu .choices = []string {
276+ i18n .T ("menu.manage_accounts" ),
277+ i18n .T ("menu.manage_public_keys" ),
278+ i18n .T ("menu.assign_keys" ),
279+ i18n .T ("menu.rotate_system_keys" ),
280+ i18n .T ("menu.deploy_to_fleet" ),
281+ i18n .T ("menu.view_audit_log" ),
282+ i18n .T ("menu.view_accounts_by_tag" ),
283+ }
266284 return m , nil
267285 }
268286 }
@@ -394,6 +412,9 @@ func (m menuModel) View(data dashboardData, width int) string {
394412
395413// Run is the main entrypoint for the TUI. It initializes and runs the Bubble Tea program.
396414func Run () {
415+ // Initialize i18n with the language from config
416+ i18n .Init (viper .GetString ("language" ))
417+
397418 if _ , err := tea .NewProgram (initialModel ()).Run (); err != nil {
398419 fmt .Printf ("Alas, there's been an error: %v" , err )
399420 os .Exit (1 )
0 commit comments