Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ cargo clippy -p openecraft -p openecraft-parts-manager --target wasm32-unknown-u
| --- | --- | --- |
| `openecraft` | `.` (`src/`) | Editor (desktop + web) – the root package, built by trunk |
| `openecraft-parts` | `crates/openecraft-parts` | Shared library: part model, function templates, CSV/JSON, catalog, parts server API types |
| `openecraft-ui` | `crates/openecraft-ui` | Shared egui library: part tree / editor / previews, parts server client, file dialogs |
| `openecraft-i18n` | `crates/openecraft-i18n` | Languages and UI translations (English, German, French, Spanish); no dependencies |
| `openecraft-ui` | `crates/openecraft-ui` | Shared egui library: part tree / editor / previews, parts server client, file dialogs, language menu |
| `openecraft-server` | `server/` | Standalone parts database server (axum, JSON file storage) |
| `openecraft-parts-manager` | `parts-manager/` | Standalone parts server maintenance app (desktop + web, own `index.html` / `Trunk.toml`) |

Expand All @@ -41,6 +42,38 @@ cargo clippy -p openecraft -p openecraft-parts-manager --target wasm32-unknown-u
- New crates are added to `[workspace] members` in the root `Cargo.toml`; the
convention test reads that list, so its rules apply to every member.

## Languages – mandatory for every feature

The app is available in **English, German, French and Spanish**. All four are required:
a feature, menu entry, dialog, message, tooltip, report heading or placeholder text is
not done until it is available in all of them. Further languages are optional (add a
column to the catalog and a `Lang` variant).

