1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! Universal localization file toolkit for Rust.
//!
//! Supports parsing, writing, and converting between Apple `.strings`, `.xcstrings`, `.xliff`,
//! Android `strings.xml`, CSV, and TSV files.
//! All conversion happens through the unified `Resource` model.
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use langcodec::{Codec, convert_auto};
//!
//! // Convert between formats automatically
//! convert_auto("en.lproj/Localizable.strings", "strings.xml")?;
//!
//! // Or work with the unified Resource model
//! let mut codec = Codec::new();
//! codec.read_file_by_extension("en.lproj/Localizable.strings", None)?;
//! codec.write_to_file()?;
//!
//! // Or use the builder pattern for fluent construction
//! let codec = Codec::builder()
//! .add_file("en.lproj/Localizable.strings")?
//! .add_file("fr.lproj/Localizable.strings")?
//! .add_file("values-es/strings.xml")?
//! .read_file_by_extension("de.strings", Some("de".to_string()))?
//! .build();
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! # Supported Formats
//!
//! - **Apple `.strings`**: Traditional iOS/macOS localization files
//! - **Apple `.xcstrings`**: Modern Xcode localization format with plural support
//! - **Apple `.xliff`**: Xcode localization exchange files (XLIFF 1.2)
//! - **Android `strings.xml`**: Android resource files
//! - **CSV**: Comma-separated values for simple key-value pairs
//! - **TSV**: Tab-separated values for simple key-value pairs
//!
//! # Features
//!
//! - ✨ Parse, write, convert, and merge multiple localization file formats
//! - 🦀 Idiomatic, modular, and ergonomic Rust API
//! - 📦 Designed for CLI tools, CI/CD pipelines, and library integration
//! - 🔄 Unified internal model (`Resource`) for lossless format-agnostic processing
//! - 📖 Well-documented, robust error handling and extensible codebase
//!
//! # Examples
//!
//! ## Basic Format Conversion
//! ```rust,no_run
//! use langcodec::convert_auto;
//!
//! // Convert Apple .strings to Android XML
//! convert_auto("en.lproj/Localizable.strings", "values-en/strings.xml")?;
//!
//! // Convert to CSV for analysis
//! convert_auto("Localizable.xcstrings", "translations.csv")?;
//! # Ok::<(), langcodec::Error>(())
//! ```
//!
//! ## Working with Resources
//! ```rust,no_run
//! use langcodec::{Codec, types::Entry};
//!
//! // Load multiple files with the builder pattern
//! let codec = Codec::builder()
//! .add_file("en.lproj/Localizable.strings")?
//! .add_file("fr.lproj/Localizable.strings")?
//! .add_file("values-es/strings.xml")?
//! .build();
//!
//! // Find specific translations
//! if let Some(en_resource) = codec.get_by_language("en") {
//! if let Some(entry) = en_resource.entries.iter().find(|e| e.id == "welcome") {
//! println!("Welcome message: {}", entry.value);
//! }
//! }
//! # Ok::<(), langcodec::Error>(())
//! ```
//!
//! ## Modifying Translations
//! ```rust,no_run
//! use langcodec::{Codec, types::{Translation, EntryStatus}};
//!
//! let mut codec = Codec::builder()
//! .add_file("en.lproj/Localizable.strings")?
//! .add_file("fr.lproj/Localizable.strings")?
//! .build();
//!
//! // Update an existing translation
//! codec.update_translation(
//! "welcome_message",
//! "en",
//! Translation::Singular("Hello, World!".to_string()),
//! Some(EntryStatus::Translated)
//! )?;
//!
//! // Add a new translation
//! codec.add_entry(
//! "new_feature",
//! "en",
//! Translation::Singular("Check out our new feature!".to_string()),
//! Some("Promotional message for new feature".to_string()),
//! Some(EntryStatus::New)
//! )?;
//!
//! // Copy a translation from one language to another
//! codec.copy_entry("welcome_message", "en", "fr", true)?;
//!
//! // Find all translations for a key
//! for (resource, entry) in codec.find_entries("welcome_message") {
//! println!("{}: {}", resource.metadata.language, entry.value);
//! }
//!
//! // Validate the codec
//! if let Err(validation_error) = codec.validate() {
//! eprintln!("Validation failed: {}", validation_error);
//! }
//! # Ok::<(), langcodec::Error>(())
//! ```
//!
//! ## Batch Processing
//! ```rust,no_run
//! use langcodec::Codec;
//! use std::path::Path;
//!
//! let mut codec = Codec::new();
//!
//! // Load all localization files in a directory
//! for entry in std::fs::read_dir("locales")? {
//! let path = entry?.path();
//! if path.extension().and_then(|s| s.to_str()) == Some("strings") {
//! codec.read_file_by_extension(&path, None)?;
//! }
//! }
//!
//! // Write all resources back to their original formats
//! codec.write_to_file()?;
//! # Ok::<(), langcodec::Error>(())
//! ```
// Re-export most used types for easy consumption
pub use crate::;