Files
j_kedzierski/scripts/fix_translations_properly.ts

93 lines
2.6 KiB
TypeScript

import { getPayload } from 'payload'
import configPromise from '../src/payload.config'
function deepStripIds(obj: any): any {
if (Array.isArray(obj)) return obj.map(deepStripIds);
if (obj !== null && typeof obj === 'object') {
const newObj = { ...obj };
delete newObj.id;
for (const key of Object.keys(newObj)) {
newObj[key] = deepStripIds(newObj[key]);
}
return newObj;
}
return obj;
}
async function run() {
const payload = await getPayload({ config: configPromise })
const addressDE = "Vom Kunden zu bestätigen";
const hoursDE = "Mo-Fr: 9:00 - 17:00\nNach vorheriger Terminvereinbarung";
// Kontakt
const kontaktPL = await payload.find({ collection: 'pages', locale: 'pl', where: { slug: { equals: 'kontakt' } } });
if (kontaktPL.docs.length > 0) {
let changed = false;
const layoutDE = deepStripIds(kontaktPL.docs[0].layout).map((b: any) => {
const newB = { ...b };
if (newB.blockType === 'pageHeader') {
newB.subtitle = 'Haben Sie Fragen zu Ihrer Steuererklärung in Deutschland? Kontaktieren Sie uns — wir helfen Ihnen gerne.';
changed = true;
}
if (newB.blockType === 'contactSection') {
newB.address = addressDE;
newB.hours = hoursDE;
changed = true;
}
return newB;
});
if (changed) {
await payload.update({
collection: 'pages',
id: kontaktPL.docs[0].id,
locale: 'de',
data: { layout: layoutDE }
});
console.log('Updated Kontakt DE');
}
}
// Jak sie umowic
const jsuPL = await payload.find({ collection: 'pages', locale: 'pl', where: { slug: { equals: 'jak-sie-umowic' } } });
if (jsuPL.docs.length > 0) {
let changed = false;
const layoutDE = deepStripIds(jsuPL.docs[0].layout).map((b: any) => {
const newB = { ...b };
if (newB.blockType === 'contactSection') {
newB.address = addressDE;
newB.hours = hoursDE;
changed = true;
}
return newB;
});
if (changed) {
await payload.update({
collection: 'pages',
id: jsuPL.docs[0].id,
locale: 'de',
data: { layout: layoutDE }
});
console.log('Updated Jak Sie Umowic DE');
}
}
// Company Global
const companyDE = await payload.findGlobal({ slug: 'company', locale: 'de' });
if (companyDE) {
await payload.updateGlobal({
slug: 'company',
locale: 'de',
data: {
address: addressDE,
hours: hoursDE
}
});
console.log('Updated Company DE');
}
process.exit(0);
}
run()