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
//! # glossa-codegen
//!
//! Use a code generator to generate code.
//!
//! It can generate const language localisation map for code at compile time
//!
//! ## features
//!
//! - yaml
//!   - Enabled by default.
//!   - The default file extension is ".yaml" or ".yml"
//! - ron
//!   - The default ext is ".ron"
//! - toml
//!   - The ext is ".toml"
//! - json
//!   - ext: ".json"
//! - highlight
//!
//! In addition to highlight, this corresponds to different types of configuration. You can enable all features or add them as needed.
//!
//! By default, the file type is determined based on the file name suffix, and the **map name** (table name) is set based on the file name. Whether deserialisation is needed at compile-time is determined by the enabled feature.
//!
//! ## Preparations
//!
//! Before writing `build.rs`, we need to prepare the localisation resource files (localised files).
//!
//! de (Deutsch, Lateinisch, Deutschland):
//!
//! - "assets/l10n/de/error.yaml"
//!
//! ```yaml
//! text-not-found: Kein lokalisierter Text gefunden
//! ```
//!
//! en (English, Latin, United States):
//!
//! - "assets/l10n/en/error.yaml"
//!
//! ```yaml
//! text-not-found: No localized text found
//! ```
//!
//! en-GB (English, Latin, Great Britain):
//!
//! - `assets/l10n/en-GB/error.yaml`
//!
//! ```yaml
//! text-not-found: No localised text found
//! ```
//!
//! es (español, latino, España):
//!
//! - `assets/l10n/es/error.yaml`
//!
//! ```yaml
//! text-not-found: No se encontró texto localizado
//! ```
//!
//! pt (português, latim, Brasil)
//!
//! - `assets/l10n/pt/error.yaml`
//!
//! ```yaml
//! text-not-found: Nenhum texto localizado encontrado
//! ```
//!
//! ---
//!
//! ## build.rs
//!
//! ```rust
//! use glossa_codegen::{consts::*, prelude::*};
//! use std::{
//!     fs::File,
//!     io::{self, BufWriter},
//!     path::PathBuf,
//! };
//!
//! fn main() -> io::Result<()> {
//!     // Specify the version as the current package version to avoid repetitive compilation for the same version.
//!     let ver = get_pkg_version!();
//!
//!     // This is a constant array: ["src", "assets", "localisation.rs"], which is converted into a path for storing automatically generated Rust code related to localisation.
//!     // On Windows, the path is 'src\assets\localisation.rs'.
//!     // On Unix, the path is "src/assets/localisation.rs".
//!     // Note: this is a relative path!
//!     let mut path = PathBuf::from_iter(default_l10n_rs_file_arr());
//!
//!     // If it's the same version, then exit.
//!     if is_same_version(&path, Some(ver))? {
//!       // When developing, we can comment out the `return` statement below so that every change will be recompiled and won't exit prematurely.
//!         return Ok(());
//!     }
//!
//!     // If the path is "src/assets/localisation.rs", then it will append `mod localisation;` and related `use` statements to "src/assets/mod.rs".
//!     append_to_l10n_mod(&path)?;
//!
//!     // This creates a new file: "src/assets/localisation.rs".
//!     // Unlike append, if only create is used, then the file will be cleared when it is written.
//!     let mut file = BufWriter::new(File::create(&path)?);
//!     let writer = MapWriter::new(file);
//!
//!     // default_l10n_dir_arr() is also a constant array: ["assets", "l10n"].
//!     // If the current localisation resource path is at the parent level, then you can use `path = PathBuf::from_iter([".."].into_iter().chain(default_l10n_dir_arr()));`.
//!     path = PathBuf::from_iter(default_l10n_dir_arr());
//!
//!     let generator = Generator::new(path).with_version(ver);
//!     // Invoke the generator here to generate code and write it to the `rs` file.
//!     generator.run(writer)
//! }
//! ```

pub mod consts;
mod generator;

#[cfg(feature = "highlight")]
pub mod highlight;

pub(crate) mod conversion;
mod create;
pub(crate) mod deser;
pub(crate) mod header;
mod map_writer;
pub mod prelude;
mod version;