Skip to content

Commit 16d011e

Browse files
committed
chore(fmt): workspace
1 parent 5f65590 commit 16d011e

7 files changed

Lines changed: 53 additions & 36 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ This is a `0.4.0` release available on [crates.io](https://crates.io/crates/lang
6161
- Stats (JSON): `langcodec stats -i Localizable.xcstrings --json`
6262
- See full options: langcodec-cli/README.md#stats
6363
- Example output:
64+
6465
```json
6566
{
6667
"summary": { "languages": 1, "unique_keys": 42 },

langcodec-cli/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ fn main() {
191191
},
192192
);
193193
}
194-
Commands::View { input, lang, full, check_plurals } => {
194+
Commands::View {
195+
input,
196+
lang,
197+
full,
198+
check_plurals,
199+
} => {
195200
// Create validation context
196201
let mut context = ValidationContext::new().with_input_file(input.clone());
197202

langcodec-cli/src/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use langcodec::{collect_resource_plural_issues, Codec, types::EntryStatus};
1+
use langcodec::{Codec, collect_resource_plural_issues, types::EntryStatus};
22
use serde_json::json;
33
use std::collections::HashMap;
44

langcodec-cli/tests/plural_validation_cli_tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ fn test_cli_view_check_plurals_fails_on_missing() {
3838
String::from_utf8_lossy(&output.stdout)
3939
);
4040
let stderr = String::from_utf8_lossy(&output.stderr);
41-
assert!(stderr.contains("Plural validation failed"), "stderr: {}", stderr);
41+
assert!(
42+
stderr.contains("Plural validation failed"),
43+
"stderr: {}",
44+
stderr
45+
);
4246
}
4347

4448
#[test]

langcodec/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Universal localization file toolkit for Rust. Parse, write, convert, merge.
1313
langcodec = "0.4.0"
1414
```
1515

16-
Docs: https://docs.rs/langcodec
16+
Docs: <https://docs.rs/langcodec>
1717

1818
## Quick Start
1919

langcodec/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ pub mod converter;
143143
pub mod error;
144144
pub mod formats;
145145
pub mod placeholder;
146+
pub mod plural_rules;
146147
pub mod traits;
147148
pub mod types;
148-
pub mod plural_rules;
149149

150150
// Re-export most used types for easy consumption
151151
pub use crate::{
@@ -160,8 +160,8 @@ pub use crate::{
160160
formats::FormatType,
161161
placeholder::{extract_placeholders, normalize_placeholders, signature},
162162
plural_rules::{
163-
autofix_fill_missing_from_other_resource, collect_resource_plural_issues,
164-
required_categories_for_str, validate_resource_plurals, PluralValidationReport,
163+
PluralValidationReport, autofix_fill_missing_from_other_resource,
164+
collect_resource_plural_issues, required_categories_for_str, validate_resource_plurals,
165165
},
166166
types::{
167167
ConflictStrategy, Entry, EntryStatus, Metadata, Plural, PluralCategory, Resource,

langcodec/src/plural_rules.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
types::{EntryStatus, Plural, PluralCategory, Resource, Translation},
88
};
99

10-
use serde::Serialize;
1110
use lazy_static::lazy_static;
11+
use serde::Serialize;
1212

1313
lazy_static! {
1414
/// Static mapping from base language subtag → required plural categories (CLDR‑style, cardinals).
@@ -91,21 +91,20 @@ pub struct PluralValidationReport {
9191
pub fn required_categories_for(lang: &LanguageIdentifier) -> BTreeSet<PluralCategory> {
9292
// Base language subtag only for rule selection
9393
let lang_str = lang.language.as_str();
94-
CATEGORY_TABLE
95-
.get(lang_str)
96-
.cloned()
97-
.unwrap_or_else(|| {
98-
// Conservative default to avoid noisy validation for unknown locales
99-
let mut s = BTreeSet::new();
100-
s.insert(PluralCategory::Other);
101-
s
102-
})
94+
CATEGORY_TABLE.get(lang_str).cloned().unwrap_or_else(|| {
95+
// Conservative default to avoid noisy validation for unknown locales
96+
let mut s = BTreeSet::new();
97+
s.insert(PluralCategory::Other);
98+
s
99+
})
103100
}
104101

105102
/// Helper for string language codes (accepts underscores, normalizes to hyphen).
106103
pub fn required_categories_for_str(lang: &str) -> BTreeSet<PluralCategory> {
107104
let normalized = lang.replace('_', "-");
108-
let parsed: LanguageIdentifier = normalized.parse().unwrap_or_else(|_| "und".parse().unwrap());
105+
let parsed: LanguageIdentifier = normalized
106+
.parse()
107+
.unwrap_or_else(|_| "und".parse().unwrap());
109108
required_categories_for(&parsed)
110109
}
111110

@@ -177,7 +176,9 @@ pub fn validate_resource_plurals(resource: &Resource) -> Result<(), Error> {
177176
///
178177
/// Returns the number of categories added across the resource.
179178
pub fn autofix_fill_missing_from_other_resource(resource: &mut Resource) -> usize {
180-
let Some(lang_id) = resource.parse_language_identifier() else { return 0; };
179+
let Some(lang_id) = resource.parse_language_identifier() else {
180+
return 0;
181+
};
181182
let mut added = 0usize;
182183
for entry in &mut resource.entries {
183184
// Skip entries that shouldn't be translated
@@ -193,8 +194,8 @@ pub fn autofix_fill_missing_from_other_resource(resource: &mut Resource) -> usiz
193194
if let Some(other_val) = plural.forms.get(&PluralCategory::Other).cloned() {
194195
for cat in missing {
195196
// Insert only if still missing (avoid race with duplicates)
196-
if !plural.forms.contains_key(&cat) {
197-
plural.forms.insert(cat, other_val.clone());
197+
if let std::collections::btree_map::Entry::Vacant(e) = plural.forms.entry(cat) {
198+
e.insert(other_val.clone());
198199
added += 1;
199200
}
200201
}
@@ -247,11 +248,13 @@ mod tests {
247248
},
248249
entries: vec![Entry {
249250
id: "apples".into(),
250-
value: Translation::Plural(Plural::new(
251-
"apples",
252-
vec![(PluralCategory::Other, "%d apples".to_string())].into_iter(),
253-
)
254-
.unwrap()),
251+
value: Translation::Plural(
252+
Plural::new(
253+
"apples",
254+
vec![(PluralCategory::Other, "%d apples".to_string())].into_iter(),
255+
)
256+
.unwrap(),
257+
),
255258
comment: None,
256259
status: EntryStatus::Translated,
257260
custom: Default::default(),
@@ -273,11 +276,13 @@ mod tests {
273276
},
274277
entries: vec![Entry {
275278
id: "apples".into(),
276-
value: Translation::Plural(Plural::new(
277-
"apples",
278-
vec![(PluralCategory::Other, "%d apples".to_string())].into_iter(),
279-
)
280-
.unwrap()),
279+
value: Translation::Plural(
280+
Plural::new(
281+
"apples",
282+
vec![(PluralCategory::Other, "%d apples".to_string())].into_iter(),
283+
)
284+
.unwrap(),
285+
),
281286
comment: None,
282287
status: EntryStatus::Translated,
283288
custom: Default::default(),
@@ -304,11 +309,13 @@ mod tests {
304309
},
305310
entries: vec![Entry {
306311
id: "apples".into(),
307-
value: Translation::Plural(Plural::new(
308-
"apples",
309-
vec![(PluralCategory::Other, "%d apples".to_string())].into_iter(),
310-
)
311-
.unwrap()),
312+
value: Translation::Plural(
313+
Plural::new(
314+
"apples",
315+
vec![(PluralCategory::Other, "%d apples".to_string())].into_iter(),
316+
)
317+
.unwrap(),
318+
),
312319
comment: None,
313320
status: EntryStatus::Translated,
314321
custom: Default::default(),

0 commit comments

Comments
 (0)