Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Jul 30, 2025

支持基于当前仓库内的文件进行扫描并生成 transifex.yaml 配置文件

Log:

Summary by Sourcery

Add a new CLI subcommand to automatically scan translation files in the repository and generate a Transifex configuration file.

New Features:

  • Introduce a "gentxyaml" command to scan .ts and .po files and generate a transifex.yaml
  • Automatically identify source translation files based on language code patterns and related translations
  • Generate and serialize TransifexYaml with filters and branch settings

Enhancements:

  • Integrate the new command into the CLI and error handling flow
  • Use walkdir for recursive file discovery and regex for language code detection

Build:

  • Add walkdir dependency for directory traversal

Tests:

  • Add comprehensive unit tests for language code detection, translation pattern extraction, and expression generation in gentxyaml module

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia

The full list of commands accepted by this bot can be found here.

Details 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

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 30, 2025

Reviewer's Guide

Introduces a new gentxyaml CLI command that walks the project directory to locate translation files, uses regex-based heuristics to pick source files and derive language patterns, constructs a Transifex YAML config, and writes (or prints) it; includes dependency, module, and test updates.

Sequence diagram for gentxyaml CLI command execution

sequenceDiagram
    actor User
    participant CLI as CLI
    participant gentxyaml as gentxyaml::subcmd_gentxyaml
    participant FS as FileSystem
    participant Yaml as serde_yml

    User->>CLI: te gentxyaml <project_root>
    CLI->>gentxyaml: subcmd_gentxyaml(project_root)
    gentxyaml->>FS: scan_all_translation_files(project_root)
    FS-->>gentxyaml: List of translation files
    gentxyaml->>gentxyaml: identify_source_files(project_root, files)
    gentxyaml->>gentxyaml: generate_transifex_yaml(project_root, source_files)
    gentxyaml->>Yaml: to_string(tx_yaml)
    Yaml-->>gentxyaml: YAML string
    alt transifex.yaml exists
        gentxyaml->>CLI: Print YAML to stdout
    else
        gentxyaml->>FS: Write transifex.yaml
        FS-->>gentxyaml: Success
        gentxyaml->>CLI: Print success message
    end
    CLI-->>User: Output result
Loading

File-Level Changes

Change Details Files
Add new CLI command for generating transifex.yaml
  • Added GenTxYaml variant to Commands enum
  • Wired command execution to call subcmd_gentxyaml
src/cli.rs
Expose the gentxyaml subcommand in the module
  • Declared pub mod gentxyaml
  • Re-exported subcmd_gentxyaml
src/subcmd.rs
Add WalkDir dependency for filesystem scanning
  • Added walkdir = "2.5.0" to Cargo.toml
Cargo.toml
Implement gentxyaml subcommand with scanning, heuristics, and YAML output
  • Scan .ts and .po files using WalkDir and I18nFileKind
  • Identify source files via language-code and directory heuristics
  • Generate TransifexYaml filters and produce the output file or console preview
src/subcmd/gentxyaml.rs
Cover language detection and YAML logic with tests
  • Added unit tests for language code detection, pattern extraction, and expression generation
src/subcmd/gentxyaml.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @BLumia - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

支持基于当前仓库内的文件进行扫描并生成 transifex.yaml 配置文件

Log:
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码重复is_language_code 函数在 get_translation_patternfind_language_codes_in_filename 中被调用,可以考虑将这个函数提取到一个公共模块中,以避免重复代码。

  2. 错误处理:在 generate_transifex_yaml 函数中,当 I18nFileKind::from_ext_hint 返回错误时,应该提供更详细的错误信息,以便于调试。

  3. 性能优化:在 find_language_codes_in_path 函数中,对 codes 进行排序和去重操作,这可能会影响性能,特别是在处理大量文件时。可以考虑使用更高效的数据结构或算法来优化这部分代码。

  4. 代码可读性generate_translation_expression 函数中的逻辑较为复杂,可以考虑将其拆分成多个小函数,每个函数负责一个具体的任务,以提高代码的可读性和可维护性。

  5. 测试用例tests 模块中的测试用例覆盖了大部分功能,但是缺少对错误处理和边界条件的测试。建议增加更多的测试用例,以确保代码的健壮性。

  6. 代码风格:在 generate_translation_expression 函数中,使用了多个 else if 语句来处理不同的文件名模式。可以考虑使用 match 语句来提高代码的可读性。

  7. 依赖管理:在 Cargo.toml 文件中添加了 walkdirsame-file 依赖,但是没有更新相应的文档或注释来解释这些依赖的用途。建议在文档中添加说明,以便其他开发者理解这些依赖的作用。

  8. 安全性:代码中没有明显的安全漏洞,但是建议定期更新依赖,以防止已知的安全问题。

总体来说,代码逻辑清晰,功能实现正确,但是存在一些可以优化的地方。建议在未来的开发中,注意代码的可读性、可维护性和性能优化。

@BLumia BLumia merged commit be161df into master Jul 30, 2025
9 checks passed
@BLumia BLumia deleted the gentxyaml branch July 30, 2025 09:33
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.

3 participants