Skip to content

Conversation

@az-smartling
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 mt translate and mt detect commands to include the translated file name, and modifies the table row generation logic to properly handle multiple target locales. This enhancement provides more detailed information about the translated files and ensures accurate representation of data when multiple target locales are involved.

Highlights

  • Output Format Update: The output format for both mt translate and mt detect commands has been updated to include a new TranslatedFile field.
  • Template Modification: The default translate template now includes the TranslatedFile field, providing more comprehensive output information.
  • Row Generation Logic: The logic for generating table rows in both detect and translate commands has been modified to account for multiple target locales, ensuring each locale has its own row.
  • Data Provider Interface: The TableDataProvider interface and its implementations now include a targetLocalesQnt parameter in the ToTableRows method, allowing for dynamic row generation based on the number of target locales.
  • Update Struct: The TranslateUpdates struct was updated to include TranslatedFile field.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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

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.

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))

Choose a reason for hiding this comment

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

high

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.

Suggested change
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)

Choose a reason for hiding this comment

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

high

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.

Suggested change
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)

Choose a reason for hiding this comment

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

high

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.

Suggested change
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)

Choose a reason for hiding this comment

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

high

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.

Suggested change
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)

Choose a reason for hiding this comment

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

high

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

Suggested change
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)

Choose a reason for hiding this comment

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

medium

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.

Suggested change
render := output.InitRender(outputParams, dataProvider, files, 1)
render := output.InitRender(outputParams, dataProvider, files, 1)

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