glossa_codegen/generator/init_lazy_data.rs
1use crate::{
2 Generator,
3 generator::flattening::{L10nDSLMaps, L10nMaps},
4};
5
6impl Generator<'_> {
7 /// Initializes and retrieves DSL-based localization maps
8 ///
9 /// # Behavior
10 /// - Performs lazy initialization of DSL maps on first access
11 /// - Subsequent calls return cached reference
12 pub fn get_or_init_dsl_maps(&self) -> &L10nDSLMaps {
13 self
14 .lazy_maps
15 .dsl
16 .get_or_init(|| self.flatten_dsl_maps())
17 }
18
19 /// Initializes and retrieves primary localization maps
20 ///
21 /// # Behavior
22 /// - Lazily loads core localization data on first access
23 /// - Caches results for subsequent requests
24 pub fn get_or_init_maps(&self) -> &L10nMaps {
25 self
26 .lazy_maps
27 .regular
28 .get_or_init(|| self.flatten_l10n_maps())
29 }
30}
31
32impl<'h> Generator<'h> {
33 /// Initializes and retrieves highlighted localization maps
34 ///
35 /// # Behavior
36 /// - Lazy initialization of special highlight entries
37 /// - Only initializes if highlight configuration exists
38 pub fn get_or_init_highlight_maps(&'h self) -> Option<&'h L10nMaps> {
39 self
40 .lazy_maps
41 .highlight
42 .get_or_init(|| self.flatten_highlight_maps())
43 .as_ref()
44 }
45
46 /// Provides merged view of localization data
47 ///
48 /// > Merges [Self::get_or_init_maps()] & [Self::get_or_init_highlight_maps()]
49 pub fn get_or_init_merged_maps(&'h self) -> &'h L10nMaps {
50 if self.get_highlight().is_none() {
51 return self.get_or_init_maps();
52 }
53
54 self
55 .lazy_maps
56 .merged
57 .get_or_init(|| self.merge_l10n_and_highlight_maps())
58 }
59}