1#[path = "Extract.rs"]
9pub mod Extract;
10#[path = "Replace.rs"]
11pub mod Replace;
12#[path = "Bundle.rs"]
13pub mod Bundle;
14
15pub use Extract::NLSExtractor;
16pub use Replace::NLSReplacer;
17pub use Bundle::NLSBundle;
18
19#[derive(Debug, Clone, Default)]
21pub struct NLSConfig {
22 pub source_lang:String,
24 pub output_dir:String,
26 pub inline:bool,
28 pub key_pattern:String,
30 pub languages:Vec<String>,
32}
33
34impl NLSConfig {
35 pub fn new() -> Self {
36 Self {
37 source_lang:"en".to_string(),
38 output_dir:"out/nls".to_string(),
39 inline:false,
40 key_pattern:"*.nls.*".to_string(),
41 languages:vec!["en".to_string()],
42 }
43 }
44}
45
46#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
48pub struct LocalizationEntry {
49 pub key:String,
51 pub value:String,
53 pub comment:Option<String>,
55}
56
57#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
59pub struct LocalizationBundle {
60 pub language:String,
62 pub hash:String,
64 pub entries:Vec<LocalizationEntry>,
66}
67
68impl LocalizationBundle {
69 pub fn new(language:&str) -> Self { Self { language:language.to_string(), hash:String::new(), entries:Vec::new() } }
70
71 pub fn add_entry(&mut self, key:impl Into<String>, value:impl Into<String>) {
72 self.entries
73 .push(LocalizationEntry { key:key.into(), value:value.into(), comment:None });
74 }
75
76 pub fn compute_hash(&mut self) {
78 use std::{
79 collections::hash_map::DefaultHasher,
80 hash::{Hash, Hasher},
81 };
82
83 let mut hasher = DefaultHasher::new();
84 for entry in &self.entries {
85 entry.key.hash(&mut hasher);
86 entry.value.hash(&mut hasher);
87 }
88 self.hash = format!("{:x}", hasher.finish());
89 }
90}