@jsverse/transloco
Version:
The internationalization (i18n) library for Angular
31 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTranslateFilesFromOptions = exports.checkIfTranslationFilesExist = void 0;
const p = require("node:path");
const fs = require("fs");
const schematics_1 = require("@angular-devkit/schematics");
const schema_1 = require("../ng-add/schema");
const translation_files_gen_1 = require("../ng-add/generators/translation-files.gen");
function checkIfTranslationFilesExist(path, langs, extension, skipThrow) {
for (const lang of langs) {
const filePath = p.resolve(`${path}/${lang}${extension}`);
if (fs.existsSync(filePath)) {
if (skipThrow) {
return true;
}
throw new schematics_1.SchematicsException(`Translation file ${filePath} is already exist, please use --skip-creation`);
}
}
return false;
}
exports.checkIfTranslationFilesExist = checkIfTranslationFilesExist;
function createTranslateFilesFromOptions(host, options, translationFilePath) {
const extension = options.translateType === schema_1.TranslationFileTypes.Typescript ? '.ts' : '.json';
const translationCreator = options.translateType === schema_1.TranslationFileTypes.Typescript
? translation_files_gen_1.typescriptTranslationFileCreator
: translation_files_gen_1.jsonTranslationFileCreator;
checkIfTranslationFilesExist(translationFilePath, options.langs, extension);
return (0, translation_files_gen_1.createTranslateFiles)(options.langs, translationCreator, translationFilePath);
}
exports.createTranslateFilesFromOptions = createTranslateFilesFromOptions;
//# sourceMappingURL=translations.js.map