MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / detectLanguage

Function detectLanguage

graph-ui/src/lib/i18n.ts:152–171  ·  view source on GitHub ↗
(acceptLanguage?: string | null, override?: string | null)

Source from the content-addressed store, hash-verified

150export type UiMessages = (typeof messages)[UiLanguage];
151
152export function detectLanguage(acceptLanguage?: string | null, override?: string | null): UiLanguage {
153 if (override === "zh" || override === "en") return override;
154 if (!acceptLanguage) return "en";
155
156 // Ranked by q, not by whether "zh" appears anywhere. A substring test served
157 // Chinese for "en-US,en;q=0.9,zh;q=0.5", where English is clearly preferred,
158 // and for "zh;q=0, en", where q=0 means Chinese is unacceptable.
159 const best = acceptLanguage
160 .split(",")
161 .map((part) => {
162 const [tag, ...params] = part.trim().split(";");
163 const q = params.map((p) => /^\s*q\s*=\s*([\d.]+)\s*$/i.exec(p)).find(Boolean);
164 return { tag: tag.trim().toLowerCase(), q: q ? Number(q[1]) : 1 };
165 })
166 .filter(({ tag, q }) => tag && Number.isFinite(q) && q > 0)
167 .sort((a, b) => b.q - a.q)
168 .find(({ tag }) => tag.split("-")[0] === "zh" || tag.split("-")[0] === "en");
169
170 return best?.tag.startsWith("zh") ? "zh" : "en";
171}
172
173let cachedLanguage: UiLanguage = "en";
174let languageLoaded = false;

Callers 2

i18n.test.tsFile · 0.90
loadUiLanguageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected