langcodec_cli/transformers/
langcodec_resource_array.rs

1use std::fs;
2
3/// Transform a langcodec::Resource array JSON file to a Vec<Resource>.
4/// This format is a direct representation of langcodec::Resource objects in JSON.
5pub fn transform(input: String) -> Result<Vec<langcodec::Resource>, String> {
6    // Read the file content
7    let content =
8        fs::read_to_string(&input).map_err(|e| format!("Error reading file {}: {}", input, e))?;
9
10    // Parse as JSON array of Resource objects
11    let resources: Vec<langcodec::Resource> = serde_json::from_str(&content)
12        .map_err(|e| format!("Error parsing JSON as Resource array: {}", e))?;
13
14    // Validate that we have at least one resource
15    if resources.is_empty() {
16        return Err("Resource array is empty".to_string());
17    }
18
19    Ok(resources)
20}