Skip to content

feat(system): add prefer language during initialization#1236

Merged
looplj merged 1 commit intolooplj:release/v0.9.xfrom
myml:fix-i18n
Apr 1, 2026
Merged

feat(system): add prefer language during initialization#1236
looplj merged 1 commit intolooplj:release/v0.9.xfrom
myml:fix-i18n

Conversation

@myml
Copy link
Copy Markdown
Contributor

@myml myml commented Apr 1, 2026

Captures the user's language preference during system initialization and sets it on the owner account. Defaults to English if not specified.

现在首次登录后,自动切换到英文了,导致无法查看到中文的引导教程(要关闭教程弹窗才能切换语言)。

Captures the user's language preference during system initialization
and sets it on the owner account. Defaults to English if not specified.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a 'preferLanguage' field to the system initialization process, allowing users to set their preferred language during setup. The changes span the frontend initialization form, API request structures, and the backend business logic. I have reviewed the implementation and suggest refactoring the default language handling in the business layer to avoid hardcoding 'en' and instead rely on the database schema defaults or conditional setting, as shown in the provided suggestion.

Comment on lines +411 to 423
preferLanguage := params.PreferLanguage
if preferLanguage == "" {
preferLanguage = "en" // Default to English if not specified
}
user, err := tx.User.Create().
SetEmail(params.OwnerEmail).
SetPassword(hashedPassword).
SetFirstName(params.OwnerFirstName).
SetLastName(params.OwnerLastName).
SetPreferLanguage(preferLanguage).
SetIsOwner(true).
SetScopes([]string{"*"}). // Give owner all scopes
Save(ctx)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The default language "en" is hardcoded here, which duplicates the default value already defined in the User schema. It's better to let the database default handle it if the parameter is empty. This improves maintainability by centralizing the default value in the schema definition and avoiding redundant logic in the business layer.

Suggested change
preferLanguage := params.PreferLanguage
if preferLanguage == "" {
preferLanguage = "en" // Default to English if not specified
}
user, err := tx.User.Create().
SetEmail(params.OwnerEmail).
SetPassword(hashedPassword).
SetFirstName(params.OwnerFirstName).
SetLastName(params.OwnerLastName).
SetPreferLanguage(preferLanguage).
SetIsOwner(true).
SetScopes([]string{"*"}). // Give owner all scopes
Save(ctx)
userCreate := tx.User.Create().
SetEmail(params.OwnerEmail).
SetPassword(hashedPassword).
SetFirstName(params.OwnerFirstName).
SetLastName(params.OwnerLastName).
SetIsOwner(true).
SetScopes([]string{"*"}) // Give owner all scopes
if params.PreferLanguage != "" {
userCreate.SetPreferLanguage(params.PreferLanguage)
}
user, err := userCreate.Save(ctx)

@looplj looplj merged commit d06f7d6 into looplj:release/v0.9.x Apr 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants