Skip to content
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

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

zhengkunwang223
Copy link
Member

No description provided.

Copy link

f2c-ci-robot bot commented Jan 14, 2025

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)
}
Copy link
Member

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:

  1. 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.

  2. Initialization of App Structure: There were missing initializations when copying from localAppDefine.AppProperty to new instance of model.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
Copy link
Member

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:

  1. Corrected indentation of the if statement that checks if key == "postgres".

These improvements ensure proper readability and maintainability of the code.

return i.ShortDescZh
}
return i.ShortDescEn
}
Copy link
Member

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:

  1. JSON Unmarshalling: The patch includes json.Unmarshal calls within GetDescription, which allows mapping of strings like "en" or "zh" from a translation map back into their respective language fields (ShortDescEn or ShortDescZh). This is useful for internationalizing applications where descriptions can vary by locale.

  2. Language Selection: After unmarhsalling the descriptions, it selects the appropriate description based on the user's current language setting (common.GetLang(ctx)).

  3. 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.

  4. 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.

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

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

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Jan 14, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wanghe-fit2cloud wanghe-fit2cloud merged commit ca0dc71 into dev Jan 14, 2025
5 of 6 checks passed
@wanghe-fit2cloud wanghe-fit2cloud deleted the pr@dev@website branch January 14, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants