jason810496 opened a new pull request, #55917: URL: https://github.com/apache/airflow/pull/55917
related: #55604 ## Why As noted in https://github.com/apache/airflow/pull/55604#pullrequestreview-3221382716, integrating Copilot can help us automatically translate from the source language (English). ## What This change integrates Copilot with the `dev/i18n/copilot_translations.py` script. 1. Added the `--translate-with-copilot` flag: This will translate only the `TODO` entries. Please ensure you run `--add-missing` beforehand. ```bash uv run dev/i18n/check_translations_completeness.py --language zh-TW --translate-with-copilot ``` 2. Added the `--with-copilot` flag, which can be used together with the existing `--add-missing` flag: This will add `TODO` entries and translate them in the same CLI run. ```bash uv run dev/i18n/check_translations_completeness.py --language zh-TW --add-missing --with-copilot ``` ## How I used [B00TK1D/copilot-api](https://github.com/B00TK1D/copilot-api/tree/main) as a reference and refactored it to be class-based and more robust, including retry logic for API calls and improved error handling. The authentication flow for the Copilot Translator is as follows: 1. Obtain a Copilot Access Token: - This requires opening a browser and entering a device code. - The Copilot Access Token will be saved as `.copilot_token`. - Alternatively, users can copy their own Copilot Access Token and save it as `.copilot_token`. 2. Obtain a Copilot Session Token (short-lived; it will auto-refresh if a 401 error is encountered). 3. Use the Copilot Codex API for translation. The prompts are structured as follows: ``` dev/i18n/prompts ├── global.jinja2 └── locales └── zh-TW.jinja2 ``` The translation flow for a given language path is: 1. Initialize the `context: str` variable as an empty string. 2. Recursively traverse the JSON structure, updating the context with the current key (`context=f"{context}.{key}"`). 3. If a value starts with `TODO: translate:`, call Copilot to translate the value: 1. Retrieve the language name. 2. Load the global template as the prompt template. 3. Render the prompt with `language_name`, `value`, `key`, and `context`. 4. Append the language-specific prompt if available. ## Demo https://github.com/user-attachments/assets/68d5b694-bafa-483f-921c-7ec548f41557 ## Future Work - Documentaion - Refine the global prompt for better translation quality. - Improve prompts for each language (depends on language reviewers). - Add a new flag or command to create a PR via script. - Support a `--language all` flag to create PRs for all languages at once. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org