All files / infrastructure/translations/server/src/utils readLocale.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

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            2x   2x 4x 2x        
import { fileURLToPath } from "node:url";
import type { Messages } from "../types/Messages.ts";
import path from "node:path";
import { PROJECTS_PATH } from "../configs/constants.ts";
import { readFile } from "node:fs/promises";
 
const PROJECTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), PROJECTS_PATH);
 
const readLocale = async (project: string, locale: string): Promise<Messages> => {
    const raw = await readFile(path.join(PROJECTS_DIR, project, `${locale}.json`), "utf-8");
    return JSON.parse(raw) as Messages;
};
 
export default readLocale;