Prototype for an l10n message bundle database

This commit is contained in:
Savanni D'Gerinel 2025-02-21 10:28:41 -05:00
parent 151876bcd4
commit 359ab96779
7 changed files with 248 additions and 487 deletions

587
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -33,4 +33,4 @@ members = [
"tree", "tree",
"visions/server", "visions/server",
"gm-dash/server" "gm-dash/server"
] , "l10n-db"]

19
l10n-db/Cargo.toml Normal file
View File

@ -0,0 +1,19 @@
[package]
name = "l10n-db"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.30", features = ["derive"] }
icu_locid = { version = "1.5.0", features = ["serde"] }
serde = { version = "1.0.218", features = ["derive"] }
toml = "0.8.20"
# [lib]
# name = "l10n_db"
# path = "src/lib.rs"
#
# [[bin]]
# name = "l10n-db"
# path = "src/main.rs"

37
l10n-db/src/bin/main.rs Normal file
View File

@ -0,0 +1,37 @@
use clap::{Parser, Subcommand};
use l10n_db;
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
// Edit, potentially creating, a key
// EditKey { },
// List al keys in the database
ListKeys,
// Search the database
// Search { },
/// Export the database
Export {
#[arg(short, long)]
format: String,
#[arg(short, long)]
locale: String
},
}
fn main() {
let cli = Cli::parse();
match &cli.command {
Some(Commands::ListKeys) => todo!(),
Some(Commands::Export{..}) => todo!(),
None => {},
}
}

24
l10n-db/src/bundle.rs Normal file
View File

@ -0,0 +1,24 @@
use std::{collections::HashMap, path::Path};
use crate::Message;
pub struct Bundle {
messages: HashMap<String, Message>
}
impl Bundle {
pub fn new() -> Self {
Self{ messages: HashMap::new() }
}
pub fn load_from_disk(path: &Path) -> Self {
Self {
messages: HashMap::new()
}
}
}
#[cfg(test)]
mod test {
}

20
l10n-db/src/lib.rs Normal file
View File

@ -0,0 +1,20 @@
mod bundle;
pub use bundle::Bundle;
mod types;
pub use types::{Message, Variant};
/*
#[cfg(test)]
mod test {
#[test]
fn it_can_represent_an_untranslated_message() {
todo!()
}
#[test]
fn it_can_represent_a_partially_translated_message() {
todo!()
}
}
*/

46
l10n-db/src/types.rs Normal file
View File

@ -0,0 +1,46 @@
use std::{collections::HashMap, time::SystemTime};
use icu_locid::LanguageIdentifier;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
pub struct Message {
key: String,
description: String,
variants: HashMap<LanguageIdentifier, Variant>,
}
impl Message {
pub fn new(key: String) -> Self {
Self {
key,
description: "".to_owned(),
variants: HashMap::new(),
}
}
pub fn set_description(&mut self, desc: String) {
self.description = desc;
}
pub fn description(&self) -> &str {
&self.description
}
pub fn variant_mut(&mut self, locale: LanguageIdentifier) -> &mut Variant {
self.variants.entry(locale.clone()).or_insert(Variant {
locale,
content: "".to_owned(),
modified: SystemTime::now(),
})
}
}
#[derive(Deserialize, Serialize)]
pub struct Variant {
locale: LanguageIdentifier,
content: String,
modified: SystemTime,
}