@copy-cms/cli
v1.0.19
Published
CLI tool for syncing copy keys to Copy
Readme
@copy/sync
Scan copy keys in je codebase en sync ze naar Copy. Haal copy automatisch op tijdens je build via de Next.js plugin.
Setup
Stap 1: Installeren
pnpm add @copy/cli
pnpm add i18next react-i18next i18next-resources-to-backendStap 2: .env.local
CMS_SYNC_API_KEY=eyJ...
NEXT_PUBLIC_CMS_URL=https://copy.example.nl
CMS_OUTPUT_DIR=src/lib/i18n/dictionariesZoek je API key? In Copy: Project Settings → Environments → jouw environment → API Key
projectId wordt automatisch uit de API key gehaald — je hoeft hem niet apart
op te geven.
CMS_OUTPUT_DIR is optioneel en staat standaard op src/lib/i18n/dictionaries.
Stap 3: Plugin in next.config.ts
import withCopy from '@copy/cli/next';
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {};
// Option A: Expliciet instellen (negeert ENVIRONMENT var)
export default withCopy(nextConfig, {
syncOnDev: true, // scan & upload keys
pullOnDev: true, // download copy
});
// Option B: CI/CD-based (via ENVIRONMENT var)
// export default withCopy(nextConfig);
// → ENVIRONMENT=staging pnpm build → sync + pull
// → ENVIRONMENT=production pnpm build → pull onlyStap 4: i18n provider
import { TranslationProvider } from '@/lib/i18n/provider';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html>
<body>
<TranslationProvider>{children}</TranslationProvider>
</body>
</html>
);
}Run copy init om alles in één keer te genereren.
Vertalingen gebruiken
Server component
import { getTranslation } from '@/lib/i18n/server';
export default async function Page() {
const { t } = await getTranslation('common');
return <h1>{t('common:app.title')}</h1>;
}Client component
'use client';
import { useTranslation } from '@/lib/i18n/client';
export function MyButton() {
const { t } = useTranslation('common');
return <button>{t('common:button.click')}</button>;
}CLI
copy sync # scan keys en upload naar Copy
copy sync --dry-run # toon wat zou veranderen zonder te uploaden
copy pull # download gepubliceerde copy
copy pull --env staging
copy pull --output ./translations
copy status # diff vs laatste sync (geen netwerk)
copy init # eenmalige setup wizardProgrammatic API
import { syncTranslations, pullTranslations } from '@copy/cli/api';
await syncTranslations({ projectRoot: '.', verbose: true });
await pullTranslations({ outputDir: 'src/lib/i18n/dictionaries' });Logs
Sync:
[CMS] ✓ Synced: 3 key(s) added, 12 translation(s) added, 2 pruned, 8 skippedPull:
[CMS] ✓ Pulled translations: 4 file(s)
en/common.json — 42 key(s)
en/auth.json — 8 key(s)
nl/common.json — 42 key(s), 3 new
nl/auth.json — 8 key(s)Workflow
Developers (lokaal):
- Voeg
t('namespace:key')toe in code - Run
copy pullom de laatste copy op te halen - Push naar develop
CI/CD Staging:
ENVIRONMENT=staging pnpm build- Plugin: sync keys → pull copy van staging
CI/CD Production:
ENVIRONMENT=production pnpm build- Plugin: pull copy van gepubliceerde release
Troubleshooting
| Probleem | Oplossing |
| -------------------- | -------------------------------------------------------------------------------- |
| Geen keys gevonden | Gebruik t('namespace:key') — namespace is verplicht |
| Plugin doet niks | Controleer dat CMS_SYNC_API_KEY en NEXT_PUBLIC_CMS_URL in .env.local staan |
| API key niet herkend | Herstart dev server na wijzigen van .env.local |
| Pull mislukt | Controleer API key in Copy Project Settings |
| Oude copy | copy pull --force om cache te omzeilen |
