| 264 | }) |
| 265 | |
| 266 | const getFileContent = (root, relPath, englishRoot) => { |
| 267 | const filePath = root ? path.join(root, relPath) : relPath |
| 268 | if (DEBUG_JIT_DATA_READS) console.log('READ', filePath) |
| 269 | try { |
| 270 | return fs.readFileSync(filePath, 'utf-8') |
| 271 | } catch (err) { |
| 272 | // It might fail because that particular data entry doesn't yet |
| 273 | // exist in a translation |
| 274 | if (err.code === 'ENOENT') { |
| 275 | // If looking it up as a file fails, give it one more chance if the |
| 276 | // read was for a translation. |
| 277 | if (root !== englishRoot) { |
| 278 | // We can try again but this time using the English files |
| 279 | return getFileContent(englishRoot, relPath, englishRoot) |
| 280 | } |
| 281 | } |
| 282 | throw err |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | function memoize(func) { |
| 287 | const cache = new Map() |