function processTemplateFile()

in scripts/generateTemplates.js [183:215]


function processTemplateFile(fileData, cohortIndexEntries, workbookIndexEntries, templatePath, rootDirectory, languages) {
    try {
        // Location of translated RESJSON outputted by the localization build
        const translatedRESJSONPath = getClonedLocFilePath(templatePath, rootDirectory, WorkbookFileType.Template);

        const packageOutputPath = getPackageOutputPath(templatePath, rootDirectory, cohortIndexEntries, workbookIndexEntries);
        if (!templatePath.endsWith("\\")) {
            // Generate localized templates
            languages.forEach(lang => {
                // Location of translated resjson
                const localizedFilePath = translatedRESJSONPath.replace(LangOutputSpecifier, lang);
                // Location of package for translated workbook
                const translatedResultPath = packageOutputPath.replace(LangOutputSpecifier, LanguagesMap[lang]);

                if (lang === DefaultLang) {
                    writeTranslatedFile(fileData, translatedResultPath);
                } else {
                    if (fs.existsSync(localizedFilePath)) {
                        // Do workbook string replacement here
                        const jsonData = fs.readFileSync(localizedFilePath, Encoding);
                        parseTemplateResult(jsonData, fileData, translatedResultPath);
                    } else {
                        // No loc file found, just push the workbook file as is in English
                        logMessage("Did not find localized file in: " + localizedFilePath);
                        writeTranslatedFile(fileData, translatedResultPath);
                    }
                }
            });
        }
    } catch (e) {
        logError("Failed to process template file: " + templatePath + "Error: " + e, true);
    }
}