kawkab-frontend
Version:
Kawkab frontend is a frontend library for the Kawkab framework
30 lines (29 loc) • 1.13 kB
JavaScript
import { generateFile } from '../utils/stub.js';
import fs from 'fs-extra';
import path from 'path';
export function makeTransCommand(program) {
program
.command('make:trans <lang> [module]')
.description('Create a new translation file for a specific language in a module')
.action((lang, module = 'main') => {
const langCode = lang.toLowerCase();
const targetPath = `app/${module}/translations/${langCode}.json`;
const absoluteTargetPath = path.resolve(process.cwd(), targetPath);
if (fs.existsSync(absoluteTargetPath)) {
try {
const fileContent = fs.readJsonSync(absoluteTargetPath);
const newKey = `new_key_${Date.now()}`;
if (!fileContent[newKey]) {
fileContent[newKey] = "New translation value";
fs.writeJsonSync(absoluteTargetPath, fileContent, { spaces: 2 });
}
}
catch (error) {
}
return;
}
generateFile('trans.stub', targetPath, {
LangCode: langCode,
});
});
}