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
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import type { SupportedLocale } from "@/app/lib/i18n/locales";
|
|
|
|
// Assembles/parses the `content` JSON blob mobile-api's Message.content carries
|
|
// (locale -> translated text), per spec "The Portal Manages Translations Across
|
|
// Areas": "assembling them into the `content` JSON blob".
|
|
|
|
/**
|
|
* Builds the `content` blob from the add/edit form's per-locale text fields.
|
|
* Only the RUNTIME locale list is considered (add-admin-locale-management: the
|
|
* list comes from LocalesProvider, not a hardcoded array); an
|
|
* empty/whitespace-only value is omitted rather than stored as `""`, so the
|
|
* list's filled/empty indicator can tell "translated" from "blank"
|
|
* unambiguously.
|
|
*/
|
|
export function buildContentBlob(
|
|
perLocale: Record<string, string>,
|
|
locales: SupportedLocale[],
|
|
): string {
|
|
const filled: Record<string, string> = {};
|
|
for (const { code } of locales) {
|
|
const value = perLocale[code]?.trim();
|
|
if (value) filled[code] = value;
|
|
}
|
|
return JSON.stringify(filled);
|
|
}
|
|
|
|
/** Parses a stored `content` blob back into a locale->text record for the edit
|
|
* form's prefill and the list's filled/empty indicator. Never throws: malformed
|
|
* or non-object content resolves to `{}` rather than breaking the page. */
|
|
export function parseContentBlob(content: string | null | undefined): Record<string, string> {
|
|
if (!content) return {};
|
|
try {
|
|
const parsed = JSON.parse(content);
|
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
return parsed as Record<string, string>;
|
|
}
|
|
return {};
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
/** Renders a value that may arrive as either a plain display string or a raw
|
|
* locale-JSON blob (e.g. seeded data that skipped the backend's display-string
|
|
* normalisation) as a single displayable string. Prefers `en_US`, falls back to
|
|
* the first locale present, and passes a plain string through unchanged. Never
|
|
* throws and never renders raw JSON. */
|
|
export function displayLocaleName(value: string | null | undefined): string {
|
|
const parsed = parseContentBlob(value);
|
|
const keys = Object.keys(parsed);
|
|
if (keys.length === 0) return value ?? "";
|
|
if ("en_US" in parsed) return parsed.en_US;
|
|
return parsed[keys[0]];
|
|
}
|