1pub mod extract;
9pub mod replace;
10pub mod bundle;
11
12pub use extract::NLSExtractor;
13pub use replace::NLSReplacer;
14pub use bundle::NLSBundle;
15
16#[derive(Debug, Clone, Default)]
18pub struct NLSConfig {
19 pub source_lang:String,
21 pub output_dir:String,
23 pub inline:bool,
25 pub key_pattern:String,
27 pub languages:Vec<String>,
29}
30
31impl NLSConfig {
32 pub fn new() -> Self {
33 Self {
34 source_lang:"en".to_string(),
35 output_dir:"out/nls".to_string(),
36 inline:false,
37 key_pattern:"*.nls.*".to_string(),
38 languages:vec!["en".to_string()],
39 }
40 }
41}
42
43#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
45pub struct LocalizationEntry {
46 pub key:String,
48 pub value:String,
50 pub comment:Option<String>,
52}
53
54#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
56pub struct LocalizationBundle {
57 pub language:String,
59 pub hash:String,
61 pub entries:Vec<LocalizationEntry>,
63}
64
65impl LocalizationBundle {
66 pub fn new(language:&str) -> Self { Self { language:language.to_string(), hash:String::new(), entries:Vec::new() } }
67
68 pub fn add_entry(&mut self, key:impl Into<String>, value:impl Into<String>) {
69 self.entries
70 .push(LocalizationEntry { key:key.into(), value:value.into(), comment:None });
71 }
72
73 pub fn compute_hash(&mut self) {
75 use std::{
76 collections::hash_map::DefaultHasher,
77 hash::{Hash, Hasher},
78 };
79
80 let mut hasher = DefaultHasher::new();
81 for entry in &self.entries {
82 entry.key.hash(&mut hasher);
83 entry.value.hash(&mut hasher);
84 }
85 self.hash = format!("{:x}", hasher.finish());
86 }
87}