Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Social Engine & Remote Navigator8 * File : apps/social-web/src/i18n.ts9 * Module : social-web10 * Repository : https://git.spboucher.ai/maclustr-social11 * Project Website : https://social.spboucher.ai12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Dictionary-based i18n. French is the default; every user-visible string goes through t().43import common from './i18n/common.ts';44import shell from './i18n/shell.ts';45import editorial from './i18n/editorial.ts';46import operations from './i18n/operations.ts';47import settings from './i18n/settings.ts';4849export const D = { ...common, ...shell, ...editorial, ...operations, ...settings };50export type Key = keyof typeof D;51export type Lang = 'fr' | 'en';52export const LANGS: Lang[] = ['fr', 'en'];53export const localeOf = (lang: Lang) => (lang === 'fr' ? 'fr-CA' : 'en-CA');54export type Vars = Record<string, string | number>;55export type TFn = (key: Key, vars?: Vars) => string;5657const fill = (s: string, vars?: Vars) => (vars ? s.replace(/\{(\w+)\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m)) : s);58export function translate(lang: Lang, key: Key, vars?: Vars): string {59 const e = D[key] as readonly [string, string] | undefined;60 return e ? fill(e[lang === 'fr' ? 0 : 1], vars) : key;61}62/** Label for a server enum value (`prefix.value`). Unknown values are shown verbatim rather than hidden. */63export function labelOf(lang: Lang, prefix: string, value: string | null | undefined): string {64 if (value === null || value === undefined || value === '') return '—';65 const e = (D as Record<string, readonly [string, string]>)[`${prefix}.${value}`];66 return e ? e[lang === 'fr' ? 0 : 1] : String(value);67}68export function hasLabel(prefix: string, value: string): boolean { return `${prefix}.${value}` in D; }69