hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { formatMessage, type Locale } from "@/i18n/messages"; |
| 2 | |
| 3 | /** |
| 4 | * Copy for the AI output drawer and its export actions. |
| 5 | * |
| 6 | * These strings deliberately live in their own module instead of the shared |
| 7 | * `src/i18n/messages.ts` table: that file is being edited by sibling lanes on |
| 8 | * the same day this drawer was built. The shape mirrors the shared table — a |
| 9 | * typed key union, one dict per locale, `{var}` interpolation through |
| 10 | * `formatMessage` — so the entries can be folded into the shared table later |
| 11 | * without touching a call site. |
| 12 | */ |
| 13 | export type RagOutputMessageKey = |
| 14 | | "view" |
| 15 | | "drawerTitle" |
| 16 | | "date" |
| 17 | | "note" |
| 18 | | "sources" |
| 19 | | "noSources" |
| 20 | | "unnamedSource" |
| 21 | | "emptyText" |
| 22 | | "failedTitle" |
| 23 | | "failedLine" |
| 24 | | "otherFields" |
| 25 | | "chunks" |
| 26 | | "passages" |
| 27 | | "passagePagesSingle" |
| 28 | | "passagePagesRange" |
| 29 | | "passagesTruncated" |
| 30 | | "passagesTruncatedNoTotal" |
| 31 | | "noteText" |
| 32 | | "technical" |
| 33 | | "copy" |
| 34 | | "copied" |
| 35 | | "copyFailed" |
| 36 | | "download" |
| 37 | | "print"; |
| 38 | |
| 39 | const en: Record<RagOutputMessageKey, string> = { |
| 40 | "view": "View", |
| 41 | "drawerTitle": "AI output", |
| 42 | "date": "Date", |
| 43 | "note": "Note", |
| 44 | "sources": "Source attachments", |
| 45 | "noSources": "No attachments — built from the note text.", |
| 46 | "unnamedSource": "Unnamed attachment", |
| 47 | "emptyText": "This output has no readable text. The raw record is below.", |
| 48 | "failedTitle": "Some attachments could not be processed", |
| 49 | "failedLine": "Not processed: {names}", |
| 50 | "otherFields": "Other fields", |
| 51 | "chunks": "Text chunks", |
| 52 | "passages": "Extracted text", |
| 53 | "passagePagesSingle": "p. {page}", |
| 54 | "passagePagesRange": "pp. {start}-{end}", |
| 55 | "passagesTruncated": "{total} passages were extracted in total; the first {shown} are listed here.", |
| 56 | "passagesTruncatedNoTotal": "Only the first {shown} extracted passages are listed here.", |
| 57 | "noteText": "Note text", |
| 58 | "technical": "Technical details", |
| 59 | "copy": "Copy", |
| 60 | "copied": "Copied to the clipboard", |
| 61 | "copyFailed": "Could not copy to the clipboard.", |
| 62 | "download": "Download (.md)", |
| 63 | "print": "Print / PDF", |
| 64 | }; |
| 65 | |
| 66 | const tr: Record<RagOutputMessageKey, string> = { |
| 67 | "view": "Görüntüle", |
| 68 | "drawerTitle": "YZ çıktısı", |
| 69 | "date": "Tarih", |
| 70 | "note": "Not", |
| 71 | "sources": "Kaynak ekler", |
| 72 | "noSources": "Ek yok — not metninden oluşturuldu.", |
| 73 | "unnamedSource": "Adı bilinmeyen ek", |
| 74 | "emptyText": "Bu çıktıda okunabilir bir metin yok. Ham kayıt aşağıdadır.", |
| 75 | "failedTitle": "Bazı ekler işlenemedi", |
| 76 | "failedLine": "İşlenemeyenler: {names}", |
| 77 | "otherFields": "Diğer alanlar", |
| 78 | "chunks": "Metin parçaları", |
| 79 | "passages": "Çıkarılan metin", |
| 80 | "passagePagesSingle": "s. {page}", |
| 81 | "passagePagesRange": "s. {start}-{end}", |
| 82 | "passagesTruncated": "Toplam {total} metin parçası çıkarıldı; burada ilk {shown} tanesi gösteriliyor.", |
| 83 | "passagesTruncatedNoTotal": "Çıkarılan parçaların yalnızca ilk {shown} tanesi gösteriliyor.", |
| 84 | "noteText": "Not metni", |
| 85 | "technical": "Teknik ayrıntı", |
| 86 | "copy": "Kopyala", |
| 87 | "copied": "Panoya kopyalandı", |
| 88 | "copyFailed": "Panoya kopyalanamadı.", |
| 89 | "download": "İndir (.md)", |
| 90 | "print": "Yazdır / PDF", |
| 91 | }; |
| 92 | |
| 93 | export function ragOutputMessage( |
| 94 | locale: Locale, |
| 95 | key: RagOutputMessageKey, |
| 96 | vars?: Record<string, string | number>, |
| 97 | ): string { |
| 98 | return formatMessage((locale === "tr" ? tr : en)[key], vars); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * One passage's page range (`s. 3-4`), or an empty string when the service |
| 103 | * recorded no page — the label is then left off entirely. |
| 104 | */ |
| 105 | export function ragOutputPassagePages( |
| 106 | locale: Locale, |
| 107 | pageStart: number | null, |
| 108 | pageEnd: number | null, |
| 109 | ): string { |
| 110 | if (pageStart == null) return ""; |
| 111 | if (pageEnd == null || pageEnd <= pageStart) { |
| 112 | return ragOutputMessage(locale, "passagePagesSingle", { page: pageStart }); |
| 113 | } |
| 114 | return ragOutputMessage(locale, "passagePagesRange", { start: pageStart, end: pageEnd }); |
| 115 | } |