Files
j_kedzierski/scripts/translate_remaining.ts
T

98 lines
3.7 KiB
TypeScript

import { getPayload } from 'payload'
import configPromise from '../src/payload.config'
async function run() {
const payload = await getPayload({ config: configPromise })
// Translation mapping for FinalCTA to EN
const enCta = {
title: "Have questions about your tax return?",
subtitle: "Contact us directly via WhatsApp. We will analyze your situation and help you get the refund you deserve.",
buttonText: "Message on WhatsApp",
}
// Translation mapping for FinalCTA to DE
const deCta = {
title: "Haben Sie Fragen zu Ihrer Steuererklärung?",
subtitle: "Kontaktieren Sie uns direkt über WhatsApp. Wir analysieren Ihre Situation und helfen Ihnen, die Ihnen zustehende Rückerstattung zu erhalten.",
buttonText: "Auf WhatsApp schreiben",
}
const pages = await payload.find({ collection: 'pages', limit: 100, locale: 'pl' })
for (const page of pages.docs) {
if (page.slug === 'home') continue; // already mostly translated
// EN Update
const enPage = await payload.findByID({ collection: 'pages', id: page.id, locale: 'en' })
if (enPage && enPage.layout) {
let modified = false
const layout = enPage.layout.map((block: any) => {
// Strip populated ids
for (const key of Object.keys(block)) {
if (block[key] && typeof block[key] === 'object' && block[key].id !== undefined) {
block[key] = block[key].id
}
}
if (block.blockType === 'finalCta') {
block.title = enCta.title
block.subtitle = enCta.subtitle
block.buttonText = enCta.buttonText
modified = true
}
if (block.blockType === 'pageHeader') {
if (page.slug === 'uslugi') {
block.title = "Our Services"
block.subtitle = "Professional tax and accounting support in Germany."
} else if (page.slug === 'kontakt') {
block.title = "Contact"
block.subtitle = "Do you have questions about tax settlement in Germany? Contact us — we will be happy to help."
}
modified = true
}
return block
})
if (modified) {
await payload.update({ collection: 'pages', id: page.id, locale: 'en', data: { layout } })
console.log(`Updated EN translations for ${page.slug}`)
}
}
// DE Update
const dePage = await payload.findByID({ collection: 'pages', id: page.id, locale: 'de' })
if (dePage && dePage.layout) {
let modified = false
const layout = dePage.layout.map((block: any) => {
for (const key of Object.keys(block)) {
if (block[key] && typeof block[key] === 'object' && block[key].id !== undefined) {
block[key] = block[key].id
}
}
if (block.blockType === 'finalCta') {
block.title = deCta.title
block.subtitle = deCta.subtitle
block.buttonText = deCta.buttonText
modified = true
}
if (block.blockType === 'pageHeader') {
if (page.slug === 'uslugi') {
block.title = "Unsere Dienstleistungen"
block.subtitle = "Professionelle steuerliche und buchhalterische Betreuung in Deutschland."
} else if (page.slug === 'kontakt') {
block.title = "Kontakt"
block.subtitle = "Haben Sie Fragen zur Steuererklärung in Deutschland? Kontaktieren Sie uns — wir helfen Ihnen gerne weiter."
}
modified = true
}
return block
})
if (modified) {
await payload.update({ collection: 'pages', id: page.id, locale: 'de', data: { layout } })
console.log(`Updated DE translations for ${page.slug}`)
}
}
}
process.exit(0)
}
run().catch(console.error)