Skip to content

Commit e5cb6e6

Browse files
committed
Merge branch 'main' into pro-8358-add-missing-schema-fields-skip-migration
* main: Pro 8541 switch locale empty doc (#5135)
2 parents ab672ee + 55d4435 commit e5cb6e6

15 files changed

Lines changed: 166 additions & 55 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Add `@apostrophecms/migration:add-missing-schema-fields` task. This task does not run database migrations.
88
* Translation strings added for the layout- and layout-column-widgets.
9+
* When switching locale from the doc editor, ask if the user wants to localize the current document in the target locale or want to start a blank document.
910

1011
### Changes
1112

‎modules/@apostrophecms/doc-type/ui/apos/components/AposDocEditor.vue‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,15 @@ export default {
526526
draft: true
527527
});
528528
529+
this.currentId = docData._id;
529530
if (docData.archived) {
530531
this.restoreOnly = true;
531532
} else {
532533
this.restoreOnly = false;
533534
}
534535
const canEdit = docData._edit || this.moduleOptions.canEdit;
535536
this.readOnly = canEdit === false;
536-
if (canEdit && !await this.lock(this.getOnePath, this.currentId)) {
537+
if (canEdit && !await this.lock(this.getOnePath)) {
537538
this.lockNotAvailable();
538539
}
539540
} catch {
@@ -860,10 +861,11 @@ export default {
860861
this.modal.showModal = false;
861862
},
862863
async switchLocale({
863-
locale, localized, save
864+
locale, save, localized, toLocalize
864865
}) {
866+
let saved;
865867
if (save) {
866-
const saved = await this.saveHandler('onSave', {
868+
saved = await this.saveHandler('onSave', {
867869
keepOpen: true,
868870
andPublish: false
869871
});
@@ -874,18 +876,37 @@ export default {
874876
this.referenceDocId = saved._id;
875877
}
876878
}
877-
this.updateModalData(this.modalData.id, { locale });
878-
this.localeSwitched = locale !== apos.i18n.locale;
879-
this.published = null;
880879
if (localized) {
881880
this.currentId = localized._id;
881+
this.switchModalLocale(locale.name);
882882
await this.instantiateExistingDoc();
883-
} else {
883+
return;
884+
}
885+
if (!toLocalize) {
886+
this.switchModalLocale(locale.name);
884887
this.currentId = '';
885888
this.docType = this.moduleName;
886889
await this.instantiateNewDoc();
890+
return;
891+
}
892+
893+
const isLocalized = await apos.modal.execute('AposI18nLocalize', {
894+
doc: saved || this.original,
895+
locale,
896+
moduleName: this.moduleName,
897+
shouldRedirect: false
898+
});
899+
900+
if (isLocalized) {
901+
this.switchModalLocale(locale.name);
902+
await this.instantiateExistingDoc();
887903
}
888904
},
905+
switchModalLocale(locale) {
906+
this.updateModalData(this.modalData.id, { locale });
907+
this.localeSwitched = locale !== apos.i18n.locale;
908+
this.published = null;
909+
},
889910
getRequestBody({ newInstance = false, update = false }) {
890911
const body = newInstance
891912
? { _newInstance: true }

‎modules/@apostrophecms/doc-type/ui/apos/components/AposDocLocalePicker.vue‎

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
>
1717
<AposLocalePicker
1818
:current-locale="locale"
19-
:localized="localized"
19+
:localized="docLocalized"
2020
:forbidden="forbidden"
2121
:forbidden-tooltip="forbiddenTooltip"
2222
:is-open="isOpen"
23-
:show-localized="showLocalized"
23+
:show-localized="!isManager"
2424
@switch-locale="switchLocale"
2525
/>
2626
</AposContextMenu>
@@ -53,19 +53,18 @@ const props = defineProps({
5353
type: Boolean,
5454
required: true
5555
},
56-
showLocalized: {
56+
isManager: {
5757
type: Boolean,
58-
default: true
58+
default: false
5959
}
6060
});
6161
6262
const $t = inject('i18n');
6363
const i18nAction = apos.modules['@apostrophecms/i18n'].action;
64-
const forbiddenTooltip = $t('apostrophe:localeSwitcherPermissionToCreate', {
65-
docType: props.moduleOptions.label.toLowerCase()
66-
});
64+
const docType = $t(props.moduleOptions.label)?.toLowerCase();
65+
const forbiddenTooltip = $t('apostrophe:localeSwitcherPermissionToCreate', { docType });
6766
const menu = ref(null);
68-
const localized = ref({});
67+
const docLocalized = ref({});
6968
const forbidden = ref([]);
7069
const isOpen = ref(false);
7170
const button = computed(() => {
@@ -91,7 +90,7 @@ async function open() {
9190
const docs = await apos.http.get(
9291
`${props.moduleOptions.action}/${props.docId}/locales`, { busy: true }
9392
);
94-
localized.value = Object.fromEntries(
93+
docLocalized.value = Object.fromEntries(
9594
docs.results
9695
.filter(doc => doc.aposLocale.endsWith(':draft'))
9796
.map(doc => [ doc.aposLocale.split(':')[0], doc ])
@@ -106,7 +105,7 @@ async function open() {
106105
107106
async function checkCreatePermission() {
108107
const localesWithNoDocs = Object.keys(apos.i18n.locales)
109-
.filter((locale) => !localized.value[locale]);
108+
.filter((locale) => !docLocalized.value[locale]);
110109
111110
const allowed = await apos.http.get(`${i18nAction}/locales-permissions`, {
112111
qs: {
@@ -131,29 +130,58 @@ async function switchLocale(locale) {
131130
return;
132131
}
133132
133+
if (props.isManager) {
134+
emit('switch-locale', { locale });
135+
return;
136+
}
137+
134138
const save = props.isModified
135139
? await apos.confirm({
136140
heading: 'apostrophe:unsavedChanges',
137-
description: $t(
138-
'apostrophe:localeSwitcherDiscardChangesPrompt',
139-
{ docType: props.moduleOptions.label.toLowerCase() }
140-
),
141+
description: 'apostrophe:localeSwitcherDiscardChangesPrompt',
141142
negativeLabel: 'apostrophe:localeSwitcherDiscardChangesNegative',
142143
affirmativeLabel: 'apostrophe:localeSwitcherDiscardChangesAffirmative',
143144
icon: false
144145
}, {
145146
hasCloseButton: true,
146-
tiny: true
147+
tiny: true,
148+
interpolate: {
149+
docType
150+
}
147151
})
148152
: false;
149153
150154
if (save === null) {
151155
return;
152156
}
153157
158+
const docExist = docLocalized.value[props.locale];
159+
const isDocLocalized = docLocalized.value[locale.name];
160+
const toLocalize = (docExist && !isDocLocalized)
161+
? await apos.confirm({
162+
heading: 'apostrophe:switchLocalesAndLocalizeDoc',
163+
description: 'apostrophe:notInLocaleDoc',
164+
negativeLabel: 'apostrophe:noCreateBlankDoc',
165+
affirmativeLabel: 'apostrophe:yesLocalizeAndSwitchLocalesDoc'
166+
}, {
167+
hasCloseButton: true,
168+
tiny: true,
169+
interpolate: {
170+
docType,
171+
label: locale.label,
172+
currentLocale: props.locale
173+
}
174+
})
175+
: false;
176+
177+
if (toLocalize === null) {
178+
return;
179+
}
180+
154181
emit('switch-locale', {
155-
locale: locale.name,
156-
localized: localized.value[locale.name],
182+
locale,
183+
localized: docLocalized.value[locale.name],
184+
toLocalize,
157185
save
158186
});
159187
}

‎modules/@apostrophecms/i18n/i18n/de.json‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
"batchPublishCompleted": "{{ count }} {{ type }} veröffentlicht.",
6363
"batchPublishProgress": "Veröffentlichung {{ type }}...",
6464
"batchRestoreCompleted": "{{ count }} {{ type }} wiederhergestellt.",
65+
"batchRestoreProgress": "Wiederherstellung {{ type }}...",
6566
"batchTagProgress": "Taggen von {{ count }} {{ type }}...",
6667
"batchUntagProgress": "Entfernen der Markierung von {{ count }} {{ type }}...",
67-
"batchRestoreProgress": "Wiederherstellung {{ type }}...",
6868
"breakpointPreviewClear": "Klarer Haltepunkt",
6969
"breakpointPreviewDesktop": "Desktop",
7070
"breakpointPreviewExit": "Beenden",
@@ -85,9 +85,9 @@
8585
"clearSelection": "Auswahl löschen",
8686
"close": "Schliessen",
8787
"closeGlobal": "Globale Einstellungen schliessen",
88+
"collapseAll": "Alles einklappen",
8889
"colorFieldClickToSelect": "Klicken, um eine Farbe auszuwählen",
8990
"colorFieldColorValue": "Farbe {{ color }}.",
90-
"collapseAll": "Alles einklappen",
9191
"commandMenuArchiveSelected": "Archiv ausgewählt",
9292
"commandMenuContent": "Inhalt",
9393
"commandMenuCreateNew": "Neuen {{ type }} erstellenCreate new {{ type }}",
@@ -114,6 +114,7 @@
114114
"commandMenuWidgetDuplicate": "Duplizieren Widget",
115115
"commandMenuWidgetPaste": "Einfügen Widget",
116116
"commandMenuWidgetRemove": "Entfernen Widget",
117+
"confirm": "Bestätigen",
117118
"confirmArchive": "{{ type }} {{ title }} archivieren?",
118119
"confirmSettings": "Einstellungen bestätigen",
119120
"contentArchived": "Inhalt archiviert",
@@ -354,8 +355,8 @@
354355
"mergeCells": "Zellen zusammenführen",
355356
"minLabel": "Min:",
356357
"minSize": "Minimale Grösse {{ width }}x{{ height }}",
357-
"minimumSize": "Mindestgröße von {{ width }} x {{ height }} px",
358358
"minUi": "Min: {{ number }}",
359+
"minimumSize": "Mindestgröße von {{ width }} x {{ height }} px",
359360
"modalBreadcrumbsDefaultLabel": "Eine Bezeichnung festlegen",
360361
"modalTabsError": "Fehler",
361362
"modalTabsErrors": "Fehler",
@@ -375,6 +376,7 @@
375376
"next": "Weiter",
376377
"nextPage": "Nächste Seite",
377378
"no": "Nein",
379+
"noCreateBlankDoc": "Nein, leeres {{ docType }} erstellen",
378380
"noDraftSubmissions": "Keine Entwürfe",
379381
"noItemsAdded": "Keine Elemente hinzugefügt",
380382
"noItemsSelected": "Keine Elemente ausgewählt",
@@ -390,6 +392,7 @@
390392
"notFoundPageStatusCode": "404",
391393
"notFoundPageTitle": "404 - Seite nicht gefunden",
392394
"notInLocale": "Die Seite existiert nicht in {{ label }}. Aus {{ currentLocale }} übersetzen?",
395+
"notInLocaleDoc": "Das aktuelle {{ docType }} existiert nicht in {{ label }}. Version aus {{ currentLocale }} lokalisieren?",
393396
"notYetPublished": "Dieses Dokument wurde noch nicht veröffentlicht.",
394397
"notificationClearEventError": "Fehler beim Löschen der Benachrichtigung",
395398
"nudgeDown": "Nach unten verschieben",
@@ -399,6 +402,7 @@
399402
"oembedTypeNotSupported": "Einbettungstyp nicht unterstützt",
400403
"oembedVideoUrlInvalid": "Video-URL ungültig",
401404
"office": "Büro",
405+
"ok": "OK",
402406
"openGlobal": "Globale Einstellungen öffnen",
403407
"openLinkInNewTab": "Link in neuem Tab öffnen",
404408
"page": "Seite",
@@ -572,6 +576,7 @@
572576
"subscript": "Tiefgestellt",
573577
"suggestionsHeader": "Probiere einen der folgenden Vorschläge:",
574578
"superscript": "Hochgestellt",
579+
"switchLocalesAndLocalizeDoc": "Sprache wechseln und {{ docType }} für {{ label }} lokalisieren?",
575580
"switchLocalesAndLocalizePage": "Sprache ändern zu {{ label }}?",
576581
"table": "Tabelle",
577582
"tableDescription": "Fügen Sie tabellarische Inhalte zu Ihrer Seite hinzu",
@@ -651,6 +656,7 @@
651656
"willMoveImageToArchive": "Bild ins Archiv verschieben.",
652657
"yes": "Ja",
653658
"yesLocalizeAndSwitchLocales": "Ja, diese Seite übersetzen und zu der Sprache wechseln.",
659+
"yesLocalizeAndSwitchLocalesDoc": "Ja, dieses {{ docType }} lokalisieren und Sprache wechseln",
654660
"youTookControl": "Du hast die Kontrolle über dieses Dokument in einer anderen Registerkarte oder einem anderen Fenster übernommen. Ein Dokument kann immer nur an einer Stelle bearbeitet werden.",
655661
"yourDevice": "Ihr Gerät"
656662
}

‎modules/@apostrophecms/i18n/i18n/en.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
"clearSelection": "Clear Selection",
8888
"close": "Close",
8989
"closeGlobal": "Close Global Site Settings",
90+
"collapseAll": "Collapse all",
9091
"colorFieldClickToSelect": "Click to select a color",
9192
"colorFieldColorValue": "Color {{ color }}.",
92-
"collapseAll": "Collapse all",
9393
"commandMenuArchiveSelected": "Archive selected",
9494
"commandMenuContent": "Content",
9595
"commandMenuCreateNew": "Create new {{ type }}",
@@ -116,6 +116,7 @@
116116
"commandMenuWidgetDuplicate": "Duplicate Widget",
117117
"commandMenuWidgetPaste": "Paste Widget",
118118
"commandMenuWidgetRemove": "Remove Widget",
119+
"confirm": "Confirm",
119120
"confirmArchive": "You are going to archive the {{ type }} {{ title }}.",
120121
"confirmSettings": "Confirm Settings",
121122
"contentArchived": "Content Archived",
@@ -380,6 +381,7 @@
380381
"next": "Next",
381382
"nextPage": "Next Page",
382383
"no": "No",
384+
"noCreateBlankDoc": "No, create a blank {{ docType }}",
383385
"noDraftSubmissions": "No Draft Submissions to Manage",
384386
"noItemsAdded": "No Items Added",
385387
"noItemsSelected": "No Items Selected",
@@ -395,6 +397,7 @@
395397
"notFoundPageStatusCode": "404",
396398
"notFoundPageTitle": "404 - Page not found",
397399
"notInLocale": "The current page doesn’t exist in {{ label }}. Localize the version from {{ currentLocale }}?",
400+
"notInLocaleDoc": "The current {{ docType }} doesn’t exist in {{ label }}. Localize the version from {{ currentLocale }}?",
398401
"notYetPublished": "This document hasn't been published yet.",
399402
"notificationClearEventError": "There was an error clearing a registered notification event.",
400403
"nudgeDown": "Nudge Down",
@@ -404,6 +407,7 @@
404407
"oembedTypeNotSupported": "Embed type not supported",
405408
"oembedVideoUrlInvalid": "Video URL invalid",
406409
"office": "Office",
410+
"ok": "OK",
407411
"openGlobal": "Open Global Site Settings",
408412
"openLinkInNewTab": "Open link in new tab",
409413
"page": "Page",
@@ -578,6 +582,7 @@
578582
"suggestionsHeader": "Try one of these suggestions:",
579583
"superscript": "Superscript",
580584
"switchLocalesAndLocalizePage": "Switch locales and localize page to {{ label }}?",
585+
"switchLocalesAndLocalizeDoc": "Switch locales and localize {{ docType }} to {{ label }}?",
581586
"table": "Table",
582587
"tableDescription": "Add tabular content to your page",
583588
"tableImport": "Import Table",
@@ -658,6 +663,7 @@
658663
"willMoveImageToArchive": "This will move the image to the archive.",
659664
"yes": "Yes",
660665
"yesLocalizeAndSwitchLocales": "Yes, localize this page and switch locales",
666+
"yesLocalizeAndSwitchLocalesDoc": "Yes, localize this {{ docType }} and switch locales",
661667
"youTookControl": "You took control of this document in another tab or window. A document can only be edited in one place at a time.",
662668
"yourDevice": "your device"
663669
}

0 commit comments

Comments
 (0)