- Write texts in English in the code and pass them through `openecraft_i18n`:
`tr("Open")` for plain texts, `tr_fmt!("Saved {}", name)` for texts with `{}`
placeholders (the translation may reorder with `{0}`, `{1}`), `tr_const!("…")` in
`const` / `static` tables (translate with `tr(…)` where the text is shown).
Never build sentences from translated fragments (`"Macro " + tr("saved")`); translate
the whole sentence, one catalog entry per variant.
- Every English text needs a line in `crates/openecraft-i18n/src/catalog/extra.tsv`
(`English<TAB>Deutsch<TAB>Français<TAB>Español`; `\n` and `\"` as in Rust source;
`{}` placeholders must appear in every translation). `translations.tsv` holds the
initial set. The catalog is checked by `cargo test`: all four languages present,
placeholders equal, every literal passed to `tr` / `tr_fmt!` / `tr_const!` and every
built-in symbol name is in the catalog, and all translated characters exist in the
bundled fonts.
- `src/conventions/tests.rs` fails for plain string literals passed to widgets
(`ui.button("…")`, `.label("…")`, `.on_hover_text("…")`, `Window::new("…")`, …).
- Translate at the point where the text is shown, so that switching the language in
View › Language (or the parts manager's toolbar) takes effect immediately. Texts
that are stored in the project (user input, names of built-in forms) stay as they are;
generated content (reports, title blocks, check messages) is translated when it is
generated, `App` regenerates it when the language changes.
- Do not translate file formats, CSV headers of machine readable exports, JSON keys,
part data and log messages.
- Language choice: stored by the apps (`language` key), otherwise the OS / browser
language if supported, otherwise English (`openecraft_i18n::init`).

## Unit tests – mandatory layout

**Unit tests never live inline in a module file.** Each module keeps its tests in a
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
[package]
name = "openecraft"
version = "0.1.0"
edition = "2021"
Expand All @@ -10,7 +10,7 @@ name = "openecraft"
path = "src/main.rs"

[workspace]
members = [".", "crates/openecraft-parts", "crates/openecraft-ui", "server", "parts-manager"]
members = [".", "crates/openecraft-i18n", "crates/openecraft-parts", "crates/openecraft-ui", "server", "parts-manager"]

[dependencies]
eframe = { version = "0.37", default-features = false, features = [
Expand All @@ -30,6 +30,7 @@ serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
log = "0.4"
openecraft-parts = { path = "crates/openecraft-parts" }
openecraft-i18n = { path = "crates/openecraft-i18n" }
openecraft-ui = { path = "crates/openecraft-ui" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand All @@ -38,7 +39,7 @@ env_logger = "0.11"
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = ["Window", "Document", "Element", "HtmlCanvasElement"] }
web-sys = { version = "0.3", features = ["Window", "Document", "Element", "HtmlCanvasElement", "Navigator"] }

[profile.release]
opt-level = 2
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ built with [egui / eframe](https://github.com/emilk/egui).

## Features

- **Languages**: English, German, French and Spanish (View › Language; the editor and the
parts manager remember the choice and start in the system / browser language if supported).
- **Projects with pages**: multi-line schematic pages (A3, 10 columns / 6 rows, title block),
cover sheet and generated report pages. Page navigator with reordering.
- **IEC symbol library** (~40 symbols): coils and timers, NO/NC/changeover contacts, main
Expand Down Expand Up @@ -236,6 +238,7 @@ cargo test --workspace

| File | Purpose |
| --- | --- |
| `crates/openecraft-i18n` | Languages and UI translations (English, German, French, Spanish); catalog in `src/catalog/*.tsv` |
| `crates/openecraft-parts` | Shared library: part model, function templates, CSV/JSON, catalog, server API types, 3D math |
| `crates/openecraft-ui` | Shared egui library: part editor and previews, parts server client, file dialogs |
| `server/` | `openecraft-server`: parts database server (REST API, JSON storage) |
Expand Down
8 changes: 8 additions & 0 deletions crates/openecraft-i18n/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "openecraft-i18n"
version = "0.1.0"
edition = "2021"
description = "Language selection and UI translations (English, German, French, Spanish) of OpenECraft"
license = "MIT OR Apache-2.0"

[dependencies]
47 changes: 47 additions & 0 deletions crates/openecraft-i18n/src/catalog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! The translation catalog: tab separated `English<TAB>Deutsch<TAB>Français<TAB>Español`
//! lines in `catalog/*.tsv`. The English text is the lookup key and must be identical to
//! the literal passed to `tr` / `tr_fmt!` / `tr_const!` (`\n` and `\"` are written as in
//! Rust source). Lines starting with `#` are comments.

pub type Entry = (&'static str, &'static str, &'static str, &'static str);

const FILES: [&str; 2] = [include_str!("catalog/translations.tsv"), include_str!("catalog/extra.tsv")];

/// All catalog entries; a malformed line yields `None` (reported by the tests).
pub fn parse() -> impl Iterator<Item = Option<Entry>> {
FILES
.iter()
.flat_map(|f| f.lines())
.filter(|l| !l.trim().is_empty() && !l.starts_with('#'))
.map(|line| {
let mut cols = line.split('\t');
let entry = (unescape(cols.next()?), unescape(cols.next()?), unescape(cols.next()?), unescape(cols.next()?));
cols.next().is_none().then_some(entry)
})
}

pub fn all() -> impl Iterator<Item = Entry> {
parse().flatten()
}

/// Resolves the Rust escapes used in the catalog (`\n`, `\t`, `\"`, `\\`).
fn unescape(s: &'static str) -> &'static str {
if !s.contains('\\') {
return s;
}
let mut out = String::with_capacity(s.len());
let mut chars = s.chars();
while let Some(c) = chars.next() {
if c != '\\' {
out.push(c);
continue;
}
match chars.next() {
Some('n') => out.push('\n'),
Some('t') => out.push('\t'),
Some(other) => out.push(other),
None => out.push('\\'),
}
}
Box::leak(out.into_boxed_str())
}
15 changes: 15 additions & 0 deletions crates/openecraft-i18n/src/catalog/extra.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Entries added by hand (not part of the generated translations.tsv).
{} connections removed from their harness {} Verbindungen aus ihrem Kabelbaum entfernt {} liaisons retirées de leur faisceau {} conexiones quitadas de su mazo
{} connections assigned to {} {} Verbindungen {} zugewiesen {} liaisons affectées à {} {} conexiones asignadas a {}
🗄 Show in panel layout ({}) 🗄 Im Schaltschrank-Layout anzeigen ({}) 🗄 Afficher dans l'implantation de l'armoire ({}) 🗄 Mostrar en la distribución del armario ({})
| Potential {} | Potenzial {} | Potentiel {} | Potencial {}
📁 Project parts ({}) 📁 Projektartikel ({}) 📁 Articles du projet ({}) 📁 Artículos del proyecto ({})
part {} not found Artikel {} nicht gefunden article {} introuvable artículo {} no encontrado
… {} more rows – see Reports window / CSV export … {} weitere Zeilen – siehe Berichtsfenster / CSV-Export … {} lignes de plus – voir la fenêtre Rapports / export CSV … {} filas más – ver la ventana de informes / exportación CSV
strip {} mm, ferrule {} mm² {} abisolieren {} mm, Aderendhülse {} mm² {} dénuder {} mm, embout {} mm² {} pelar {} mm, punta {} mm² {}
strip {} mm abisolieren {} mm dénuder {} mm pelar {} mm
unexpected answer: {} unerwartete Antwort: {} réponse inattendue : {} respuesta inesperada: {}
connection failed: {} Verbindung fehlgeschlagen: {} échec de la connexion : {} conexión fallida: {}
value set… Wertesatz … jeu de valeurs… conjunto de valores…
Shown in title blocks with {prop:Name} Wird in Schriftfeldern mit {prop:Name} angezeigt Affiché dans les cartouches avec {prop:Name} Se muestra en los cajetines con {prop:Name}
e.g. W z. B. W p. ex. W p. ej. W
Loading
Loading