danielsitek/tateru-cli

View on GitHub
src/utils/loadTranslation.ts

Summary

Maintainability
A
3 hrs
Test Coverage
import fs from 'fs';
import path from 'path';


export const loadTranslation = (projectRoot: string, translationFilePath: string): any => {
    const translationFileSrc = path.resolve(projectRoot, translationFilePath);

    if (!fs.existsSync(translationFileSrc)) {
        throw new Error(`Cannot load translation file ${translationFileSrc}`);
    }

    const contentString = fs.readFileSync(translationFileSrc).toString('utf8');
    const contentJson = JSON.parse(contentString);

    return {
        ...contentJson
    };
};