Skip to content

Conversation

mr-vara
Copy link
Contributor

@mr-vara mr-vara commented May 23, 2025

Proposed changes

This PR introduces a reusable GitHub Actions workflow that automates the translation of .po and .json localization files using Azure AI Translation (Microsoft Translator), followed by creating a pull request with the translated content.

Key Features

  • Supports translation for .po and WordPress-style .json files.
  • Handles translation contexts, intelligently removing trailing context from translations.
  • Uses Azure AI Translation (Microsoft Translator) for accurate and scalable language translation.
  • Accepts an optional text_domain input; defaults to the invoking repository name if not provided.
  • Automatically opens a pull request with the translated content.

Required Secrets (to be passed by child repositories)

  • TRANSLATOR_API_KEY: Azure AI Translation (Microsoft Translator) API Key. (This secret needs to be set on org level)
  • NEWFOLD_ACCESS_TOKEN: GitHub token with repo and pull_request scope for PR creation.

This shared workflow helps maintain translation consistency across multiple repositories, while centralizing the logic for easy maintenance and scalability.

Documentation

AI Translation Workflow Documentation

Copy link

@fralicandro fralicandro left a comment

Choose a reason for hiding this comment

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

I have another question regarding strings that contain placeholders. How does the AI handle them? Have we tested this scenario?

For example, if I have a string like "Order %s completed", where %s could be something like the order number, how is it processed by the AI?

@circlecube circlecube requested a review from desrosj May 28, 2025 14:11
Copy link
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

Left some feedback for you @mr-vara! I have an additional request, a question, and sharing a little research I did.

Request: Could you also open a pull request for one repo that will utilize this to demonstrate how this workflow will be called? That will help me see the full picture.

Question: Are there any reasons why this should be done in a separate pull request than a PR? For example, if a PR changes some text strings, why would we not want the translations to be updated at the same time? If it's a cost issue (repeatedly translating a string that changes multiple times), we could set the workflow up to only run when certain actions are taken (a specific label is applied, the PR receives an approving review, etc.). That would avoid forgetting to update translations, merge them contextually with the associated code changes, make the translation changes available while testing the PR, etc.

One thing that I considered while reviewing is that it seems odd we would need to write our own script to perform the translations. I did some searching, and there are a few actions that seem related but I don't believe fit our specific use case. I also looked at the https://github.com/Azure/cli repository, but that also does not appear to satisfy the requirements.

@mr-vara
Copy link
Contributor Author

mr-vara commented May 29, 2025

I have another question regarding strings that contain placeholders. How does the AI handle them? Have we tested this scenario?

For example, if I have a string like "Order %s completed", where %s could be something like the order number, how is it processed by the AI?

There is no direct way, but we can still provide context for the same in the workaround way.

@mr-vara
Copy link
Contributor Author

mr-vara commented May 29, 2025

Left some feedback for you @mr-vara! I have an additional request, a question, and sharing a little research I did.

Thank you for the review @desrosj I'll address them and will test it in my test repositories and let you know when it is ready for re-review.

Request: Could you also open a pull request for one repo that will utilize this to demonstrate how this workflow will be called? That will help me see the full picture.

I've created one for Bluehost Plugin here.

Question: Are there any reasons why this should be done in a separate pull request than a PR? For example, if a PR changes some text strings, why would we not want the translations to be updated at the same time? If it's a cost issue (repeatedly translating a string that changes multiple times), we could set the workflow up to only run when certain actions are taken (a specific label is applied, the PR receives an approving review, etc.). That would avoid forgetting to update translations, merge them contextually with the associated code changes, make the translation changes available while testing the PR, etc.

I may not be the final decision-maker on this, but I’d like to share the current thinking and invite feedback or suggestions. There are a few reasons why translations are currently handled in a separate pull request:

  1. Separation of Concerns: This approach clearly distinguishes between developer-authored code/content changes and machine-generated translation updates, making each easier to review and track.
  2. Review Process Alignment: Code reviews and reviews of AI-generated translations serve different purposes and may require different expertise. Keeping them separate avoids conflating the two.
  3. Error Handling: In case the translation workflow encounters issues (e.g., API failures, inconsistencies), isolating it in its own PR helps prevent delays or complications in the main development workflow.

Potential Middle Ground:
We can configure the workflow to run on demand (e.g., via a label or manual trigger) on any branch. This would allow flexibility to generate translations earlier in the process if needed—for example, to support end-to-end testing—without making it mandatory for every PR.

Open to thoughts or alternative approaches!

One thing that I considered while reviewing is that it seems odd we would need to write our own script to perform the translations. I did some searching, and there are a few actions that seem related but I don't believe fit our specific use case. I also looked at the https://github.com/Azure/cli repository, but that also does not appear to satisfy the requirements.

I agree with you regarding writing our own script. Yes, it's odd, but I feel we left with no other choices. I'm open to alternative approaches, if we have any.

@desrosj
Copy link
Member

desrosj commented May 30, 2025

@mr-vara

I've created one for Bluehost Plugin newfold-labs/wp-plugin-bluehost#283.

Thanks!

For the reasons to keep translations separate, I think all of those make sense. Especially making the review of the suggested translations from AI a separate and more intentional process. 👍

@mr-vara
Copy link
Contributor Author

mr-vara commented Jun 2, 2025

  1. I have few concerns regarding two suggestions:
    Using cache for Python Setup action: The issue here is, if we use cache, it expects a python project setup, i.e., needs a requirements.txt file and it expect it in the caller repository.
  2. Separating the python code to a independent file: The issue here with reusable workflow is, it expects the python script to be in the caller repository. Here the solution I can see is, we can download the script and delete it before the commit step.

And as per your suggestion in private chat, @desrosj
I'm ignoring the Python cache for the time being. And for the second one:
I'm going to add an additional actions/checkout step to checkout the workflows repository. Something like:

- name: Checkout workflow related scripts
  uses: actions/checkout
  with:
    repository: newfold-labes/workflows
    path: 'workflow-repo' 

I'll make sure to exclude the workflow-repo directory from any translation tasks, and delete the directory immediately after running the script.

I'll test this first in my personal repositories and will update here.

@mr-vara
Copy link
Contributor Author

mr-vara commented Jun 3, 2025

@desrosj I have addressed the suggestions. For the Python script separation, I've downloaded the file instead of checking out to the entire workflows repo. Please let me know if you think otherwise.

@mr-vara mr-vara requested a review from desrosj June 3, 2025 12:36
@desrosj
Copy link
Member

desrosj commented Jun 11, 2025

I'm hoping to re-review this today. @mr-vara I just wanted to check that you're happy with where this is at to avoid any reviews from being dismissed for other small changes.

@mr-vara
Copy link
Contributor Author

mr-vara commented Jun 12, 2025

I'm hoping to re-review this today. @mr-vara I just wanted to check that you're happy with where this is at to avoid any reviews from being dismissed for other small changes.

Yes, @desrosj In fact I have addressed all other changes as well.

Copy link
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

Thanks @mr-vara! Great work. I think that this is really close.

mr-vara and others added 7 commits June 19, 2025 11:18
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
@mr-vara mr-vara requested a review from desrosj June 20, 2025 04:52
Copy link
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

Looks good, @mr-vara! Thanks for all of your work on this.

@mr-vara mr-vara merged commit 197c261 into main Jun 23, 2025
10 checks passed
@mr-vara mr-vara deleted the PRESS11-157 branch June 23, 2025 05:56
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.

5 participants