i18n: make localization context non-global
- Simplify Localization{Context,Manager} to just Localization
- Fixed a bunch of lifetime issueo
- Removed all Arcs and Locks
- Removed globals
* widgets now need access to &mut Localization for i18n
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -6,11 +6,11 @@ use nostrdb::{Ndb, Transaction};
|
||||
use notedeck::{
|
||||
contacts::{contacts_filter, hybrid_contacts_filter},
|
||||
filter::{self, default_limit, default_remote_limit, HybridFilter},
|
||||
tr, FilterError, FilterState, NoteCache, RootIdError, RootNoteIdBuf,
|
||||
tr, FilterError, FilterState, Localization, NoteCache, RootIdError, RootNoteIdBuf,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::{borrow::Cow, fmt::Display};
|
||||
use tokenator::{ParseError, TokenParser, TokenSerializable, TokenWriter};
|
||||
use tracing::{error, warn};
|
||||
|
||||
@@ -254,6 +254,7 @@ impl AlgoTimeline {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl Display for TimelineKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
@@ -301,6 +302,7 @@ impl Display for TimelineKind {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl TimelineKind {
|
||||
pub fn pubkey(&self) -> Option<&Pubkey> {
|
||||
@@ -594,31 +596,32 @@ impl TimelineKind {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_title(&self) -> ColumnTitle<'_> {
|
||||
pub fn to_title(&self, i18n: &mut Localization) -> ColumnTitle<'_> {
|
||||
match self {
|
||||
TimelineKind::Search(query) => {
|
||||
ColumnTitle::formatted(format!("Search \"{}\"", query.search))
|
||||
}
|
||||
TimelineKind::List(list_kind) => match list_kind {
|
||||
ListKind::Contact(_pubkey_source) => {
|
||||
ColumnTitle::formatted(tr!("Contacts", "Column title for contact lists"))
|
||||
ColumnTitle::formatted(tr!(i18n, "Contacts", "Column title for contact lists"))
|
||||
}
|
||||
},
|
||||
TimelineKind::Algo(AlgoTimeline::LastPerPubkey(list_kind)) => match list_kind {
|
||||
ListKind::Contact(_pubkey_source) => ColumnTitle::formatted(tr!(
|
||||
i18n,
|
||||
"Contacts (last notes)",
|
||||
"Column title for last notes per contact"
|
||||
)),
|
||||
},
|
||||
TimelineKind::Notifications(_pubkey_source) => {
|
||||
ColumnTitle::formatted(tr!("Notifications", "Column title for notifications"))
|
||||
ColumnTitle::formatted(tr!(i18n, "Notifications", "Column title for notifications"))
|
||||
}
|
||||
TimelineKind::Profile(_pubkey_source) => ColumnTitle::needs_db(self),
|
||||
TimelineKind::Universe => {
|
||||
ColumnTitle::formatted(tr!("Universe", "Column title for universe feed"))
|
||||
ColumnTitle::formatted(tr!(i18n, "Universe", "Column title for universe feed"))
|
||||
}
|
||||
TimelineKind::Generic(_) => {
|
||||
ColumnTitle::formatted(tr!("Custom", "Column title for custom timelines"))
|
||||
ColumnTitle::formatted(tr!(i18n, "Custom", "Column title for custom timelines"))
|
||||
}
|
||||
TimelineKind::Hashtag(hashtag) => ColumnTitle::formatted(hashtag.join(" ").to_string()),
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::{
|
||||
use notedeck::{
|
||||
contacts::hybrid_contacts_filter,
|
||||
filter::{self, HybridFilter},
|
||||
tr, Accounts, CachedNote, ContactState, FilterError, FilterState, FilterStates, NoteCache,
|
||||
NoteRef, UnknownIds,
|
||||
tr, Accounts, CachedNote, ContactState, FilterError, FilterState, FilterStates, Localization,
|
||||
NoteCache, NoteRef, UnknownIds,
|
||||
};
|
||||
|
||||
use egui_virtual_list::VirtualList;
|
||||
@@ -64,11 +64,15 @@ pub enum ViewFilter {
|
||||
}
|
||||
|
||||
impl ViewFilter {
|
||||
pub fn name(&self) -> String {
|
||||
pub fn name(&self, i18n: &mut Localization) -> String {
|
||||
match self {
|
||||
ViewFilter::Notes => tr!("Notes", "Filter label for notes only view"),
|
||||
ViewFilter::Notes => tr!(i18n, "Notes", "Filter label for notes only view"),
|
||||
ViewFilter::NotesAndReplies => {
|
||||
tr!("Notes & Replies", "Filter label for notes and replies view")
|
||||
tr!(
|
||||
i18n,
|
||||
"Notes & Replies",
|
||||
"Filter label for notes and replies view"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user