Skip to content

Commit

Permalink
feat: adds ability to copy data from across locales (#8203)
Browse files Browse the repository at this point in the history
### What?

Adds ability to copy data from one locale to another at a document
level.

### How?

For any localized collection, you will find a new option in the document
controls called `Copy to Locale`.

This option will open a drawer, from here you can select your origin and
destination locales.

If data already exists in the destination locale, you can choose to: 
1. Overwrite this data (this will copy any empty fields in your origin
locale)
2. Not overwrite existing data (this will only copy data into empty
fields in the destination locale)

---------

Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
  • Loading branch information
JessChowdhury and JarrodMFlesch authored Nov 26, 2024
1 parent 61d6614 commit 601759d
Show file tree
Hide file tree
Showing 50 changed files with 1,401 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/next/src/utilities/handleServerFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ServerFunction, ServerFunctionHandler } from 'payload'

import { copyDataFromLocaleHandler } from '@payloadcms/ui/rsc'
import { buildFormStateHandler } from '@payloadcms/ui/utilities/buildFormState'
import { buildTableStateHandler } from '@payloadcms/ui/utilities/buildTableState'

Expand All @@ -20,6 +21,7 @@ export const handleServerFunctions: ServerFunctionHandler = async (args) => {
}

const serverFunctions = {
'copy-data-from-locale': copyDataFromLocaleHandler as any as ServerFunction,
'form-state': buildFormStateHandler as any as ServerFunction,
'render-document': renderDocumentHandler as any as ServerFunction,
'render-document-slots': renderDocumentSlotsHandler as any as ServerFunction,
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/src/clientKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ export const clientTranslationKeys = createClientTranslationKeys([
'general:columns',
'general:columnToSort',
'general:confirm',
'general:confirmCopy',
'general:confirmDeletion',
'general:confirmDuplication',
'general:copied',
'general:clearAll',
'general:copy',
'general:copyWarning',
'general:copying',
'general:create',
'general:created',
'general:createdAt',
Expand Down Expand Up @@ -212,6 +215,7 @@ export const clientTranslationKeys = createClientTranslationKeys([
'general:only',
'general:or',
'general:order',
'general:overwriteExistingData',
'general:pageNotFound',
'general:password',
'general:payloadSettings',
Expand Down Expand Up @@ -247,6 +251,7 @@ export const clientTranslationKeys = createClientTranslationKeys([
'general:user',
'general:username',
'general:unauthorized',
'general:unsavedChanges',
'general:unsavedChangesDuplicate',
'general:untitled',
'general:updatedAt',
Expand All @@ -258,6 +263,13 @@ export const clientTranslationKeys = createClientTranslationKeys([
'general:uploadingBulk',
'general:welcome',

'localization:copyToLocale',
'localization:copyFromTo',
'localization:selectLocaleToCopy',
'localization:cannotCopySameLocale',
'localization:copyFrom',
'localization:copyTo',

'operators:equals',
'operators:exists',
'operators:isNotIn',
Expand Down
13 changes: 13 additions & 0 deletions packages/translations/src/languages/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ export const arTranslations: DefaultTranslationsObject = {
columns: 'الأعمدة',
columnToSort: 'التّرتيب حسب العامود',
confirm: 'تأكيد',
confirmCopy: 'تأكيد النسخ',
confirmDeletion: 'تأكيد الحذف',
confirmDuplication: 'تأكيد التّكرار',
copied: 'تمّ النّسخ',
copy: 'نسخ',
copying: 'نسخ',
copyWarning: 'أنت على وشك الكتابة فوق {{to}} بـ {{from}} لـ {{label}} {{title}}. هل أنت متأكد؟',
create: 'إنشاء',
created: 'تمّ الإنشاء',
createdAt: 'تمّ الإنشاء في',
Expand Down Expand Up @@ -269,6 +272,7 @@ export const arTranslations: DefaultTranslationsObject = {
open: 'فتح',
or: 'أو',
order: 'التّرتيب',
overwriteExistingData: 'استبدل بيانات الحقل الموجودة',
pageNotFound: 'الصّفحة غير موجودة',
password: 'كلمة المرور',
payloadSettings: 'الإعدادات',
Expand Down Expand Up @@ -301,6 +305,7 @@ export const arTranslations: DefaultTranslationsObject = {
titleDeleted: 'تم حذف {{label}} "{{title}}" بنجاح.',
true: 'صحيح',
unauthorized: 'غير مصرح به',
unsavedChanges: 'لديك تغييرات غير محفوظة. قم بالحفظ أو التجاهل قبل المتابعة.',
unsavedChangesDuplicate: 'لديك تغييرات لم يتم حفظها. هل تريد الاستمرار في الاستنساخ؟',
untitled: 'بدون عنوان',
updatedAt: 'تم التحديث في',
Expand All @@ -316,6 +321,14 @@ export const arTranslations: DefaultTranslationsObject = {
viewReadOnly: 'عرض للقراءة فقط',
welcome: 'مرحبًا',
},
localization: {
cannotCopySameLocale: 'لا يمكن النسخ إلى نفس الموقع',
copyFrom: 'نسخ من',
copyFromTo: 'النسخ من {{from}} إلى {{to}}',
copyTo: 'انسخ إلى',
copyToLocale: 'نسخ إلى الموقع المحلي',
selectLocaleToCopy: 'حدد الموقع المحلي للنسخ',
},
operators: {
contains: 'يحتوي',
equals: 'يساوي',
Expand Down
15 changes: 15 additions & 0 deletions packages/translations/src/languages/az.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ export const azTranslations: DefaultTranslationsObject = {
columns: 'Sütunlar',
columnToSort: 'Sıralamağa sütun',
confirm: 'Təsdiqlə',
confirmCopy: 'Kopyanı təsdiqləyin',
confirmDeletion: 'Silməni təsdiqlə',
confirmDuplication: 'Dublikasiyanı təsdiqlə',
copied: 'Kopyalandı',
copy: 'Kopyala',
copying: 'Kopyalama',
copyWarning:
'Siz {{label}} {{title}} üçün {{from}} ilə {{to}} -nu üzərindən yazmaq ətrafındasınız. Eminsiniz?',
create: 'Yarat',
created: 'Yaradıldı',
createdAt: 'Yaradıldığı tarix',
Expand Down Expand Up @@ -271,6 +275,7 @@ export const azTranslations: DefaultTranslationsObject = {
open: 'Aç',
or: 'Və ya',
order: 'Sıra',
overwriteExistingData: 'Mövcud sahə məlumatlarını yenidən yazın',
pageNotFound: 'Səhifə tapılmadı',
password: 'Şifrə',
payloadSettings: 'Payload Parametrləri',
Expand Down Expand Up @@ -303,6 +308,8 @@ export const azTranslations: DefaultTranslationsObject = {
titleDeleted: '{{label}} "{{title}}" uğurla silindi.',
true: 'Doğru',
unauthorized: 'İcazəsiz',
unsavedChanges:
'Sizin saxlanılmamış dəyişiklikləriniz var. Davam etmədən əvvəl saxlayın və ya atın.',
unsavedChangesDuplicate:
'Saxlanılmamış dəyişiklikləriniz var. Dublikatla davam etmək istəyirsiniz?',
untitled: 'Başlıqsız',
Expand All @@ -319,6 +326,14 @@ export const azTranslations: DefaultTranslationsObject = {
viewReadOnly: 'Yalnız oxu rejimində bax',
welcome: 'Xoş gəldiniz',
},
localization: {
cannotCopySameLocale: 'Eyni dildə köçürmək mümkün deyil',
copyFrom: 'Kopyalayın',
copyFromTo: '{{from}}-dan {{to}}-ya kopyalama',
copyTo: 'Köçür',
copyToLocale: 'Yerliyə köçürün',
selectLocaleToCopy: 'Köçürmək üçün yerli seçin',
},
operators: {
contains: 'daxilində',
equals: 'bərabərdir',
Expand Down
14 changes: 14 additions & 0 deletions packages/translations/src/languages/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ export const bgTranslations: DefaultTranslationsObject = {
columns: 'Колони',
columnToSort: 'Колона за сортиране',
confirm: 'Потвърди',
confirmCopy: 'Потвърди копирането',
confirmDeletion: 'Потвърди изтриване',
confirmDuplication: 'Потвърди дупликация',
copied: 'Копирано',
copy: 'Копирай',
copying: 'Копиране',
copyWarning:
'Предстои да презапишете {{to}} с {{from}} за {{label}} {{title}}. Сигурни ли сте?',
create: 'Създай',
created: 'Създаден',
createdAt: 'Създаден на',
Expand Down Expand Up @@ -270,6 +274,7 @@ export const bgTranslations: DefaultTranslationsObject = {
open: 'Отвори',
or: 'Или',
order: 'Ред',
overwriteExistingData: 'Презапишете съществуващите данни в полето',
pageNotFound: 'Страницата не беше открита',
password: 'Парола',
payloadSettings: 'Настройки на Payload',
Expand Down Expand Up @@ -302,6 +307,7 @@ export const bgTranslations: DefaultTranslationsObject = {
titleDeleted: '{{label}} "{{title}}" успешно изтрит.',
true: 'Вярно',
unauthorized: 'Неоторизиран',
unsavedChanges: 'Имате незапазени промени. Запазете или отхвърлете преди да продължите.',
unsavedChangesDuplicate: 'Имаш незапазени промени. Искаш ли да продължиш да дупликираш?',
untitled: 'Неозаглавен',
updatedAt: 'Обновен на',
Expand All @@ -317,6 +323,14 @@ export const bgTranslations: DefaultTranslationsObject = {
viewReadOnly: 'Преглед само за четене',
welcome: 'Добре дошъл',
},
localization: {
cannotCopySameLocale: 'Не може да се копира в същата локация',
copyFrom: 'Копирай от',
copyFromTo: 'Копиране от {{from}} към {{to}}',
copyTo: 'Копирай в',
copyToLocale: 'Копирайте в местното',
selectLocaleToCopy: 'Изберете място за копиране',
},
operators: {
contains: 'съдържа',
equals: 'е равно на',
Expand Down
13 changes: 13 additions & 0 deletions packages/translations/src/languages/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,13 @@ export const csTranslations: DefaultTranslationsObject = {
columns: 'Sloupce',
columnToSort: 'Sloupec k seřazení',
confirm: 'Potvrdit',
confirmCopy: 'Potvrzení kopie',
confirmDeletion: 'Potvrdit odstranění',
confirmDuplication: 'Potvrdit duplikaci',
copied: 'Zkopírováno',
copy: 'Kopírovat',
copying: 'Kopírování',
copyWarning: 'Chystáte se přepsat {{to}} s {{from}} pro {{label}} {{title}}. Jste si jistý?',
create: 'Vytvořit',
created: 'Vytvořeno',
createdAt: 'Vytvořeno v',
Expand Down Expand Up @@ -270,6 +273,7 @@ export const csTranslations: DefaultTranslationsObject = {
open: 'Otevřít',
or: 'Nebo',
order: 'Pořadí',
overwriteExistingData: 'Přepsat existující data pole',
pageNotFound: 'Stránka nenalezena',
password: 'Heslo',
payloadSettings: 'Payload nastavení',
Expand Down Expand Up @@ -302,6 +306,7 @@ export const csTranslations: DefaultTranslationsObject = {
titleDeleted: '{{label}} "{{title}}" úspěšně smazáno.',
true: 'Pravda',
unauthorized: 'Neoprávněný',
unsavedChanges: 'Máte neuložené změny. Uložte nebo zahoďte před pokračováním.',
unsavedChangesDuplicate: 'Máte neuložené změny. Chtěli byste pokračovat v duplikování?',
untitled: 'Bez názvu',
updatedAt: 'Aktualizováno v',
Expand All @@ -317,6 +322,14 @@ export const csTranslations: DefaultTranslationsObject = {
viewReadOnly: 'Zobrazit pouze pro čtení',
welcome: 'Vítejte',
},
localization: {
cannotCopySameLocale: 'Nelze kopírovat do stejného umístění',
copyFrom: 'Kopírovat z',
copyFromTo: 'Kopírování z {{from}} do {{to}}',
copyTo: 'Kopírovat do',
copyToLocale: 'Kopírovat do lokalizace',
selectLocaleToCopy: 'Vyberte lokalitu ke kopírování',
},
operators: {
contains: 'obsahuje',
equals: 'rovná se',
Expand Down
14 changes: 14 additions & 0 deletions packages/translations/src/languages/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ export const daTranslations: DefaultTranslationsObject = {
columns: 'Kolonner',
columnToSort: 'Kolonne at sortere',
confirm: 'Bekræft',
confirmCopy: 'Bekræft kopi',
confirmDeletion: 'Bekræft sletning',
confirmDuplication: 'Bekræft duplikering',
copied: 'Kopieret',
copy: 'Kopier',
copying: 'Kopiering',
copyWarning:
'Du er lige ved at overskrive {{to}} med {{from}} for {{label}} {{title}}. Er du sikker?',
create: 'Opret',
created: 'Oprettet',
createdAt: 'Oprettet til',
Expand Down Expand Up @@ -269,6 +273,7 @@ export const daTranslations: DefaultTranslationsObject = {
open: 'Åben',
or: 'Eller',
order: 'Rækkefølge',
overwriteExistingData: 'Overskriv eksisterende feltdata',
pageNotFound: 'Siden blev ikke fundet',
password: 'Adgangskode',
payloadSettings: 'Payload-indstillinger',
Expand Down Expand Up @@ -301,6 +306,7 @@ export const daTranslations: DefaultTranslationsObject = {
titleDeleted: '{{label}} "{{title}}" slettet.',
true: 'Sandt',
unauthorized: 'Uautoriseret',
unsavedChanges: 'Du har ikke gemte ændringer. Gem eller kassér før fortsættelse.',
unsavedChangesDuplicate: 'Du har ikke-gemte ændringer. Vil du fortsætte med at duplikere?',
untitled: 'Uden titel',
updatedAt: 'Opdateret ved',
Expand All @@ -316,6 +322,14 @@ export const daTranslations: DefaultTranslationsObject = {
viewReadOnly: 'Vis kun-læsning',
welcome: 'Velkommen',
},
localization: {
cannotCopySameLocale: 'Kan ikke kopiere til den samme lokalitet',
copyFrom: 'Kopier fra',
copyFromTo: 'Kopierer fra {{from}} til {{to}}',
copyTo: 'Kopier til',
copyToLocale: 'Kopier til lokal',
selectLocaleToCopy: 'Vælg lokalitet til kopiering',
},
operators: {
contains: 'Indeholder',
equals: 'Lig med',
Expand Down
15 changes: 15 additions & 0 deletions packages/translations/src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ export const deTranslations: DefaultTranslationsObject = {
columns: 'Spalten',
columnToSort: 'Spalten zum Sortieren',
confirm: 'Bestätigen',
confirmCopy: 'Kopie bestätigen',
confirmDeletion: 'Löschen bestätigen',
confirmDuplication: 'Duplizieren bestätigen',
copied: 'Kopiert',
copy: 'Kopieren',
copying: 'Kopieren',
copyWarning:
'Sie sind dabei, {{to}} mit {{from}} für {{label}} {{title}} zu überschreiben. Sind Sie sicher?',
create: 'Erstellen',
created: 'Erstellt',
createdAt: 'Erstellt am',
Expand Down Expand Up @@ -275,6 +279,7 @@ export const deTranslations: DefaultTranslationsObject = {
open: 'Öffnen',
or: 'oder',
order: 'Reihenfolge',
overwriteExistingData: 'Überschreiben Sie vorhandene Felddaten',
pageNotFound: 'Seite nicht gefunden',
password: 'Passwort',
payloadSettings: 'Payload Einstellungen',
Expand Down Expand Up @@ -307,6 +312,8 @@ export const deTranslations: DefaultTranslationsObject = {
titleDeleted: '{{label}} {{title}} wurde erfolgreich gelöscht.',
true: 'Wahr',
unauthorized: 'Nicht autorisiert',
unsavedChanges:
'Sie haben ungespeicherte Änderungen. Speichern oder verwerfen Sie diese, bevor Sie fortfahren.',
unsavedChangesDuplicate:
'Du hast ungespeicherte Änderungen, möchtest du mit dem Duplizieren fortfahren?',
untitled: 'ohne Titel',
Expand All @@ -323,6 +330,14 @@ export const deTranslations: DefaultTranslationsObject = {
viewReadOnly: 'Nur-Lese-Ansicht',
welcome: 'Willkommen',
},
localization: {
cannotCopySameLocale: 'Kann nicht in dieselbe Gebietsschema kopieren',
copyFrom: 'Kopieren von',
copyFromTo: 'Kopieren von {{from}} zu {{to}}',
copyTo: 'Kopieren nach',
copyToLocale: 'Kopieren in das Gebietsschema',
selectLocaleToCopy: 'Wählen Sie den Ort zum Kopieren aus',
},
operators: {
contains: 'enthält',
equals: 'gleich',
Expand Down
14 changes: 14 additions & 0 deletions packages/translations/src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ export const enTranslations = {
columns: 'Columns',
columnToSort: 'Column to Sort',
confirm: 'Confirm',
confirmCopy: 'Confirm copy',
confirmDeletion: 'Confirm deletion',
confirmDuplication: 'Confirm duplication',
copied: 'Copied',
copy: 'Copy',
copying: 'Copying',
copyWarning:
'You are about to overwrite {{to}} with {{from}} for {{label}} {{title}}. Are you sure?',
create: 'Create',
created: 'Created',
createdAt: 'Created At',
Expand Down Expand Up @@ -272,6 +276,7 @@ export const enTranslations = {
open: 'Open',
or: 'Or',
order: 'Order',
overwriteExistingData: 'Overwrite existing field data',
pageNotFound: 'Page not found',
password: 'Password',
payloadSettings: 'Payload Settings',
Expand Down Expand Up @@ -304,6 +309,7 @@ export const enTranslations = {
titleDeleted: '{{label}} "{{title}}" successfully deleted.',
true: 'True',
unauthorized: 'Unauthorized',
unsavedChanges: 'You have unsaved changes. Save or discard before continuing.',
unsavedChangesDuplicate: 'You have unsaved changes. Would you like to continue to duplicate?',
untitled: 'Untitled',
updatedAt: 'Updated At',
Expand All @@ -319,6 +325,14 @@ export const enTranslations = {
viewReadOnly: 'View read-only',
welcome: 'Welcome',
},
localization: {
cannotCopySameLocale: 'Cannot copy to the same locale',
copyFrom: 'Copy from',
copyFromTo: 'Copying from {{from}} to {{to}}',
copyTo: 'Copy to',
copyToLocale: 'Copy to locale',
selectLocaleToCopy: 'Select locale to copy',
},
operators: {
contains: 'contains',
equals: 'equals',
Expand Down
Loading

0 comments on commit 601759d

Please sign in to comment.