Ghost/ghost/i18n/generate-context.js
Daniel Lockyer 3432857f9a
Added locales/context.json to help with translating
refs https://ghost.slack.com/archives/CFH10N79S/p1679491616052209?thread_ts=1679411948.063929&cid=CFH10N79S

- this adds a small script to generate a `context.json` file, which
  contains all keys and allows people to provide context on the
  translation
2023-03-23 16:29:59 +01:00

29 lines
772 B
JavaScript

const fs = require('fs').promises;
const path = require('path');
const BASE_PATH = './locales/en';
const CONTEXT_FILE = './locales/context.json';
(async () => {
const context = require(CONTEXT_FILE);
const newContext = {};
const files = await fs.readdir(BASE_PATH);
for (const file of files) {
const filePath = path.join(process.cwd(), BASE_PATH, file);
const data = require(filePath);
for (const key of Object.keys(data)) {
newContext[key] = context[key] || '';
}
}
const orderedContext = Object.keys(newContext).sort().reduce((obj, key) => {
obj[key] = newContext[key];
return obj;
}, {});
await fs.writeFile(CONTEXT_FILE, JSON.stringify(orderedContext, null, 4));
})();