| 312 | * @returns {Promise<undefined>} - A promise that resolves when all locales have been written. |
| 313 | */ |
| 314 | const writeLocales = async (locales, backendIds) => |
| 315 | Promise.all( |
| 316 | Object.keys(locales).map(async key => { |
| 317 | const locale = locales[key] |
| 318 | let cleaned = locale |
| 319 | if (key === defaultLocale && !backendOnly) { |
| 320 | // Remove backend keys from the default locale |
| 321 | cleaned = Object.keys(locale).reduce((acc, next) => { |
| 322 | if (!backendIds.includes(next)) { |
| 323 | return { |
| 324 | ...acc, |
| 325 | [next]: locale[next], |
| 326 | } |
| 327 | } |
| 328 | return acc |
| 329 | }, {}) |
| 330 | } |
| 331 | const content = JSON.stringify(cleaned, null, 2).concat('\n') |
| 332 | await mkdirp(localesDir) |
| 333 | await write(`${localesDir}/${key}.json`, content) |
| 334 | }), |
| 335 | ) |
| 336 | |
| 337 | /** |
| 338 | * Write messages out for supported locales as CSV, for use when translating. |