Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
872a142
missing negative button interpolation in apos confirm modal
ValJed Nov 3, 2025
d772b4d
adds translation keys
ValJed Nov 3, 2025
ec69bdc
adds confirmation modal in AposDocLocalePicker to ask for doc localiz…
ValJed Nov 3, 2025
49f523b
rename shouldLocalize toLocalize, passes entire locale (name, label) …
ValJed Nov 3, 2025
54669ba
updaes AposDocEditor switchLocale method
ValJed Nov 3, 2025
df3ee5a
removes logs
ValJed Nov 3, 2025
b4e3fe3
passes isManager props in AposDocLocaleSwitcher to handle different b…
ValJed Nov 3, 2025
0bd99b5
gets current locale from modalData in localize modal
ValJed Nov 4, 2025
e7e3d3d
emits modal result when localizing document if has been done or not
ValJed Nov 4, 2025
6d6cd15
if toLocalize is null (the use closed the modal) just do nothing
ValJed Nov 4, 2025
37fe79a
set currentId in instantiateExistingDoc method, no more slug conflict…
ValJed Nov 4, 2025
ee84a64
adds translation in all locales
ValJed Nov 4, 2025
a4fa926
adds changelog
ValJed Nov 4, 2025
097f453
fixes translation key
ValJed Nov 4, 2025
53960bf
fixes pages manager
ValJed Nov 4, 2025
6ce2cec
do not ask to localize if doc doesn't exist in current locale
ValJed Nov 4, 2025
3482501
removes duplicated updateModalData method instantiation
ValJed Nov 4, 2025
b82443d
uses saved doc to localize (if saved before to switch), passes module…
ValJed Nov 4, 2025
c155180
fixes sk translations
ValJed Nov 5, 2025
c03f0e3
feedback changelog
ValJed Nov 5, 2025
439ed93
fixes locale switcher localize modal translation for pages
ValJed Nov 5, 2025
a981739
Merge remote-tracking branch 'origin/main' into pro-8541-switch-local…
ValJed Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

### Adds

* When switching locale from the doc editor, ask the user if he wants to localize the current one in the target locale or want to start a blank document.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* When switching locale from the doc editor, ask the user if he wants to localize the current one in the target locale or want to start a blank document.
* 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


## 4.23.0 (2025-10-30)

