Skip to content

feat: placeholder normalization and validation in library#3

Merged
WendellXY merged 5 commits intomainfrom
feat/placeholders
Sep 1, 2025
Merged

feat: placeholder normalization and validation in library#3
WendellXY merged 5 commits intomainfrom
feat/placeholders

Conversation

@WendellXY
Copy link
Copy Markdown
Collaborator

Adds placeholder parsing, normalization (%@ → %s, %1 → %1, %ld/%lu → %d/%u) and validation APIs to the lib. Provides optional normalization in conversions, tests, and docs examples. Updates ROADMAP accordingly.

Introduces a new placeholder module for parsing, normalizing, and validating placeholders across languages and plural forms. Adds `validate_placeholders` to `Codec` to ensure consistency of placeholder signatures, with tests for both matching and mismatched cases. Updates exports in lib.rs to include the new utilities.
Implements methods for normalizing placeholders across translations and collecting placeholder issues, with strict and non-strict validation modes. Updates the roadmap to mark placeholder normalization and validation as complete, and adds tests for the new methods.
Introduces convert_with_normalization and convert_auto_with_normalization functions to optionally normalize iOS-style placeholders (e.g., %@, %1$@, %ld) to canonical forms before serialization. Updates documentation and tests to demonstrate usage. Also improves Codec API docs with usage examples for placeholder validation and normalization.
Copilot AI review requested due to automatic review settings September 1, 2025 10:05
Comment thread langcodec/src/codec.rs Fixed
Comment thread langcodec/src/codec.rs Fixed
Comment thread langcodec/src/converter.rs Fixed
Comment thread langcodec/src/converter.rs Fixed
Comment thread langcodec/src/converter.rs Fixed
Comment thread langcodec/src/placeholder.rs Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds comprehensive placeholder normalization and validation functionality to the langcodec library. This enables cross-platform compatibility by normalizing iOS placeholder formats (%@, %1$@, %ld) to canonical Android-compatible forms (%s, %1$s, %d/%u) and provides validation to ensure placeholder consistency across languages.

  • Introduces a new placeholder module with parsing, normalization and signature extraction capabilities
  • Adds optional normalization to conversion functions with new convert_with_normalization and convert_auto_with_normalization APIs
  • Implements placeholder validation methods in the Codec for detecting cross-language inconsistencies

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
langcodec/src/placeholder.rs New module containing placeholder parsing, normalization, and signature generation logic
langcodec/src/lib.rs Exports new placeholder functions and updated conversion APIs
langcodec/src/converter.rs Adds normalization variants of convert functions and comprehensive test coverage
langcodec/src/codec.rs Implements placeholder validation and normalization methods in the Codec struct
ROADMAP.md Updates milestone status to reflect completed placeholder normalization feature
Comments suppressed due to low confidence (2)

langcodec/src/converter.rs:282

  • This helper closure is duplicated between the original convert function and convert_with_normalization. Consider extracting it to a shared helper function to reduce code duplication.
    let pick_resource = |lang: Option<String>| -> Option<Resource> {
        match lang {
            Some(l) => resources.iter().find(|r| r.metadata.language == l).cloned(),
            None => resources.first().cloned(),
        }
    };

langcodec/src/converter.rs:1

  • The placeholder validation logic in validate_placeholders and collect_placeholder_issues is nearly identical. Consider extracting the common logic into a shared helper function to reduce duplication.
//! Format conversion utilities for langcodec.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread langcodec/src/placeholder.rs Outdated
Comment thread langcodec/src/placeholder.rs Outdated
Comment thread langcodec/src/converter.rs Outdated
Comment thread langcodec/src/converter.rs Outdated
Simplifies iteration over plural forms in codec.rs by using values() and values_mut() instead of iterating with keys. In converter.rs, removes unnecessary to_path_buf() conversions and passes input/output as references, and consistently removes redundant references in read_from and write_to calls. Also removes an unused function in placeholder.rs.
Refactors placeholder normalization logic to handle positional iOS object placeholders more robustly, ensuring %<n>$@ is converted to %<n>$s. Also improves code formatting and consistency across modules, and reorders some imports for clarity. No functional changes outside of placeholder normalization and code style.
@WendellXY WendellXY merged commit 0626de7 into main Sep 1, 2025
7 checks passed
@WendellXY WendellXY deleted the feat/placeholders branch September 1, 2025 11:04
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