feat: placeholder normalization and validation in library#3
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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_normalizationandconvert_auto_with_normalizationAPIs - 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
convertfunction andconvert_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_placeholdersandcollect_placeholder_issuesis 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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.