1#[path = "Extract.rs"]
9pub mod Extract;
10
11#[path = "Replace.rs"]
12pub mod Replace;
13
14#[path = "Bundle.rs"]
15pub mod Bundle;
16
17pub use Extract::NLSExtractor;
18pub use Replace::NLSReplacer;
19pub use Bundle::NLSBundle;
20
21#[derive(Debug, Clone, Default)]
23pub struct NLSConfig {
24 pub source_lang:String,
26
27 pub output_dir:String,
29
30 pub inline:bool,
32
33 pub key_pattern:String,
35
36 pub languages:Vec<String>,
38}
39
40impl NLSConfig {
41 pub fn new() -> Self {
42 Self {
43 source_lang:"en".to_string(),
44
45 output_dir:"out/nls".to_string(),
46
47 inline:false,
48
49 key_pattern:"*.nls.*".to_string(),
50
51 languages:vec!["en".to_string()],
52 }
53 }
54}
55
56#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
58pub struct LocalizationEntry {
59 pub key:String,
61
62 pub value:String,
64
65 pub comment:Option<String>,
67}
68
69#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
71pub struct LocalizationBundle {
72 pub language:String,
74
75 pub hash:String,
77
78 pub entries:Vec<LocalizationEntry>,
80}
81
82impl LocalizationBundle {
83 pub fn new(language:&str) -> Self { Self { language:language.to_string(), hash:String::new(), entries:Vec::new() } }
84
85 pub fn add_entry(&mut self, key:impl Into<String>, value:impl Into<String>) {
86 self.entries
87 .push(LocalizationEntry { key:key.into(), value:value.into(), comment:None });
88 }
89
90 pub fn compute_hash(&mut self) {
92 use std::{
93 collections::hash_map::DefaultHasher,
94 hash::{Hash, Hasher},
95 };
96
97 let mut hasher = DefaultHasher::new();
98
99 for entry in &self.entries {
100 entry.key.hash(&mut hasher);
101
102 entry.value.hash(&mut hasher);
103 }
104
105 self.hash = format!("{:x}", hasher.finish());
106 }
107}