i18n: complete Slovak Monitor and CLI messages

This commit is contained in:
VAIO73
2026-10-21 09:53:29 +00:00
parent 65f47ec646
commit 6b41ff4247
23 changed files with 1228 additions and 188 deletions
+17
View File
@@ -0,0 +1,17 @@
import enMessages from "../messages/en/common.json"
import skMessages from "../messages/sk/common.json"
import { detectBrowserLanguage, LANGUAGE_STORAGE_KEY } from "./i18n/languages"
type Failure = keyof typeof enMessages.apiErrors
// fetchApi also runs outside React hooks. Read the provider's current document
// language, with its stored/browser preference as a fallback.
export function apiFailure(key: Failure, params: Record<string, string | number> = {}): string {
let language = typeof document === "undefined" ? "" : document.documentElement?.lang
if (!language && typeof window !== "undefined") {
try { language = window.localStorage.getItem(LANGUAGE_STORAGE_KEY) || "" } catch { /* private browsing */ }
}
language ||= detectBrowserLanguage()
const messages = language === "sk" ? skMessages.apiErrors : enMessages.apiErrors
return messages[key].replace(/\{(\w+)\}/g, (match, name) => params[name] === undefined ? match : String(params[name]))
}