Refactored UI strings into cental location
CI / test (push) Successful in 7m8s
Release / windows (push) Successful in 3m38s

This commit is contained in:
Torbjörn Molin committed 2026-11-09 11:22:18 +01:00
1 parent 8755fec633
commit 8c6dec9062
14 files changed
+605 -251

No files matched your search

+373
View File
@@ -0,0 +1,373 @@
//! Every user-visible text in one place.
//!
//! Fixed texts are `const`s; texts with values in them are small functions so
//! the wording (and word order) lives here, not at the call site. Call sites
//! import this module as `tr`. Icons that are pure symbols (▶, ✖, `.*`, `Aa`)
//! are here too so a later translation pass sees everything.
//!
//! Not here: widget ids, settings keys, debug-script commands and env vars.
use std::fmt::Display;
use std::path::Path;
pub const APP_NAME: &str = "logreadlite";
pub const APP_TAGLINE: &str = "A fast viewer for large log files.";
// ----- common -----
pub const CANCEL: &str = "Cancel";
pub const CLOSE: &str = "Close";
pub const COPY: &str = "📋 Copy";
pub const COPY_LINE: &str = "Copy line";
pub const EXPORT_DOTS: &str = "Export…";
pub const IMPORT: &str = "Import";
pub const CUSTOM: &str = "Custom";
pub const NONE_PAREN: &str = "(none)";
pub const RULE_FILE_FILTER: &str = "Log rules";
pub const REGEX_ICON: &str = ".*";
pub const REGEX_TIP: &str = "Regex";
pub const CASE_ICON: &str = "Aa";
pub const CASE_TIP: &str = "Case sensitive";
pub const WORD_ICON: &str = "\\b";
pub const WORD_TIP: &str = "Whole word";
pub const ARROW_OPEN: &str = "▼";
pub const ARROW_CLOSED: &str = "▶";
pub fn arrow(open: bool) -> &'static str {
if open { ARROW_OPEN } else { ARROW_CLOSED }
}
// ----- app shell: menus, tabs, start screen -----
pub const MENU_FILE: &str = "File";
pub const MENU_OPEN: &str = "Open… (Ctrl+O)";
pub const MENU_FIND_IN_FILES: &str = "Find in files… (Ctrl+Shift+F)";
pub const MENU_RECENT: &str = "Recent files";
pub const MENU_IMPORT_RULES: &str = "Import rules…";
pub const MENU_EXPORT_RULES: &str = "Export rules…";
pub const MENU_RELOAD: &str = "Reload file";
pub const MENU_CLOSE_TAB: &str = "Close tab (Ctrl+W)";
pub const MENU_QUIT: &str = "Quit";
pub const MENU_VIEW: &str = "View";
pub const MENU_SHOW_GUTTER: &str = "Show gutter";
pub const MENU_GUTTER_LINE_NUMBERS: &str = "Gutter shows line numbers";
pub const MENU_FONT_SIZE: &str = "Font size";
pub const MENU_HELP: &str = "Help";
pub const MENU_SHORTCUTS: &str = "Keyboard shortcuts";
pub const MENU_ABOUT: &str = "About";
pub const TAB_CLOSE_ICON: &str = "✖";
pub const SHORTCUTS_TITLE: &str = "Keyboard shortcuts";
pub const SHORTCUTS: &[(&str, &str)] = &[
("Ctrl/Cmd+O", "Open file"),
("Ctrl/Cmd+Shift+F", "Find in files"),
("Ctrl/Cmd+W", "Close tab"),
("Ctrl/Cmd+Tab", "Next tab"),
("Ctrl/Cmd+F", "Search"),
("Enter / F3", "Next match"),
("Shift+Enter / Shift+F3", "Previous match"),
("Ctrl/Cmd+G", "Go to line"),
("Alt+Z", "Toggle line wrap"),
("Up / Down", "Select entry"),
("Space / Right", "Expand entry"),
("Left", "Collapse entry"),
("Shift+Click / Shift+Up / Down", "Select a range of entries"),
("Ctrl/Cmd+C", "Copy selected entries"),
("PageUp / PageDown", "Scroll a page"),
("Home / End", "Start / end of file"),
];
pub const ABOUT_TITLE: &str = "About";
pub fn about_version(v: &str) -> String {
format!("Version {v}")
}
pub const START_HINT: &str = "Open a log file (Ctrl+O), drop files or a folder here, or pick a recent file.";
pub const START_OPEN: &str = "Open file…";
pub const DROP_RULES_NEEDS_LOG: &str = "Open a log file first, then drop the rule file on it";
pub fn cannot_save_settings(e: impl Display) -> String {
format!("Cannot save settings: {e:#}")
}
// ----- log tab: toolbar -----
pub const TB_ENTRY_START: &str = "✏ Entry start";
pub const TB_ENTRY_START_TIP: &str = "Edit the entry-start pattern";
pub const TB_EXPAND_ALL: &str = "⊞ Expand all";
pub const TB_COLLAPSE_ALL: &str = "⊟ Collapse all";
pub const TB_WRAP: &str = "↩ Wrap";
pub const TB_WRAP_TIP: &str = "Line wrap (Alt+Z)";
pub const TB_HIGHLIGHTS: &str = "🎨 Highlights";
pub const FILE_GONE: &str = "The file was deleted or moved. Showing the last version.";
// ----- log tab: search -----
pub const SEARCH_HINT: &str = "Search (Ctrl+F)";
pub const SEARCH_PREV_ICON: &str = "⏶";
pub const SEARCH_PREV_TIP: &str = "Previous match (Shift+Enter, Shift+F3)";
pub const SEARCH_NEXT_ICON: &str = "⏷";
pub const SEARCH_NEXT_TIP: &str = "Next match (Enter, F3)";
pub const SEARCH_HIDDEN_TOO: &str = "hidden too";
pub const SEARCH_HIDDEN_TOO_TIP: &str = "Also stop at matches in entries hidden by the filter";
pub const INVALID_REGEX: &str = "invalid regex";
pub const SEARCH_CAPPED: &str = " (too many matches, capped at 1M)";
pub fn match_pos(pos: &str, total: &str) -> String {
format!("match {pos} of {total}")
}
pub fn match_count(total: &str) -> String {
format!("{total} matches")
}
pub fn searching_pct(p: f32) -> String {
format!(" (searching {:.0}%)", p * 100.0)
}
// ----- log tab: filter bar -----
pub const FILTER_LABEL: &str = "Filter:";
pub const FILTER_NOT: &str = "not";
pub const FILTER_ONLY: &str = "only";
pub const FILTER_KIND_TIP: &str = "Switch between Exclude and Only";
pub const FILTER_HINT: &str = "keyword";
pub const FILTER_ADD_EXCLUDE: &str = "− Exclude";
pub const FILTER_ADD_EXCLUDE_TIP: &str = "Hide entries containing this";
pub const FILTER_ADD_ONLY: &str = "+ Only";
pub const FILTER_ADD_ONLY_TIP: &str = "Show only entries containing this";
// ----- log tab: status bar -----
pub const ENCODING_UTF8: &str = "UTF-8";
pub const FILE_GREW: &str = "file grew on disk";
pub const RELOAD: &str = "Reload";
pub fn indexing_pct(p: f32) -> String {
format!("indexing {:.0}%", p * 100.0)
}
pub fn entries_of(visible: &str, total: &str) -> String {
format!("{visible} of {total} entries")
}
pub fn entries(total: &str) -> String {
format!("{total} entries")
}
pub fn filtering_pct(p: f32) -> String {
format!(" (filtering {:.0}%)", p * 100.0)
}
pub fn lines(n: &str) -> String {
format!(" · {n} lines")
}
pub fn indexed_in(secs: f32) -> String {
format!(" · indexed in {secs:.2} s")
}
// ----- log tab: view -----
pub const VIEW_INDEXING: &str = "Indexing…";
pub const VIEW_FILTERING: &str = "Filtering…";
pub const VIEW_EMPTY: &str = "The file is empty.";
pub const VIEW_NO_MATCH: &str = "No entries match the filter.";
pub const ENTRY_CUT: &str = "\n… (cut)";
pub const LINE_CUT: &str = " … line cut at 64 KB, right-click → Show full entry";
pub fn more_lines_badge(n: u32) -> String {
format!(" +{n} lines ")
}
pub const CTX_COPY_ENTRY: &str = "Copy entry";
pub const CTX_SHOW_FULL: &str = "Show full entry";
pub const CTX_COLLAPSE: &str = "Collapse";
pub const CTX_EXPAND: &str = "Expand";
pub const CTX_FILTER_LIKE: &str = "Filter out entries like this";
pub const CTX_HIGHLIGHT_LIKE: &str = "Highlight entries like this";
pub fn ctx_copy_selected(n: &str) -> String {
format!("Copy {n} selected entries")
}
pub fn entry_title(n: u32) -> String {
format!("Entry {n}")
}
pub fn bytes(n: &str) -> String {
format!("{n} bytes")
}
pub const GOTO_TITLE: &str = "Go to line";
pub const GOTO_HINT: &str = "line number";
pub const GOTO_GO: &str = "Go";
pub const GOTO_NOT_READY: &str = "indexing not finished yet";
pub fn goto_out_of_range(total: impl Display) -> String {
format!("line must be 1–{total}")
}
// ----- entry-start pattern panel -----
pub const PATTERN_TITLE: &str = "Entry start pattern";
pub const PATTERN_HELP: &str = "A line that matches starts a new entry; other lines continue the entry above.";
pub const PATTERN_PRESET: &str = "Preset";
pub const PATTERN_REMEMBER_PATH: &str = "Remember for this file";
pub const PATTERN_REMEMBER_GLOB: &str = "Also for files named";
pub const PATTERN_APPLY: &str = "Apply";
pub const PATTERN_REDETECT: &str = "Re-detect";
pub const PATTERN_PREVIEW: &str = "Preview";
pub fn pattern_sample_score(starts: usize, lines: usize, score: f32) -> String {
format!("{starts} entries in sample of {lines} lines · score {score:.2}")
}
// ----- highlight rules panel -----
pub const RULES_TITLE: &str = "Highlight rules";
pub const RULES_HELP: &str = "First matching row rule tints the entry; all match rules color their text.";
pub const SCOPE_ROW: &str = "row";
pub const SCOPE_MATCH: &str = "match";
pub const RULES_ADD: &str = "+ Add rule";
pub const RULES_FILES: &str = "Rule files";
pub const RULES_IMPORT_DOTS: &str = "Import…";
pub const RULES_SAVE_GLOBAL: &str = "Save as global default";
pub const RULES_SAVE_GLOBAL_TIP: &str = "Rules for newly opened files";
pub const RULES_SAVED_GLOBAL: &str = "Saved rules as the global default";
pub const RULES_SAVE_FOR_GLOB: &str = "Save for files matching";
pub const RULESETS_TITLE: &str = "Named rule sets";
pub const RULESETS_NONE: &str = "(none saved)";
pub const RULESETS_SWITCH: &str = "Switch to…";
pub const RULESETS_NAME_HINT: &str = "name, e.g. Java service";
pub const RULESETS_SAVE: &str = "Save set";
pub fn swatch_label(name: &str) -> String {
format!("■ {name}")
}
pub fn rules_saved_for(glob: &str) -> String {
format!("Saved rules for {glob}")
}
pub fn ruleset_loaded(name: &str, skipped: usize) -> String {
if skipped == 0 {
format!("Loaded rule set {name}")
} else {
format!("Loaded rule set {name} ({skipped} invalid rules skipped)")
}
}
pub fn ruleset_load_failed(name: &str, e: impl Display) -> String {
format!("Cannot load {name}: {e:#}")
}
pub fn ruleset_saved(name: &str) -> String {
format!("Saved rule set {name}")
}
pub fn cannot_save(e: impl Display) -> String {
format!("Cannot save: {e:#}")
}
pub fn cannot_read(path: &Path, e: impl Display) -> String {
format!("Cannot read {}: {e:#}", path.display())
}
pub fn cannot_write(path: &Path, e: impl Display) -> String {
format!("Cannot write {}: {e:#}", path.display())
}
pub fn not_a_rule_file(e: impl Display) -> String {
format!("Not a rule file: {e:#}")
}
// ----- import / export rule dialogs -----
pub const IMPORT_TITLE: &str = "Import rules";
pub const IMPORT_MERGE: &str = "Merge (skip duplicates)";
pub const IMPORT_REPLACE: &str = "Replace";
pub const IMPORT_TO_TAB: &str = "Apply to this tab";
pub const IMPORT_TO_GLOBAL: &str = "Save as global default";
pub fn import_summary(path: &Path, n: usize) -> String {
format!("{} — {n} rules", path.display())
}
pub fn import_invalid(n: usize) -> String {
format!("{n} invalid rules will be skipped:")
}
pub fn import_use_pattern(name: &str) -> String {
format!("Use entry-start pattern “{name}”")
}
pub fn imported(n: usize) -> String {
format!("Imported {n} rules")
}
pub const EXPORT_TITLE: &str = "Export rules";
pub const EXPORT_ALL: &str = "Everything";
pub const EXPORT_FILTERS: &str = "Filters";
pub const EXPORT_HIGHLIGHTS: &str = "Highlights";
pub const EXPORT_SELECTED: &str = "Selected";
pub const EXPORT_SAVE: &str = "Save…";
pub fn export_include_pattern(name: &str) -> String {
format!("Include entry-start pattern “{name}”")
}
pub fn exported(n: usize, path: &Path) -> String {
format!("Exported {n} rules to {}", path.display())
}
// ----- find in files -----
pub const GREP_TITLE: &str = "Find in files";
pub fn grep_title_in(folder: &str) -> String {
format!("Find in {folder}")
}
pub const GREP_FOLDER: &str = "Folder";
pub const GREP_BROWSE: &str = "Browse…";
pub const GREP_PATTERN: &str = "Pattern";
pub const GREP_PATTERN_HINT: &str = "text or regex";
pub const GREP_INCLUDE: &str = "Include";
pub const GREP_EXCLUDE: &str = "Exclude";
pub const GREP_EXCLUDE_HINT: &str = "*.gz;old/**";
pub const GREP_RECURSIVE: &str = "Recursive";
pub const GREP_GITIGNORE: &str = "Respect .gitignore";
pub const GREP_SKIP_BINARY: &str = "Skip binary files";
pub const GREP_MAX_SIZE: &str = "Max size (MB)";
pub const GREP_MAX_SIZE_HINT: &str = "any";
pub const GREP_SEARCH: &str = "🔍 Search";
pub const GREP_CAPPED: &str = "results capped (10,000 per file, 1M total)";
pub const GREP_COPY_TIP: &str = "Copy as path:line:text";
pub const GREP_EXPORT_FILE: &str = "grep-results.txt";
pub const GREP_HELP: &str = "Pick a folder and a pattern, then press Search. Double-click a hit to open it.";
pub const GREP_OPEN: &str = "Open in viewer";
pub const GREP_NEED_PATTERN: &str = "Enter a pattern";
pub fn grep_not_a_folder(path: &Path) -> String {
format!("{} is not a folder", path.display())
}
pub fn grep_summary(matches: &str, files: &str, searched: &str, running: bool) -> String {
let tail = if running { " (searching…)" } else { "" };
format!("{matches} matches in {files} of {searched} files{tail}")
}
pub fn grep_errors(n: usize) -> String {
format!("{n} errors")
}
pub fn grep_file_row(arrow: &str, path: &str, hits: &str, truncated: bool, size: &str) -> String {
let plus = if truncated { "+" } else { "" };
format!("{arrow} {path} ({hits} matches{plus}, {size})")
}
// ----- errors from the non-UI modules -----
pub fn cannot_open(path: &Path) -> String {
format!("cannot open {}", path.display())
}
pub fn cannot_read_metadata(path: &Path) -> String {
format!("cannot read metadata of {}", path.display())
}
pub fn is_a_folder(path: &Path) -> String {
format!("{} is a folder, not a file", path.display())
}
pub fn cannot_map(path: &Path) -> String {
format!("cannot map {}", path.display())
}
pub const INVALID_PATTERN: &str = "invalid pattern";
pub const EMPTY_PATTERN: &str = "empty pattern";
pub const NO_CONFIG_FOLDER: &str = "no config folder";
pub fn bad_include_glob(g: &str) -> String {
format!("bad include glob {g}")
}
pub fn bad_exclude_glob(g: &str) -> String {
format!("bad exclude glob {g}")
}
pub fn rule_file_too_new(found: impl Display, supported: impl Display) -> String {
format!("rule file version {found} is newer than this app supports ({supported})")
}
pub fn invalid_rule(kind: impl std::fmt::Debug, pattern: &str, e: impl Display) -> String {
format!("{kind:?} rule `{pattern}`: {e:#}")
}
pub fn invalid_entry_pattern(regex: &str, e: impl Display) -> String {
format!("entry-start pattern `{regex}`: {e:#}")
}