Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
// UI locale display entries. Ported from solvway-customer-portal's
|
|
// app/lib/i18n/locales.ts. The admin portal reads the same Area-A catalog and
|
|
// supports the same locales.
|
|
//
|
|
// add-admin-locale-management: the supported set is now DB-driven. The old
|
|
// hardcoded SUPPORTED_LOCALES array is downgraded to FALLBACK_LOCALES — used
|
|
// ONLY when the runtime registry fetch fails, so a registry outage degrades to
|
|
// the two registry locales instead of an empty language switcher. The runtime list
|
|
// is fetched by app/lib/server/locales.ts (admin -> /api/admin/locales) and
|
|
// handed to the switcher / /messages inputs via LocalesProvider.
|
|
export interface SupportedLocale {
|
|
code: string;
|
|
label: string;
|
|
// Whether the locale is exposed to users. Omitted on FALLBACK_LOCALES (always
|
|
// shown). The switcher and resolveLocale treat only `enabled === false` as
|
|
// hidden; the /messages editor still receives disabled rows for staging.
|
|
enabled?: boolean;
|
|
}
|
|
|
|
export const FALLBACK_LOCALES: SupportedLocale[] = [
|
|
{ code: "en_US", label: "English" },
|
|
{ code: "zh_CN", label: "简体中文" },
|
|
];
|
|
|
|
export const DEFAULT_LOCALE = "en_US";
|
|
|
|
/**
|
|
* Map a raw Accept-Language header to one of the RUNTIME locale codes (else
|
|
* DEFAULT_LOCALE). The family heuristics (zh*, id/in, ms, en) still apply but
|
|
* only resolve to a code that is actually in the runtime set — a registry that
|
|
* drops a locale can never steer users onto it.
|
|
*/
|
|
export function resolveLocale(
|
|
acceptLanguage: string | null | undefined,
|
|
codes: string[],
|
|
): string {
|
|
if (!acceptLanguage) return DEFAULT_LOCALE;
|
|
const first = acceptLanguage.split(",")[0]?.trim().toLowerCase() ?? "";
|
|
if (!first) return DEFAULT_LOCALE;
|
|
const canonical = first.replaceAll("-", "_");
|
|
|
|
const exact = codes.find(c => c.toLowerCase() === canonical);
|
|
if (exact) return exact;
|
|
|
|
const has = (code: string) => codes.includes(code);
|
|
if (canonical.startsWith("zh")) {
|
|
if (has("zh_TW") && (canonical.includes("tw") || canonical.includes("hk") || canonical.includes("hant"))) {
|
|
return "zh_TW";
|
|
}
|
|
if (has("zh_CN")) return "zh_CN";
|
|
if (has("zh_TW")) return "zh_TW";
|
|
return DEFAULT_LOCALE;
|
|
}
|
|
// "in" is the deprecated ISO-639 code for Indonesian; the backend uses in_ID.
|
|
if ((canonical.startsWith("id") || canonical.startsWith("in")) && has("in_ID")) return "in_ID";
|
|
if (canonical.startsWith("ms") && has("ms_MY")) return "ms_MY";
|
|
if (canonical.startsWith("en") && has("en_US")) return "en_US";
|
|
return DEFAULT_LOCALE;
|
|
}
|