### Adds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export default {
}
const canEdit = docData._edit || this.moduleOptions.canEdit;
this.readOnly = canEdit === false;
if (canEdit && !await this.lock(this.getOnePath, this.currentId)) {
if (canEdit && !await this.lock(this.getOnePath, docData._id)) {
this.lockNotAvailable();
}
} catch {
Expand All @@ -548,6 +548,7 @@ export default {
if (docData.type !== this.docType) {
this.docType = docData.type;
}
this.currentId = docData._id;
this.original = klona(docData);
this.docFields.data = docData;
// TODO: Is this block even useful since published is fetched after
Expand Down Expand Up @@ -860,10 +861,11 @@ export default {
this.modal.showModal = false;
},
async switchLocale({
locale, localized, save
locale, save, localized, toLocalize
}) {
let saved;
if (save) {
const saved = await this.saveHandler('onSave', {
saved = await this.saveHandler('onSave', {
keepOpen: true,
andPublish: false
});
Expand All @@ -874,18 +876,38 @@ export default {
this.referenceDocId = saved._id;
}
}
this.updateModalData(this.modalData.id, { locale });
this.localeSwitched = locale !== apos.i18n.locale;
this.published = null;
if (localized) {
this.currentId = localized._id;
this.switchModalLocale(locale.name);
await this.instantiateExistingDoc();
} else {
return;
}
if (!toLocalize) {
this.switchModalLocale(locale.name);
this.currentId = '';
this.docType = this.moduleName;
await this.instantiateNewDoc();
return;
}

const isLocalized = await apos.modal.execute('AposI18nLocalize', {
doc: saved || this.original,
locale,
moduleName: this.moduleName,
redirect: false
});

if (isLocalized) {
this.switchModalLocale(locale.name);
await this.$nextTick();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here only?

await this.instantiateExistingDoc();
}
},
switchModalLocale(locale) {
this.updateModalData(this.modalData.id, { locale });
this.localeSwitched = locale !== apos.i18n.locale;
this.published = null;
},
getRequestBody({ newInstance = false, update = false }) {
const body = newInstance
? { _newInstance: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
>
<AposLocalePicker
:current-locale="locale"
:localized="localized"
:localized="docLocalized"
:forbidden="forbidden"
:forbidden-tooltip="forbiddenTooltip"
:is-open="isOpen"
:show-localized="showLocalized"
:show-localized="!isManager"
@switch-locale="switchLocale"
/>
</AposContextMenu>
Expand Down Expand Up @@ -53,19 +53,18 @@ const props = defineProps({
type: Boolean,
required: true
},
showLocalized: {
isManager: {
type: Boolean,
default: true
default: false
}
});

const $t = inject('i18n');
const i18nAction = apos.modules['@apostrophecms/i18n'].action;
const forbiddenTooltip = $t('apostrophe:localeSwitcherPermissionToCreate', {
docType: props.moduleOptions.label.toLowerCase()
});
const docType = props.moduleOptions.label.toLowerCase();
const forbiddenTooltip = $t('apostrophe:localeSwitcherPermissionToCreate', { docType });
const menu = ref(null);
const localized = ref({});
const docLocalized = ref({});
const forbidden = ref([]);
const isOpen = ref(false);
const button = computed(() => {
Expand All @@ -91,7 +90,7 @@ async function open() {
const docs = await apos.http.get(
`${props.moduleOptions.action}/${props.docId}/locales`, { busy: true }
);
localized.value = Object.fromEntries(
docLocalized.value = Object.fromEntries(
docs.results
.filter(doc => doc.aposLocale.endsWith(':draft'))
.map(doc => [ doc.aposLocale.split(':')[0], doc ])
Expand All @@ -106,7 +105,7 @@ async function open() {

async function checkCreatePermission() {
const localesWithNoDocs = Object.keys(apos.i18n.locales)
.filter((locale) => !localized.value[locale]);
.filter((locale) => !docLocalized.value[locale]);

const allowed = await apos.http.get(`${i18nAction}/locales-permissions`, {
qs: {
Expand All @@ -131,29 +130,58 @@ async function switchLocale(locale) {
return;
}

if (props.isManager) {
emit('switch-locale', { locale });
return;
}

const save = props.isModified
? await apos.confirm({
heading: 'apostrophe:unsavedChanges',
description: $t(
'apostrophe:localeSwitcherDiscardChangesPrompt',
{ docType: props.moduleOptions.label.toLowerCase() }
),
description: 'apostrophe:localeSwitcherDiscardChangesPrompt',
negativeLabel: 'apostrophe:localeSwitcherDiscardChangesNegative',
affirmativeLabel: 'apostrophe:localeSwitcherDiscardChangesAffirmative',
icon: false
}, {
hasCloseButton: true,
tiny: true
tiny: true,
interpolate: {
docType
}
})
: false;

if (save === null) {
return;
}

const docExist = docLocalized.value[props.locale];
const isDocLocalized = docLocalized.value[locale.name];
const toLocalize = (docExist && !isDocLocalized)
? await apos.confirm({
heading: 'apostrophe:switchLocalesAndLocalizeDoc',
description: 'apostrophe:notInLocaleDoc',
negativeLabel: 'apostrophe:noCreateBlankDoc',
affirmativeLabel: 'apostrophe:yesLocalizeAndSwitchLocalesDoc'
}, {
hasCloseButton: true,
tiny: true,
interpolate: {
docType,
label: locale.label,
currentLocale: props.locale
}
})
: false;

if (toLocalize === null) {
return;
}

emit('switch-locale', {
locale: locale.name,
localized: localized.value[locale.name],
locale,
localized: docLocalized.value[locale.name],
toLocalize,
save
});
}
Expand Down
12 changes: 9 additions & 3 deletions modules/@apostrophecms/i18n/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"batchPublishCompleted": "{{ count }} {{ type }} veröffentlicht.",
"batchPublishProgress": "Veröffentlichung {{ type }}...",
"batchRestoreCompleted": "{{ count }} {{ type }} wiederhergestellt.",
"batchRestoreProgress": "Wiederherstellung {{ type }}...",
"batchTagProgress": "Taggen von {{ count }} {{ type }}...",
"batchUntagProgress": "Entfernen der Markierung von {{ count }} {{ type }}...",
"batchRestoreProgress": "Wiederherstellung {{ type }}...",
"breakpointPreviewClear": "Klarer Haltepunkt",
"breakpointPreviewDesktop": "Desktop",
"breakpointPreviewExit": "Beenden",
Expand All @@ -85,9 +85,9 @@
"clearSelection": "Auswahl löschen",
"close": "Schliessen",
"closeGlobal": "Globale Einstellungen schliessen",
"collapseAll": "Alles einklappen",
"colorFieldClickToSelect": "Klicken, um eine Farbe auszuwählen",
"colorFieldColorValue": "Farbe {{ color }}.",
"collapseAll": "Alles einklappen",
"commandMenuArchiveSelected": "Archiv ausgewählt",
"commandMenuContent": "Inhalt",
"commandMenuCreateNew": "Neuen {{ type }} erstellenCreate new {{ type }}",
Expand All @@ -114,6 +114,7 @@
"commandMenuWidgetDuplicate": "Duplizieren Widget",
"commandMenuWidgetPaste": "Einfügen Widget",
"commandMenuWidgetRemove": "Entfernen Widget",
"confirm": "Bestätigen",
"confirmArchive": "{{ type }} {{ title }} archivieren?",
"confirmSettings": "Einstellungen bestätigen",
"contentArchived": "Inhalt archiviert",
Expand Down Expand Up @@ -337,8 +338,8 @@
"mergeCells": "Zellen zusammenführen",
"minLabel": "Min:",
"minSize": "Minimale Grösse {{ width }}x{{ height }}",
"minimumSize": "Mindestgröße von {{ width }} x {{ height }} px",
"minUi": "Min: {{ number }}",
"minimumSize": "Mindestgröße von {{ width }} x {{ height }} px",
"modalBreadcrumbsDefaultLabel": "Eine Bezeichnung festlegen",
"modalTabsError": "Fehler",
"modalTabsErrors": "Fehler",
Expand All @@ -358,6 +359,7 @@
"next": "Weiter",
"nextPage": "Nächste Seite",
"no": "Nein",
"noCreateBlankDoc": "Nein, leeres {{ docType }} erstellen",
"noDraftSubmissions": "Keine Entwürfe",
"noItemsAdded": "Keine Elemente hinzugefügt",
"noItemsSelected": "Keine Elemente ausgewählt",
Expand All @@ -373,6 +375,7 @@
"notFoundPageStatusCode": "404",
"notFoundPageTitle": "404 - Seite nicht gefunden",
"notInLocale": "Die Seite existiert nicht in {{ label }}. Aus {{ currentLocale }} übersetzen?",
"notInLocaleDoc": "Das aktuelle {{ docType }} existiert nicht in {{ label }}. Version aus {{ currentLocale }} lokalisieren?",
"notYetPublished": "Dieses Dokument wurde noch nicht veröffentlicht.",
"notificationClearEventError": "Fehler beim Löschen der Benachrichtigung",
"nudgeDown": "Nach unten verschieben",
Expand All @@ -382,6 +385,7 @@
"oembedTypeNotSupported": "Einbettungstyp nicht unterstützt",
"oembedVideoUrlInvalid": "Video-URL ungültig",
"office": "Büro",
"ok": "OK",
"openGlobal": "Globale Einstellungen öffnen",
"openLinkInNewTab": "Link in neuem Tab öffnen",
"page": "Seite",
Expand Down Expand Up @@ -555,6 +559,7 @@
"subscript": "Tiefgestellt",
"suggestionsHeader": "Probiere einen der folgenden Vorschläge:",
"superscript": "Hochgestellt",
"switchLocalesAndLocalizeDoc": "Sprache wechseln und {{ docType }} für {{ label }} lokalisieren?",
"switchLocalesAndLocalizePage": "Sprache ändern zu {{ label }}?",
"table": "Tabelle",
"tableDescription": "Fügen Sie tabellarische Inhalte zu Ihrer Seite hinzu",
Expand Down Expand Up @@ -634,6 +639,7 @@
"willMoveImageToArchive": "Bild ins Archiv verschieben.",
"yes": "Ja",
"yesLocalizeAndSwitchLocales": "Ja, diese Seite übersetzen und zu der Sprache wechseln.",
"yesLocalizeAndSwitchLocalesDoc": "Ja, dieses {{ docType }} lokalisieren und Sprache wechseln",
"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.",
"yourDevice": "Ihr Gerät"
}
8 changes: 7 additions & 1 deletion modules/@apostrophecms/i18n/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
"clearSelection": "Clear Selection",
"close": "Close",
"closeGlobal": "Close Global Site Settings",
"collapseAll": "Collapse all",
"colorFieldClickToSelect": "Click to select a color",
"colorFieldColorValue": "Color {{ color }}.",
"collapseAll": "Collapse all",
"commandMenuArchiveSelected": "Archive selected",
"commandMenuContent": "Content",
"commandMenuCreateNew": "Create new {{ type }}",
Expand All @@ -116,6 +116,7 @@
"commandMenuWidgetDuplicate": "Duplicate Widget",
"commandMenuWidgetPaste": "Paste Widget",
"commandMenuWidgetRemove": "Remove Widget",
"confirm": "Confirm",
"confirmArchive": "You are going to archive the {{ type }} {{ title }}.",
"confirmSettings": "Confirm Settings",
"contentArchived": "Content Archived",
Expand Down Expand Up @@ -380,6 +381,7 @@
"next": "Next",
"nextPage": "Next Page",
"no": "No",
"noCreateBlankDoc": "No, create a blank {{ docType }}",
"noDraftSubmissions": "No Draft Submissions to Manage",
"noItemsAdded": "No Items Added",
"noItemsSelected": "No Items Selected",
Expand All @@ -395,6 +397,7 @@
"notFoundPageStatusCode": "404",
"notFoundPageTitle": "404 - Page not found",
"notInLocale": "The current page doesn’t exist in {{ label }}. Localize the version from {{ currentLocale }}?",
"notInLocaleDoc": "The current {{ docType }} doesn’t exist in {{ label }}. Localize the version from {{ currentLocale }}?",
"notYetPublished": "This document hasn't been published yet.",
"notificationClearEventError": "There was an error clearing a registered notification event.",
"nudgeDown": "Nudge Down",
Expand All @@ -404,6 +407,7 @@
"oembedTypeNotSupported": "Embed type not supported",
"oembedVideoUrlInvalid": "Video URL invalid",
"office": "Office",
"ok": "OK",
"openGlobal": "Open Global Site Settings",
"openLinkInNewTab": "Open link in new tab",
"page": "Page",
Expand Down Expand Up @@ -578,6 +582,7 @@
"suggestionsHeader": "Try one of these suggestions:",
"superscript": "Superscript",
"switchLocalesAndLocalizePage": "Switch locales and localize page to {{ label }}?",
"switchLocalesAndLocalizeDoc": "Switch locales and localize {{ docType }} to {{ label }}?",
"table": "Table",
"tableDescription": "Add tabular content to your page",
"tableImport": "Import Table",
Expand Down Expand Up @@ -658,6 +663,7 @@
"willMoveImageToArchive": "This will move the image to the archive.",
"yes": "Yes",
"yesLocalizeAndSwitchLocales": "Yes, localize this page and switch locales",
"yesLocalizeAndSwitchLocalesDoc": "Yes, localize this {{ docType }} and switch locales",
"youTookControl": "You took control of this document in another tab or window. A document can only be edited in one place at a time.",
"yourDevice": "your device"
}
Loading