-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This code has two main issues:
-
Handling JSON Marshal Errors: The
json.Marshal
function call to convert the description into bytes may fail if there are issues with converting a nested interface. It's best practice to handle this explicitly by checking the returned error. -
Initialization of App Structure: There were missing initializations when copying from
localAppDefine.AppProperty
to new instance ofmodel.App
. This can lead to uninitialized fields which might cause undefined behavior.
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.
@@ -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 comment
The 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:
- Corrected indentation of the
if
statement that checks ifkey == "postgres"
.
These improvements ensure proper readability and maintainability of the code.
return i.ShortDescZh | ||
} | ||
return i.ShortDescEn | ||
} |
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.
Quality Gate passedIssues Measures |
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.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
No description provided.