-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Enable Multi-Language Support for Application Installation Forms #7717
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ type AppService struct { | |
type IAppService interface { | ||
PageApp(ctx *gin.Context, req request.AppSearch) (interface{}, error) | ||
GetAppTags(ctx *gin.Context) ([]response.TagDTO, error) | ||
GetApp(key string) (*response.AppDTO, error) | ||
GetApp(ctx *gin.Context, key string) (*response.AppDTO, error) | ||
GetAppDetail(appId uint, version, appType string) (response.AppDetailDTO, error) | ||
Install(ctx context.Context, req request.AppInstallCreate) (*model.AppInstall, error) | ||
SyncAppListFromRemote() error | ||
|
@@ -94,16 +94,15 @@ func (a AppService) PageApp(ctx *gin.Context, req request.AppSearch) (interface{ | |
lang := strings.ToLower(common.GetLang(ctx)) | ||
for _, ap := range apps { | ||
appDTO := &response.AppItem{ | ||
ID: ap.ID, | ||
Name: ap.Name, | ||
Key: ap.Key, | ||
Type: ap.Type, | ||
Icon: ap.Icon, | ||
ShortDescZh: ap.ShortDescZh, | ||
ShortDescEn: ap.ShortDescEn, | ||
Resource: ap.Resource, | ||
Limit: ap.Limit, | ||
} | ||
ID: ap.ID, | ||
Name: ap.Name, | ||
Key: ap.Key, | ||
Type: ap.Type, | ||
Icon: ap.Icon, | ||
Resource: ap.Resource, | ||
Limit: ap.Limit, | ||
} | ||
appDTO.Description = ap.GetDescription(ctx) | ||
appDTOs = append(appDTOs, appDTO) | ||
appTags, err := appTagRepo.GetByAppId(ap.ID) | ||
if err != nil { | ||
|
@@ -166,7 +165,7 @@ func (a AppService) GetAppTags(ctx *gin.Context) ([]response.TagDTO, error) { | |
return res, nil | ||
} | ||
|
||
func (a AppService) GetApp(key string) (*response.AppDTO, error) { | ||
func (a AppService) GetApp(ctx *gin.Context, key string) (*response.AppDTO, error) { | ||
var appDTO response.AppDTO | ||
if key == "postgres" { | ||
key = "postgresql" | ||
|
@@ -176,6 +175,7 @@ func (a AppService) GetApp(key string) (*response.AppDTO, error) { | |
return nil, err | ||
} | ||
appDTO.App = app | ||
appDTO.App.Description = app.GetDescription(ctx) | ||
details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID)) | ||
if err != nil { | ||
return nil, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No significant issues identified in the provided code changes. Here are a few minor adjustments for clarity:
These improvements ensure proper readability and maintainability of the code. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1051,6 +1051,8 @@ func getApps(oldApps []model.App, items []dto.AppDefine) map[string]model.App { | |
app.Key = key | ||
app.ShortDescZh = config.ShortDescZh | ||
app.ShortDescEn = config.ShortDescEn | ||
description, _ := json.Marshal(config.Description) | ||
app.Description = string(description) | ||
app.Website = config.Website | ||
app.Document = config.Document | ||
app.Github = config.Github | ||
|
@@ -1150,14 +1152,32 @@ func handleLocalApp(appDir string) (app *model.App, err error) { | |
err = buserr.WithMap(constant.ErrFileParseApp, map[string]interface{}{"name": "data.yml", "err": err.Error()}, err) | ||
return | ||
} | ||
app = &localAppDefine.AppProperty | ||
appDefine := localAppDefine.AppProperty | ||
app = &model.App{} | ||
app.Name = appDefine.Name | ||
app.TagsKey = append(appDefine.Tags, "Local") | ||
app.Type = appDefine.Type | ||
app.CrossVersionUpdate = appDefine.CrossVersionUpdate | ||
app.Limit = appDefine.Limit | ||
app.Recommend = appDefine.Recommend | ||
app.Website = appDefine.Website | ||
app.Github = appDefine.Github | ||
app.Document = appDefine.Document | ||
|
||
if appDefine.ShortDescZh != "" { | ||
appDefine.Description.Zh = appDefine.ShortDescZh | ||
} | ||
if appDefine.ShortDescEn != "" { | ||
appDefine.Description.En = appDefine.ShortDescEn | ||
} | ||
desc, _ := json.Marshal(appDefine.Description) | ||
app.Description = string(desc) | ||
|
||
app.Key = "local" + appDefine.Key | ||
app.Resource = constant.AppResourceLocal | ||
app.Status = constant.AppNormal | ||
app.Recommend = 9999 | ||
app.TagsKey = append(app.TagsKey, "Local") | ||
app.Key = "local" + app.Key | ||
readMePath := path.Join(appDir, "README.md") | ||
readMeByte, err := fileOp.GetContent(readMePath) | ||
readMeByte, err := fileOp.GetContent(path.Join(appDir, "README.md")) | ||
if err == nil { | ||
app.ReadMe = string(readMeByte) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code has two main issues:
Here is an updated version that addresses these issues: @@ -1051,6 +1051,8 @@ func getApps(oldApps []model.App, items []dto.AppDefine) map[string]model.App {
return oldApps
}
+ // Assuming constant.json defines Description struct
+ type Description struct { Zh string; En string }
+
for _, item := range items {
key := item.GetKey()
- var app model.App
+ // Create a new model.App instance and populate its fields
app := model.App{
Key: key,
ShortDescZh: config.ShortDescZh,
@@ -1159,20 +1159,36 @@ func handleLocalApp(appDir string) (app *model.App, err error) {
readMeByte, err = fileOp.GetContent(path.Join(appDir, "README.md"))
}
if err == nil {
- app.ReadMe = string(readMeByte)
+ // Decode the Markdown README into raw HTML for further processing.
+ // You should implement a markdown-to-html conversion utility like go-md2html here.
+ //
+ // For now, assuming it already returns raw HTML content:
+ app.ReadMe = string(markdownToHtml(readMeByte))
}
apps[key] = app
}
+ return apps, nil Replace the line handling the README reading with appropriate parsing logic based on your project’s requirements. Alternatively, you could use an external library like go-md2html to parse the Markdown directly into raw HTML format. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The differences between the provided code patches are primarily related to adding functionality for handling and translating app descriptions using JSON and Go's built-in JSON library.
Here are some key points:
JSON Unmarshalling: The patch includes
json.Unmarshal
calls withinGetDescription
, which allows mapping of strings like "en" or "zh" from a translation map back into their respective language fields (ShortDescEn
orShortDescZh
). This is useful for internationalizing applications where descriptions can vary by locale.Language Selection: After unmarhsalling the descriptions, it selects the appropriate description based on the user's current language setting (
common.GetLang(ctx)
).Default Behavior: If no match exists in the translation map, the function defaults to returning the translated short description if possible, falling back to English or Chinese as last resort.
Simplicity with Default Values: While this approach enhances localization capabilities, keep in mind that defaulting to English or Chinese might not be ideal unless they are supported at all languages. Adjustments may needed depending on specific use cases and cultural considerations.
Optimization Suggestions:
Performance Considerations: Ensure that accessing and parsing translations efficiently, especially when dealing with large datasets, would also benefit performance.
Error Handling: Currently, error handling around
Unmarshal
is absent, but it should be added to account for malformed JSON data gracefully.Overall, the changes align with modern software development practices aimed at improving internationalization and localization features within an application.