Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 2x 1x 2x 2x 2x 1x | import { http, HttpResponse, type HttpHandler } from "msw";
import type { Locale, TranslationMap } from "#core/domain/translations";
/** MSW handlers that serve each locale's messages the way Tolgee's export API would. */
export const tolgeeHandlers = (
baseURL: string,
translations: Record<Locale, TranslationMap>,
): HttpHandler[] => [
http.get(`${baseURL}/v2/projects/:project/translations/:locale`, ({ params }) => {
const locale = String(params.locale);
const messages = translations[locale];
if (!messages) return HttpResponse.json({ code: "language_not_found" }, { status: 404 });
// Tolgee nests the map under its locale, which TolgeeProvider unwraps
return HttpResponse.json({ [locale]: messages });
}),
];
|