use a single set_language function for setting and changing language

This commit is contained in:
Alfred Kamanda 2024-09-17 15:26:50 +03:00
parent dc14480519
commit 065c8e5c1d
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703
5 changed files with 11 additions and 34 deletions

View File

@ -84,7 +84,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
if err != nil { if err != nil {
return nil, err return nil, err
} }
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@ -116,7 +116,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@ -54,7 +54,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
if err != nil { if err != nil {
return nil, err return nil, err
} }
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@ -86,7 +86,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@ -44,7 +44,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
if err != nil { if err != nil {
return nil, err return nil, err
} }
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@ -76,7 +76,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@ -39,7 +39,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
return nil, err return nil, err
} }
ussdHandlers = ussdHandlers.WithPersister(pe) ussdHandlers = ussdHandlers.WithPersister(pe)
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@ -75,7 +75,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp) rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@ -121,15 +121,15 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource
// SetLanguage sets the language across the menu // SetLanguage sets the language across the menu
func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result
var err error
inputStr := string(input) sym, _ = h.st.Where()
switch inputStr {
case "0": switch sym {
res.FlagSet = []uint32{state.FLAG_LANG} case "set_default":
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "eng" res.Content = "eng"
case "1": case "set_swa":
res.FlagSet = []uint32{state.FLAG_LANG} res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "swa" res.Content = "swa"
default: default:
} }
@ -1045,22 +1045,3 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte)
return res, nil return res, nil
} }
// SetNewLanguage sets the new language based on user input
func (h *Handlers) SetNewLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
inputStr := string(input)
switch inputStr {
case "0":
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "eng"
case "1":
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "swa"
default:
}
return res, nil
}