project_note
Clone
https://git.tahinli.com/Tahinli/project_note.git
0 watching·0 forks·Rust·3.6 MiB·c49f5e7·Tahinli·1 month ago·2 commits
| 1 | //! Localization: the supported languages, the message catalogue, count and date |
| 2 | //! formatting, and language resolution from the request. |
| 3 | //! |
| 4 | //! Every message is one arm of [`t`]'s single `match` over [`Msg`], and each arm gives |
| 5 | //! both languages. A message without a Turkish text does not compile. |
| 6 | |
| 7 | use topcoat::{ |
| 8 | context::Cx, |
| 9 | cookie::{Cookie, Cookies, SameSite, cookies, time::Duration}, |
| 10 | router::request::headers, |
| 11 | }; |
| 12 | |
| 13 | /// Name of the cookie that stores the language choice. |
| 14 | pub const LANG_COOKIE: &str = "lang"; |
| 15 | |
| 16 | /// How long the language choice is remembered. |
| 17 | pub const LANG_COOKIE_DAYS: i64 = 365; |
| 18 | |
| 19 | /// A supported interface language. |
| 20 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 21 | pub enum Lang { |
| 22 | En, |
| 23 | Tr, |
| 24 | } |
| 25 | |
| 26 | impl Lang { |
| 27 | /// The value stored in the cookie and used in the `lang` attribute of `<html>`. |
| 28 | pub fn code(self) -> &'static str { |
| 29 | match self { |
| 30 | Self::En => "en", |
| 31 | Self::Tr => "tr", |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /// Parses a cookie or form value. Returns `None` for unsupported languages. |
| 36 | pub fn from_code(code: &str) -> Option<Self> { |
| 37 | match code { |
| 38 | "en" => Some(Self::En), |
| 39 | "tr" => Some(Self::Tr), |
| 40 | _ => None, |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /// Every interface message. Add a variant here, then its texts in [`t`]. |
| 46 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 47 | pub enum Msg { |
| 48 | AppName, |
| 49 | MainNavigation, |
| 50 | SkipToContent, |
| 51 | Search, |
| 52 | SearchLabel, |
| 53 | SearchPlaceholder, |
| 54 | NewNote, |
| 55 | NewNotebook, |
| 56 | NewNotebookLabel, |
| 57 | Add, |
| 58 | AllNotes, |
| 59 | Unfiled, |
| 60 | Trash, |
| 61 | Notebooks, |
| 62 | Theme, |
| 63 | ThemeLight, |
| 64 | ThemeDark, |
| 65 | ThemeSystem, |
| 66 | ColorScheme, |
| 67 | Language, |
| 68 | LanguageEnglish, |
| 69 | LanguageTurkish, |
| 70 | HideSidebar, |
| 71 | ShowSidebar, |
| 72 | OpenMenu, |
| 73 | CloseMenu, |
| 74 | Undo, |
| 75 | Dismiss, |
| 76 | ToastTrashed, |
| 77 | ToastRestored, |
| 78 | ToastNotebookCreated, |
| 79 | ToastNotebookDeleted, |
| 80 | ToastMoved, |
| 81 | Untitled, |
| 82 | JustNow, |
| 83 | Yesterday, |
| 84 | NoNotesYet, |
| 85 | CreateOneHint, |
| 86 | EmptyNotebook, |
| 87 | EmptyUnfiled, |
| 88 | EmptyTrash, |
| 89 | SelectNote, |
| 90 | GroupToday, |
| 91 | GroupPrevious7, |
| 92 | GroupEarlier, |
| 93 | BackToList, |
| 94 | /// Link under a list that has more rows than are shown. |
| 95 | ShowMore, |
| 96 | MoveToNotebook, |
| 97 | AlreadyHere, |
| 98 | FindNotebook, |
| 99 | NotebookByName, |
| 100 | NoSuchNotebook, |
| 101 | ExportAs, |
| 102 | ExportMarkdown, |
| 103 | ExportHtml, |
| 104 | ExportPdf, |
| 105 | ExportAll, |
| 106 | MoveToTrash, |
| 107 | InTrash, |
| 108 | AlreadyInTrash, |
| 109 | RestoreFirst, |
| 110 | Restore, |
| 111 | DeleteForever, |
| 112 | EmptyTrashAction, |
| 113 | TrashRetention, |
| 114 | Trashed, |
| 115 | ConfirmEmptyTrashTitle, |
| 116 | ConfirmForeverTitle, |
| 117 | CannotUndo, |
| 118 | Cancel, |
| 119 | Rename, |
| 120 | RenameNotebook, |
| 121 | NotebookOptions, |
| 122 | DeleteNotebook, |
| 123 | DeleteNotebookTitle, |
| 124 | DeleteNotebookBody, |
| 125 | Breadcrumb, |
| 126 | NoMatches, |
| 127 | GuestName, |
| 128 | GuestSubtitle, |
| 129 | AccountMenu, |
| 130 | SearchOptions, |
| 131 | MatchCase, |
| 132 | WholeWord, |
| 133 | ExactPhrase, |
| 134 | RegexSearch, |
| 135 | InvalidRegex, |
| 136 | InvalidRegexHint, |
| 137 | SearchPartial, |
| 138 | SearchAll, |
| 139 | CheckSpelling, |
| 140 | NoteActions, |
| 141 | VersionHistory, |
| 142 | CurrentVersion, |
| 143 | NoVersionsYet, |
| 144 | RestoreVersion, |
| 145 | BackToNote, |
| 146 | ToastVersionRestored, |
| 147 | Import, |
| 148 | ImportMarkdown, |
| 149 | ImportHelp, |
| 150 | ChooseFiles, |
| 151 | ChooseFolder, |
| 152 | ImportProgress, |
| 153 | ImportDoneOne, |
| 154 | ImportDoneMany, |
| 155 | ImportFailed, |
| 156 | ImportNoFiles, |
| 157 | ImportGoToNotes, |
| 158 | LinkedFrom, |
| 159 | NoNoteNamed, |
| 160 | CreateNote, |
| 161 | |
| 162 | // Editor |
| 163 | EditorPlaceholder, |
| 164 | EditorToolbarLabel, |
| 165 | EditorBubbleLabel, |
| 166 | EditorBlockMenu, |
| 167 | EditorNoMatches, |
| 168 | EditorNavigate, |
| 169 | EditorInsert, |
| 170 | EditorClose, |
| 171 | EditorUnavailable, |
| 172 | EditorUndo, |
| 173 | EditorRedo, |
| 174 | EditorParagraph, |
| 175 | EditorHeading1, |
| 176 | EditorHeading2, |
| 177 | EditorHeading3, |
| 178 | EditorBold, |
| 179 | EditorItalic, |
| 180 | EditorInlineCode, |
| 181 | EditorLink, |
| 182 | EditorBulletList, |
| 183 | EditorNumberedList, |
| 184 | EditorQuote, |
| 185 | EditorCodeBlock, |
| 186 | EditorDivider, |
| 187 | EditorText, |
| 188 | EditorLinkDialog, |
| 189 | EditorLinkMenu, |
| 190 | EditorLinkUrl, |
| 191 | EditorLinkInvalid, |
| 192 | EditorLinkNeedsLink, |
| 193 | EditorApply, |
| 194 | EditorRemove, |
| 195 | EditorOpen, |
| 196 | EditorEdit, |
| 197 | EditorStatusSaved, |
| 198 | EditorStatusSaving, |
| 199 | EditorStatusLocal, |
| 200 | EditorStatusReconnecting, |
| 201 | EditorStatusConnecting, |
| 202 | EditorAnnounceOffline, |
| 203 | EditorAnnounceOnline, |
| 204 | EditorPasteAsText, |
| 205 | EditorNoteMenu, |
| 206 | EditorCreateNote, |
| 207 | EditorNoNotesFound, |
| 208 | EditorUntitled, |
| 209 | EditorCodeLanguage, |
| 210 | EditorCodeAuto, |
| 211 | EditorCodeFormat, |
| 212 | EditorCodeFormatting, |
| 213 | EditorCodeFormatFailed, |
| 214 | EditorCodeFormatUnsupported, |
| 215 | EditorCodeCopy, |
| 216 | EditorCodeCopied, |
| 217 | EditorCodeAutoFormat, |
| 218 | EditorAttach, |
| 219 | EditorRecordAudio, |
| 220 | EditorStopRecording, |
| 221 | EditorMediaFailed, |
| 222 | EditorMicDenied, |
| 223 | EditorRecordingNow, |
| 224 | EditorRecordingLost, |
| 225 | EditorContinueRecording, |
| 226 | } |
| 227 | |
| 228 | /// The text of `msg` in `lang`. |
| 229 | pub fn t(lang: Lang, msg: Msg) -> &'static str { |
| 230 | // (English, Turkish) for every message. |
| 231 | let (en, tr) = match msg { |
| 232 | Msg::AppName => ("Notes", "Notlar"), |
| 233 | Msg::MainNavigation => ("Main navigation", "Ana gezinme"), |
| 234 | Msg::SkipToContent => ("Skip to content", "İçeriğe geç"), |
| 235 | Msg::Search => ("Search", "Ara"), |
| 236 | Msg::SearchLabel => ("Search notes", "Notlarda ara"), |
| 237 | Msg::SearchPlaceholder => ("Search notes", "Notlarda ara"), |
| 238 | Msg::NewNote => ("New note", "Yeni not"), |
| 239 | Msg::NewNotebook => ("New notebook", "Yeni defter"), |
| 240 | Msg::NewNotebookLabel => ("Notebook name", "Defter adı"), |
| 241 | Msg::Add => ("Add", "Ekle"), |
| 242 | Msg::AllNotes => ("All notes", "Tüm notlar"), |
| 243 | Msg::Unfiled => ("Unfiled", "Dosyalanmamış"), |
| 244 | Msg::Trash => ("Trash", "Çöp kutusu"), |
| 245 | Msg::Notebooks => ("Notebooks", "Defterler"), |
| 246 | Msg::Theme => ("Theme", "Tema"), |
| 247 | Msg::ThemeLight => ("Light", "Açık"), |
| 248 | Msg::ThemeDark => ("Dark", "Koyu"), |
| 249 | Msg::ThemeSystem => ("System", "Sistem"), |
| 250 | Msg::ColorScheme => ("Color scheme", "Renk şeması"), |
| 251 | Msg::Language => ("Language", "Dil"), |
| 252 | Msg::LanguageEnglish => ("English", "English"), |
| 253 | Msg::LanguageTurkish => ("Türkçe", "Türkçe"), |
| 254 | Msg::HideSidebar => ("Hide sidebar", "Kenar çubuğunu gizle"), |
| 255 | Msg::ShowSidebar => ("Show sidebar", "Kenar çubuğunu göster"), |
| 256 | Msg::OpenMenu => ("Open menu", "Menüyü aç"), |
| 257 | Msg::CloseMenu => ("Close menu", "Menüyü kapat"), |
| 258 | Msg::Undo => ("Undo", "Geri al"), |
| 259 | Msg::Dismiss => ("Dismiss", "Kapat"), |
| 260 | Msg::ToastTrashed => ("Note moved to trash.", "Not çöp kutusuna taşındı."), |
| 261 | Msg::ToastRestored => ("Note restored.", "Not geri yüklendi."), |
| 262 | Msg::ToastNotebookCreated => ("Notebook created.", "Defter oluşturuldu."), |
| 263 | Msg::ToastNotebookDeleted => ("Notebook deleted.", "Defter silindi."), |
| 264 | Msg::ToastMoved => ("Note moved.", "Not taşındı."), |
| 265 | Msg::Untitled => ("Untitled", "Adsız"), |
| 266 | Msg::JustNow => ("Just now", "Az önce"), |
| 267 | Msg::Yesterday => ("Yesterday", "Dün"), |
| 268 | Msg::NoNotesYet => ("No notes yet.", "Henüz not yok."), |
| 269 | Msg::CreateOneHint => ("to create one.", "ile yeni not oluştur."), |
| 270 | Msg::EmptyNotebook => ("Nothing in this notebook.", "Bu defterde not yok."), |
| 271 | Msg::EmptyUnfiled => ("Nothing unfiled.", "Dosyalanmamış not yok."), |
| 272 | Msg::EmptyTrash => ("Trash is empty.", "Çöp kutusu boş."), |
| 273 | Msg::SelectNote => ("Select a note", "Bir not seçin"), |
| 274 | Msg::GroupToday => ("Today", "Bugün"), |
| 275 | Msg::GroupPrevious7 => ("Previous 7 days", "Önceki 7 gün"), |
| 276 | Msg::GroupEarlier => ("Earlier", "Daha önce"), |
| 277 | Msg::BackToList => ("Back to list", "Listeye dön"), |
| 278 | Msg::ShowMore => ("Show more", "Daha fazla göster"), |
| 279 | Msg::MoveToNotebook => ("Move to notebook", "Defterine taşı"), |
| 280 | Msg::AlreadyHere => ("Already in this notebook.", "Zaten bu defterde."), |
| 281 | Msg::FindNotebook => ("Find a notebook…", "Defter bul…"), |
| 282 | Msg::NotebookByName => ("Notebook name", "Defter adı"), |
| 283 | Msg::NoSuchNotebook => ("No notebook has that name.", "Bu adda defter yok."), |
| 284 | Msg::ExportAs => ("Export as", "Şu biçimde dışa aktar"), |
| 285 | Msg::ExportMarkdown => ("Markdown (.md)", "Markdown (.md)"), |
| 286 | Msg::ExportHtml => ("HTML (.html)", "HTML (.html)"), |
| 287 | Msg::ExportPdf => ("PDF (print)", "PDF (yazdır)"), |
| 288 | Msg::ExportAll => ("Export all notes (.zip)", "Tüm notları dışa aktar (.zip)"), |
| 289 | Msg::MoveToTrash => ("Move to trash", "Çöp kutusuna taşı"), |
| 290 | Msg::InTrash => ("This note is in the trash.", "Bu not çöp kutusunda."), |
| 291 | Msg::AlreadyInTrash => ("Already in the trash.", "Zaten çöp kutusunda."), |
| 292 | Msg::RestoreFirst => ("Restore the note to move it.", "Notu taşımak için geri yükleyin."), |
| 293 | Msg::Restore => ("Restore", "Geri yükle"), |
| 294 | Msg::DeleteForever => ("Delete forever", "Kalıcı olarak sil"), |
| 295 | Msg::EmptyTrashAction => ("Empty trash", "Çöp kutusunu boşalt"), |
| 296 | Msg::TrashRetention => ( |
| 297 | "Notes in the trash are deleted after 30 days.", |
| 298 | "Çöp kutusundaki notlar 30 gün sonra silinir.", |
| 299 | ), |
| 300 | Msg::Trashed => ("Trashed", "Çöpe taşındı"), |
| 301 | Msg::ConfirmEmptyTrashTitle => ("Empty trash?", "Çöp kutusu boşaltılsın mı?"), |
| 302 | Msg::ConfirmForeverTitle => ("Delete this note forever?", "Bu not kalıcı olarak silinsin mi?"), |
| 303 | Msg::CannotUndo => ("This cannot be undone.", "Bu işlem geri alınamaz."), |
| 304 | Msg::Cancel => ("Cancel", "İptal"), |
| 305 | Msg::Rename => ("Rename", "Yeniden adlandır"), |
| 306 | Msg::RenameNotebook => ("Rename notebook", "Defteri yeniden adlandır"), |
| 307 | Msg::NotebookOptions => ("Notebook options", "Defter seçenekleri"), |
| 308 | Msg::DeleteNotebook => ("Delete notebook", "Defteri sil"), |
| 309 | Msg::DeleteNotebookTitle => ("Delete notebook?", "Defter silinsin mi?"), |
| 310 | Msg::DeleteNotebookBody => ("Its notes move to Unfiled.", "Notları Dosyalanmamış bölümüne taşınır."), |
| 311 | Msg::Breadcrumb => ("Breadcrumb", "Konum"), |
| 312 | Msg::NoMatches => ("No notes match.", "Eşleşen not yok."), |
| 313 | Msg::GuestName => ("Guest", "Misafir"), |
| 314 | Msg::GuestSubtitle => ("Personal library", "Kişisel kitaplık"), |
| 315 | Msg::AccountMenu => ("Account menu", "Hesap menüsü"), |
| 316 | Msg::SearchOptions => ("Search options", "Arama seçenekleri"), |
| 317 | Msg::MatchCase => ("Match case", "Büyük/küçük harfe duyarlı"), |
| 318 | Msg::WholeWord => ("Whole word", "Tam kelime"), |
| 319 | Msg::ExactPhrase => ("Exact phrase", "Tam ifade"), |
| 320 | Msg::RegexSearch => ("Regular expression", "Düzenli ifade"), |
| 321 | Msg::InvalidRegex => ("Not a valid regular expression.", "Geçerli bir düzenli ifade değil."), |
| 322 | Msg::InvalidRegexHint => ("Check the brackets and escapes.", "Parantezleri ve kaçış karakterlerini kontrol edin."), |
| 323 | Msg::SearchPartial => ("Some long notes were not searched yet.", "Bazı uzun notlarda henüz aranmadı."), |
| 324 | Msg::SearchAll => ("Search all", "Tümünde ara"), |
| 325 | Msg::CheckSpelling => ( |
| 326 | "Check the spelling or try fewer words.", |
| 327 | "Yazımı kontrol edin ya da daha az kelime deneyin.", |
| 328 | ), |
| 329 | Msg::NoteActions => ("Note actions", "Not işlemleri"), |
| 330 | Msg::Import => ("Import Markdown", "Markdown içe aktar"), |
| 331 | Msg::ImportMarkdown => ("Import Markdown…", "Markdown içe aktar…"), |
| 332 | Msg::ImportHelp => ( |
| 333 | "Import .md files or a whole folder (e.g. an Obsidian vault). Each subfolder becomes a notebook.", |
| 334 | "Tek tek .md dosyaları ya da bütün bir klasörü (ör. bir Obsidian kasası) içe aktarın. Her alt klasör bir deftere dönüşür.", |
| 335 | ), |
| 336 | Msg::ChooseFiles => ("Choose files", "Dosya seç"), |
| 337 | Msg::ChooseFolder => ("Choose folder", "Klasör seç"), |
| 338 | Msg::ImportProgress => ("Importing {done} of {total}…", "{done} / {total} içe aktarılıyor…"), |
| 339 | Msg::ImportDoneOne => ("Imported {n} note.", "{n} not içe aktarıldı."), |
| 340 | Msg::ImportDoneMany => ("Imported {n} notes.", "{n} not içe aktarıldı."), |
| 341 | Msg::ImportFailed => ("{m} failed.", "{m} başarısız."), |
| 342 | Msg::ImportNoFiles => ( |
| 343 | "No .md, .markdown or .txt files found.", |
| 344 | ".md, .markdown ya da .txt dosyası bulunamadı.", |
| 345 | ), |
| 346 | Msg::ImportGoToNotes => ("Go to notes", "Notlara git"), |
| 347 | Msg::LinkedFrom => ("Linked from", "Bağlantı veren notlar"), |
| 348 | Msg::NoNoteNamed => ("No note named \u{201c}{title}\u{201d}.", "\u{201c}{title}\u{201d} adlı not yok."), |
| 349 | Msg::CreateNote => ("Create note", "Not oluştur"), |
| 350 | Msg::VersionHistory => ("Version history", "Sürüm geçmişi"), |
| 351 | Msg::CurrentVersion => ("Current version", "Güncel sürüm"), |
| 352 | Msg::NoVersionsYet => ( |
| 353 | "No earlier versions yet. Versions are saved every 10 minutes while you write.", |
| 354 | "Henüz önceki sürüm yok. Yazarken sürümler her 10 dakikada bir kaydedilir.", |
| 355 | ), |
| 356 | Msg::RestoreVersion => ("Restore this version", "Bu sürümü geri yükle"), |
| 357 | Msg::BackToNote => ("Back to note", "Nota dön"), |
| 358 | Msg::ToastVersionRestored => ("Version restored.", "Sürüm geri yüklendi."), |
| 359 | // Editor |
| 360 | Msg::EditorPlaceholder => ("Start writing…", "Yazmaya başla…"), |
| 361 | Msg::EditorToolbarLabel => ("Formatting", "Biçimlendirme"), |
| 362 | Msg::EditorBubbleLabel => ("Text formatting", "Metin biçimlendirme"), |
| 363 | Msg::EditorBlockMenu => ("Insert block", "Blok ekle"), |
| 364 | Msg::EditorNoMatches => ("No matches", "Eşleşme yok"), |
| 365 | Msg::EditorNavigate => ("navigate", "gezin"), |
| 366 | Msg::EditorInsert => ("insert", "ekle"), |
| 367 | Msg::EditorClose => ("close", "kapat"), |
| 368 | Msg::EditorUnavailable => ("Not available here", "Bu alanda kullanılamaz"), |
| 369 | Msg::EditorUndo => ("Undo", "Geri al"), |
| 370 | Msg::EditorRedo => ("Redo", "Yinele"), |
| 371 | Msg::EditorParagraph => ("Paragraph", "Metin"), |
| 372 | Msg::EditorHeading1 => ("Heading 1", "Başlık 1"), |
| 373 | Msg::EditorHeading2 => ("Heading 2", "Başlık 2"), |
| 374 | Msg::EditorHeading3 => ("Heading 3", "Başlık 3"), |
| 375 | Msg::EditorBold => ("Bold", "Kalın"), |
| 376 | Msg::EditorItalic => ("Italic", "İtalik"), |
| 377 | Msg::EditorInlineCode => ("Inline code", "Kod"), |
| 378 | Msg::EditorLink => ("Link", "Bağlantı"), |
| 379 | Msg::EditorBulletList => ("Bullet list", "Madde listesi"), |
| 380 | Msg::EditorNumberedList => ("Numbered list", "Numaralı liste"), |
| 381 | Msg::EditorQuote => ("Quote", "Alıntı"), |
| 382 | Msg::EditorCodeBlock => ("Code block", "Kod bloğu"), |
| 383 | Msg::EditorDivider => ("Divider", "Ayırıcı"), |
| 384 | Msg::EditorText => ("Text", "Metin"), |
| 385 | Msg::EditorLinkDialog => ("Link", "Bağlantı"), |
| 386 | Msg::EditorLinkMenu => ("Link options", "Bağlantı seçenekleri"), |
| 387 | Msg::EditorLinkUrl => ("Link URL", "Bağlantı adresi"), |
| 388 | Msg::EditorLinkInvalid => ( |
| 389 | "Enter a valid link, such as example.com", |
| 390 | "Geçerli bir bağlantı girin, ör. example.com", |
| 391 | ), |
| 392 | Msg::EditorLinkNeedsLink => ("Add a link first", "Önce bir bağlantı ekleyin"), |
| 393 | Msg::EditorApply => ("Apply", "Uygula"), |
| 394 | Msg::EditorRemove => ("Remove", "Kaldır"), |
| 395 | Msg::EditorOpen => ("Open", "Aç"), |
| 396 | Msg::EditorEdit => ("Edit", "Düzenle"), |
| 397 | Msg::EditorStatusSaved => ("Saved", "Kaydedildi"), |
| 398 | Msg::EditorStatusSaving => ("Saving…", "Kaydediliyor…"), |
| 399 | Msg::EditorStatusLocal => ("Saved on this device", "Bu cihazda kaydedildi"), |
| 400 | Msg::EditorStatusReconnecting => ("Reconnecting…", "Yeniden bağlanıyor…"), |
| 401 | Msg::EditorStatusConnecting => ("Connecting…", "Bağlanıyor…"), |
| 402 | Msg::EditorAnnounceOffline => ( |
| 403 | "You are offline. Changes stay on this device.", |
| 404 | "Çevrimdışısınız. Değişiklikler bu cihazda kalır.", |
| 405 | ), |
| 406 | Msg::EditorAnnounceOnline => ("Back online.", "Yeniden çevrimiçisiniz."), |
| 407 | Msg::EditorPasteAsText => ("Paste as plain text", "Düz metin olarak yapıştır"), |
| 408 | Msg::EditorNoteMenu => ("Link to a note", "Nota bağlantısı"), |
| 409 | Msg::EditorCreateNote => ("Create note “{q}”", "“{q}” notunu oluştur"), |
| 410 | Msg::EditorNoNotesFound => ("No notes found", "Not bulunamadı"), |
| 411 | Msg::EditorUntitled => ("Untitled", "Adsız"), |
| 412 | Msg::EditorCodeLanguage => ("Language", "Dil"), |
| 413 | Msg::EditorCodeAuto => ("Auto", "Otomatik"), |
| 414 | Msg::EditorCodeFormat => ("Format", "Biçimlendir"), |
| 415 | Msg::EditorCodeFormatting => ("Formatting…", "Biçimlendiriliyor…"), |
| 416 | Msg::EditorCodeFormatFailed => ("Couldn't format", "Biçimlendirilemedi"), |
| 417 | Msg::EditorCodeFormatUnsupported => ("Formatting isn't available for this language", "Bu dil için biçimlendirme yok"), |
| 418 | Msg::EditorCodeCopy => ("Copy code", "Kodu kopyala"), |
| 419 | Msg::EditorCodeCopied => ("Copied", "Kopyalandı"), |
| 420 | Msg::EditorCodeAutoFormat => ("Format when leaving the block", "Bloktan çıkınca biçimlendir"), |
| 421 | Msg::EditorAttach => ("Attach file", "Dosya ekle"), |
| 422 | Msg::EditorRecordAudio => ("Record audio", "Ses kaydet"), |
| 423 | Msg::EditorStopRecording => ("Stop recording", "Kaydı durdur"), |
| 424 | Msg::EditorMediaFailed => ("Upload failed", "Yükleme başarısız"), |
| 425 | Msg::EditorMicDenied => ("Microphone unavailable", "Mikrofon kullanılamıyor"), |
| 426 | Msg::EditorRecordingNow => ("Recording…", "Kaydediliyor…"), |
| 427 | Msg::EditorRecordingLost => ("Connection lost, reconnecting…", "Bağlantı koptu, yeniden bağlanılıyor…"), |
| 428 | Msg::EditorContinueRecording => ("Continue recording", "Kayda devam et"), |
| 429 | }; |
| 430 | match lang { |
| 431 | Lang::En => en, |
| 432 | Lang::Tr => tr, |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /// The editor's UI strings, keyed by their original `web/src/i18n.ts` key, in that file's order. |
| 437 | pub const EDITOR_MSGS: &[(&str, Msg)] = &[ |
| 438 | ("placeholder", Msg::EditorPlaceholder), |
| 439 | ("toolbarLabel", Msg::EditorToolbarLabel), |
| 440 | ("bubbleLabel", Msg::EditorBubbleLabel), |
| 441 | ("blockMenu", Msg::EditorBlockMenu), |
| 442 | ("noMatches", Msg::EditorNoMatches), |
| 443 | ("navigate", Msg::EditorNavigate), |
| 444 | ("insert", Msg::EditorInsert), |
| 445 | ("close", Msg::EditorClose), |
| 446 | ("unavailable", Msg::EditorUnavailable), |
| 447 | ("undo", Msg::EditorUndo), |
| 448 | ("redo", Msg::EditorRedo), |
| 449 | ("paragraph", Msg::EditorParagraph), |
| 450 | ("heading1", Msg::EditorHeading1), |
| 451 | ("heading2", Msg::EditorHeading2), |
| 452 | ("heading3", Msg::EditorHeading3), |
| 453 | ("bold", Msg::EditorBold), |
| 454 | ("italic", Msg::EditorItalic), |
| 455 | ("inlineCode", Msg::EditorInlineCode), |
| 456 | ("link", Msg::EditorLink), |
| 457 | ("bulletList", Msg::EditorBulletList), |
| 458 | ("numberedList", Msg::EditorNumberedList), |
| 459 | ("quote", Msg::EditorQuote), |
| 460 | ("codeBlock", Msg::EditorCodeBlock), |
| 461 | ("divider", Msg::EditorDivider), |
| 462 | ("text", Msg::EditorText), |
| 463 | ("linkDialog", Msg::EditorLinkDialog), |
| 464 | ("linkMenu", Msg::EditorLinkMenu), |
| 465 | ("linkUrl", Msg::EditorLinkUrl), |
| 466 | ("linkInvalid", Msg::EditorLinkInvalid), |
| 467 | ("linkNeedsLink", Msg::EditorLinkNeedsLink), |
| 468 | ("apply", Msg::EditorApply), |
| 469 | ("remove", Msg::EditorRemove), |
| 470 | ("open", Msg::EditorOpen), |
| 471 | ("edit", Msg::EditorEdit), |
| 472 | ("statusSaved", Msg::EditorStatusSaved), |
| 473 | ("statusSaving", Msg::EditorStatusSaving), |
| 474 | ("statusLocal", Msg::EditorStatusLocal), |
| 475 | ("statusReconnecting", Msg::EditorStatusReconnecting), |
| 476 | ("statusConnecting", Msg::EditorStatusConnecting), |
| 477 | ("announceOffline", Msg::EditorAnnounceOffline), |
| 478 | ("announceOnline", Msg::EditorAnnounceOnline), |
| 479 | ("pasteAsText", Msg::EditorPasteAsText), |
| 480 | ("noteMenu", Msg::EditorNoteMenu), |
| 481 | ("createNote", Msg::EditorCreateNote), |
| 482 | ("noNotesFound", Msg::EditorNoNotesFound), |
| 483 | ("untitled", Msg::EditorUntitled), |
| 484 | ("codeLanguage", Msg::EditorCodeLanguage), |
| 485 | ("codeAuto", Msg::EditorCodeAuto), |
| 486 | ("codeFormat", Msg::EditorCodeFormat), |
| 487 | ("codeFormatting", Msg::EditorCodeFormatting), |
| 488 | ("codeFormatFailed", Msg::EditorCodeFormatFailed), |
| 489 | ("codeFormatUnsupported", Msg::EditorCodeFormatUnsupported), |
| 490 | ("codeCopy", Msg::EditorCodeCopy), |
| 491 | ("codeCopied", Msg::EditorCodeCopied), |
| 492 | ("codeAutoFormat", Msg::EditorCodeAutoFormat), |
| 493 | ("attach", Msg::EditorAttach), |
| 494 | ("recordAudio", Msg::EditorRecordAudio), |
| 495 | ("stopRecording", Msg::EditorStopRecording), |
| 496 | ("mediaFailed", Msg::EditorMediaFailed), |
| 497 | ("micDenied", Msg::EditorMicDenied), |
| 498 | ("recordingNow", Msg::EditorRecordingNow), |
| 499 | ("recordingLost", Msg::EditorRecordingLost), |
| 500 | ("continueRecording", Msg::EditorContinueRecording), |
| 501 | ]; |
| 502 | |
| 503 | /// "1 note" / "3 notes". Turkish does not inflect the noun after a number: "1 not", "3 not". |
| 504 | pub fn notes_count(lang: Lang, n: usize) -> String { |
| 505 | match lang { |
| 506 | Lang::En if n == 1 => "1 note".to_owned(), |
| 507 | Lang::En => format!("{n} notes"), |
| 508 | Lang::Tr => format!("{n} not"), |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | /// "1 result for “rust”" / "3 results for “rust”", or the Turkish "3 sonuç “rust” için". |
| 513 | pub fn results_for(lang: Lang, n: usize, query: &str) -> String { |
| 514 | match lang { |
| 515 | Lang::En if n == 1 => format!("1 result for \u{201c}{query}\u{201d}"), |
| 516 | Lang::En => format!("{n} results for \u{201c}{query}\u{201d}"), |
| 517 | Lang::Tr => format!("{n} sonuç \u{201c}{query}\u{201d} için"), |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /// The consequence line of the empty-trash dialog: "This deletes 3 notes forever." / |
| 522 | /// "3 not kalıcı olarak silinecek." |
| 523 | pub fn forever_count(lang: Lang, n: usize) -> String { |
| 524 | match lang { |
| 525 | Lang::En => format!("This deletes {} forever.", notes_count(lang, n)), |
| 526 | Lang::Tr => format!("{} kalıcı olarak silinecek.", notes_count(lang, n)), |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /// A relative time such as "5 min ago" or "5 dk önce", a day name, or a date for older |
| 531 | /// times. `now_ms` is the current time in Unix milliseconds. |
| 532 | pub fn relative_time(lang: Lang, updated_ms: i64, now_ms: i64) -> String { |
| 533 | let secs = (now_ms - updated_ms).max(0) / 1000; |
| 534 | let mins = secs / 60; |
| 535 | let hours = secs / 3600; |
| 536 | let days = secs / 86_400; |
| 537 | if secs < 60 { |
| 538 | t(lang, Msg::JustNow).to_owned() |
| 539 | } else if secs < 3600 { |
| 540 | match lang { |
| 541 | Lang::En => format!("{mins} min ago"), |
| 542 | Lang::Tr => format!("{mins} dk önce"), |
| 543 | } |
| 544 | } else if secs < 86_400 { |
| 545 | match lang { |
| 546 | Lang::En => format!("{hours} h ago"), |
| 547 | Lang::Tr => format!("{hours} sa önce"), |
| 548 | } |
| 549 | } else if days == 1 { |
| 550 | t(lang, Msg::Yesterday).to_owned() |
| 551 | } else if days < 7 { |
| 552 | match lang { |
| 553 | Lang::En => format!("{days} days ago"), |
| 554 | Lang::Tr => format!("{days} gün önce"), |
| 555 | } |
| 556 | } else { |
| 557 | date(lang, updated_ms) |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | /// A calendar date in UTC: "Oct 27, 2026" in English, "27 Eki 2026" in Turkish. |
| 562 | pub fn date(lang: Lang, ms: i64) -> String { |
| 563 | const EN: [&str; 12] = [ |
| 564 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", |
| 565 | ]; |
| 566 | const TR: [&str; 12] = [ |
| 567 | "Oca", "Şub", "Mar", "Nis", "May", "Haz", "Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara", |
| 568 | ]; |
| 569 | // Civil-from-days (Howard Hinnant's algorithm). |
| 570 | let z = ms.div_euclid(86_400_000) + 719_468; |
| 571 | let era = z.div_euclid(146_097); |
| 572 | let doe = z - era * 146_097; |
| 573 | let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365; |
| 574 | let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); |
| 575 | let mp = (5 * doy + 2) / 153; |
| 576 | let day = doy - (153 * mp + 2) / 5 + 1; |
| 577 | let month = if mp < 10 { mp + 3 } else { mp - 9 }; |
| 578 | let year = yoe + era * 400 + if month <= 2 { 1 } else { 0 }; |
| 579 | let idx = (month - 1) as usize; |
| 580 | match lang { |
| 581 | Lang::En => format!("{} {}, {}", EN[idx], day, year), |
| 582 | Lang::Tr => format!("{} {} {}", day, TR[idx], year), |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /// A date and UTC time: "Oct 27, 2026 14:05" in English, "27 Eki 2026 14:05" in Turkish. |
| 587 | pub fn date_time(lang: Lang, ms: i64) -> String { |
| 588 | let minutes = ms.rem_euclid(86_400_000) / 60_000; |
| 589 | format!("{} {:02}:{:02}", date(lang, ms), minutes / 60, minutes % 60) |
| 590 | } |
| 591 | |
| 592 | /// Picks the language from an `Accept-Language` header: the first listed language that is |
| 593 | /// English or Turkish. Anything else falls back to English. |
| 594 | pub fn from_accept_language(header: &str) -> Lang { |
| 595 | for part in header.split(',') { |
| 596 | let tag = part.split(';').next().unwrap_or("").trim().to_ascii_lowercase(); |
| 597 | if tag.starts_with("tr") { |
| 598 | return Lang::Tr; |
| 599 | } |
| 600 | if tag.starts_with("en") { |
| 601 | return Lang::En; |
| 602 | } |
| 603 | } |
| 604 | Lang::En |
| 605 | } |
| 606 | |
| 607 | /// The language of this request. The `lang` cookie wins; without it, the browser's |
| 608 | /// `Accept-Language` decides; otherwise English. |
| 609 | pub fn lang(cx: &Cx) -> Lang { |
| 610 | if let Some(cookie) = cookies(cx).get(LANG_COOKIE) { |
| 611 | if let Some(lang) = Lang::from_code(cookie.value()) { |
| 612 | return lang; |
| 613 | } |
| 614 | } |
| 615 | let header = headers(cx) |
| 616 | .get("accept-language") |
| 617 | .and_then(|value| value.to_str().ok()) |
| 618 | .unwrap_or(""); |
| 619 | from_accept_language(header) |
| 620 | } |
| 621 | |
| 622 | /// The cookie that remembers `lang` for a year. |
| 623 | pub fn lang_cookie(lang: Lang) -> Cookie<'static> { |
| 624 | Cookie::build((LANG_COOKIE, lang.code())) |
| 625 | .path("/") |
| 626 | .same_site(SameSite::Lax) |
| 627 | .max_age(Duration::days(LANG_COOKIE_DAYS)) |
| 628 | .build() |
| 629 | } |
| 630 | |
| 631 | /// The editor's strings as a JSON object, safe inside `<script type="application/json">`. |
| 632 | pub fn editor_strings_json(lang: Lang) -> String { |
| 633 | let mut out = String::from("{"); |
| 634 | for (i, (key, msg)) in EDITOR_MSGS.iter().enumerate() { |
| 635 | if i > 0 { |
| 636 | out.push(','); |
| 637 | } |
| 638 | for (j, s) in [*key, t(lang, *msg)].iter().enumerate() { |
| 639 | out.push('"'); |
| 640 | for c in s.chars() { |
| 641 | match c { |
| 642 | '"' => out.push_str("\\\""), |
| 643 | '\\' => out.push_str("\\\\"), |
| 644 | '<' => out.push_str("\\u003c"), |
| 645 | '\n' => out.push_str("\\n"), |
| 646 | c => out.push(c), |
| 647 | } |
| 648 | } |
| 649 | out.push('"'); |
| 650 | if j == 0 { |
| 651 | out.push(':'); |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | out.push('}'); |
| 656 | out |
| 657 | } |