// PEP-123: the words a person reads depend on the view (PEP-119). «Продакт» reads «задача» and // «агент» (docs/glossary.md); «Инженер» keeps «стори» (one OpenSpec change; «задачи» there are // the items of tasks.md) and «раннер» (the process, as opposed to the agent's persona). // Pure module: used by the browser too. export type WordMode = "product" | "engineer"; /** Case forms: singular nom/gen/dat/acc/ins/pre and the same in plural. */ export type WordForm = "nom" | "gen" | "dat" | "acc" | "ins" | "pre" | "pl" | "genPl" | "datPl" | "accPl" | "insPl" | "prePl"; export const BRAND = "Peppa FACTORY"; const TASK: Record = { nom: "задача", gen: "задачи", dat: "задаче", acc: "задачу", ins: "задачей", pre: "задаче", pl: "задачи", genPl: "задач", datPl: "задачам", accPl: "задачи", insPl: "задачами", prePl: "задачах", }; // «агент» and «раннер» decline alike; both are animate, so the accusative follows the genitive. const ENDING: Record = { nom: "", gen: "а", dat: "у", acc: "а", ins: "ом", pre: "е", pl: "ы", genPl: "ов", datPl: "ам", accPl: "ов", insPl: "ами", prePl: "ах" }; const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); /** «1 задача», «2 задачи», «5 задач» — the form of a counted noun. */ export function plural(n: number, one: string, few: string, many: string): string { const d = Math.abs(n) % 100; const u = d % 10; if (d > 10 && d < 20) return many; if (u === 1) return one; return u >= 2 && u <= 4 ? few : many; } export interface Words { mode: WordMode; /** True in «Продакт»: hide what only an engineer reads. */ product: boolean; engineer: boolean; /** «задача» / «стори» in the given form. */ task(form?: WordForm): string; /** The same, capitalized. */ Task(form?: WordForm): string; /** «5 задач» / «5 стори». */ tasks(n: number): string; /** «агент» / «раннер» in the given form. */ runner(form?: WordForm): string; Runner(form?: WordForm): string; } // PEP-98: English words of the two views. Russian templates stay keys of the dictionary; the word is // a {placeholder} filled from here, so «Создать {task}» reads «Create task» / «Create story». const EN_PLURAL = new Set(["pl", "genPl", "datPl", "accPl", "insPl", "prePl"]); export function wording(mode: WordMode | null | undefined, locale?: string | null): Words { const product = mode !== "engineer"; if (locale === "en") { const task = (form: WordForm = "nom") => (product ? "task" : "story") + (EN_PLURAL.has(form) ? (product ? "s" : "") : ""); const enTask = (form: WordForm = "nom") => (!product && EN_PLURAL.has(form) ? "stories" : task(form)); const runner = (form: WordForm = "nom") => (product ? "agent" : "runner") + (EN_PLURAL.has(form) ? "s" : ""); return { mode: product ? "product" : "engineer", product, engineer: !product, task: enTask, Task: (form) => cap(enTask(form)), tasks: (n) => `${n} ${enTask(n === 1 ? "nom" : "pl")}`, runner, Runner: (form) => cap(runner(form)), }; } const task = (form: WordForm = "nom") => (product ? TASK[form] : "стори"); const runner = (form: WordForm = "nom") => (product ? "агент" : "раннер") + ENDING[form]; return { mode: product ? "product" : "engineer", product, engineer: !product, task, Task: (form) => cap(task(form)), tasks: (n) => `${n} ${product ? plural(n, TASK.nom, TASK.gen, TASK.genPl) : "стори"}`, runner, Runner: (form) => cap(runner(form)), }; } /** Texts stored or sent without knowing the reader's view (chat events, Telegram, push). */ export const PRODUCT_WORDS = wording("product");