Files
j_kedzierski/scripts/translate_en.ts
T

76 lines
2.2 KiB
TypeScript

import { getPayload } from 'payload'
import configPromise from '../src/payload.config'
async function run() {
const payload = await getPayload({ config: configPromise })
// 1. UPDATE GLOBALS
await payload.updateGlobal({
slug: 'footer',
locale: 'en',
data: {
copyright: '© 2024 Accounting Kędzierski. All rights reserved.',
association: {
title: 'Member of b.b.h. Lohnsteuerhilfeverein e.V.'
},
creator: {
label: 'Created by'
}
}
})
console.log("Footer updated")
// 2. UPDATE PAGES (Titles and basic fields)
const translations: Record<string, any> = {
'home': { title: 'Home' },
'uslugi': { title: 'Services' },
'jak-sie-umowic': { title: 'How to make an appointment' },
'o-nas': { title: 'About Us' },
'faq': { title: 'FAQ' },
'kontakt': { title: 'Contact' },
'stowarzyszenie': { title: 'Association' },
'polityka-prywatnosci': { title: 'Privacy Policy' },
'polityka-cookies': { title: 'Cookie Policy' },
'impressum': { title: 'Imprint' }
}
const pages = await payload.find({ collection: 'pages', limit: 100, locale: 'pl' })
for (const page of pages.docs) {
const slug = page.slug || ''
const enData = translations[slug] || { title: page.title }
// For Home, let's keep the hero translations if it's there
if (slug === 'home') {
enData.layout = page.layout?.map(block => {
if (block.blockType === 'hero') {
return {
...block,
title: 'Your Trusted Accounting Office in Germany',
titleAccent: 'We speak English and Polish',
subtitle: 'Professional bookkeeping, tax settlements, and business consulting for companies in Germany.',
primaryCta: 'Contact Us',
secondaryCta: { text: 'Our Services', url: '/uslugi' }
}
}
return block
})
}
try {
await payload.update({
collection: 'pages',
id: page.id,
locale: 'en',
data: enData
})
console.log(`Page updated: ${slug}`)
} catch (e) {
console.error(`Error updating page ${slug}`, e)
}
}
console.log("Done")
process.exit(0)
}
run().catch(console.error)