-
Notifications
You must be signed in to change notification settings - Fork 9
update output format for mt translate #90
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
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @az-smartling, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request updates the output format for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
The pull request introduces changes to the output format for machine translation (MT) commands, specifically enhancing the translate and detect functionalities to include TranslatedFile in the output. This involves modifying InitRender calls, updating toDetectTableRows and toTranslateTableRows functions to handle targetLocalesQnt, and adjusting TranslateUpdates struct and related logic to track translated file paths. The changes are well-contained and address the stated objective of updating the output format.
output/mt/detect.go
Outdated
| func toDetectTableRows(files []string) []table.Row { | ||
| res := make([]table.Row, len(files)) | ||
| func toDetectTableRows(files []string, targetLocalesQnt uint8) []table.Row { | ||
| res := make([]table.Row, len(files)+int(targetLocalesQnt)) |
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 calculation for res slice length len(files) + int(targetLocalesQnt) seems incorrect for the nested loop logic that follows. If targetLocalesQnt is meant to multiply the number of files, the length should be len(files) * int(targetLocalesQnt). Currently, this could lead to an index out of range error if targetLocalesQnt is greater than 1, as the inner loop attempts to write to 2*i + int(j) which can exceed the allocated slice size.
| res := make([]table.Row, len(files)+int(targetLocalesQnt)) | |
| res := make([]table.Row, len(files)*int(targetLocalesQnt)) |
| for i, v := range files { | ||
| res[i] = toDetectTableRow(v) | ||
| for j := uint8(0); j < targetLocalesQnt; j++ { | ||
| res[2*i+int(j)] = toDetectTableRow(v) |
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 index 2*i+int(j) for res seems problematic. If targetLocalesQnt is greater than 1, this index calculation will likely skip rows or overwrite existing ones, and potentially cause an index out of range error if the slice length calculation in line 64 is not len(files) * int(targetLocalesQnt). A more robust indexing would be i*int(targetLocalesQnt) + int(j) to ensure each file-locale combination gets a unique row.
| res[2*i+int(j)] = toDetectTableRow(v) | |
| res[i*int(targetLocalesQnt)+int(j)] = toDetectTableRow(v) |
| for i, v := range files { | ||
| res[i] = toTranslateTableRow(v) | ||
| for j := uint8(0); j < targetLocalesQnt; j++ { | ||
| res[2*i+int(j)] = toTranslateTableRow(v) |
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.
Similar to output/mt/detect.go, the index 2*i+int(j) for res is likely incorrect. This indexing scheme will lead to incorrect row assignments or out-of-bounds errors if targetLocalesQnt is greater than 1. The correct index should be i*int(targetLocalesQnt) + int(j) to ensure each file-locale pair is assigned to a distinct row.
| res[2*i+int(j)] = toTranslateTableRow(v) | |
| res[i*int(targetLocalesQnt)+int(j)] = toTranslateTableRow(v) |
|
|
||
| update.Locale = pointer.NewP(strings.Join(localeIDs, ",")) | ||
| updates <- update | ||
| update.ID = uint32(fileID + updateID) |
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 update.ID is calculated as uint32(fileID + updateID). This assumes a simple linear mapping which might not be correct if fileID and updateID are not sequential or if updateID is an index within LocaleProcessStatuses for a given fileID. If updateID is meant to represent the index of the locale for the current file, then the ID should probably be uint32(fileID*len(params.TargetLocales) + updateID) to correctly map to the res slice in toTranslateTableRows.
| update.ID = uint32(fileID + updateID) | |
| update.ID = uint32(fileID*len(params.TargetLocales) + updateID) |
| if err := saveToFile(reader, filepath.Join(outputDirectory, filepath.Base(filenameLocale))); err != nil { | ||
| return nil, err | ||
| } | ||
| update.ID = uint32(fileID + updateID) |
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 update.ID here is calculated as uint32(fileID + updateID). This is the same potential issue as identified on line 178. For consistency and correctness with how rows are generated in toTranslateTableRows, this calculation should likely be uint32(fileID*len(params.TargetLocales) + updateID).
| update.ID = uint32(fileID + updateID) | |
| update.ID = uint32(fileID*len(params.TargetLocales) + updateID) |
| } | ||
| var dataProvider output.DetectDataProvider | ||
| render := output.InitRender(outputParams, dataProvider, files) | ||
| render := output.InitRender(outputParams, dataProvider, files, 1) |
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 targetLocalesQnt parameter is hardcoded to 1 here. While detect might only ever deal with a single target locale (or rather, a single detected source language), it's generally better to derive this value dynamically if possible, or at least add a comment explaining why it's 1 to improve clarity and maintainability.
| render := output.InitRender(outputParams, dataProvider, files, 1) | |
| render := output.InitRender(outputParams, dataProvider, files, 1) |
No description provided.