33 class="apos-wizard apos-i18n-localize"
44 :class =" { ' apos-wizard-busy' : wizard .busy } "
55 :modal =" modal "
6+ :modal-data =" modalData "
67 @esc =" close "
78 @inactive =" modal .active = false "
89 @show-modal =" modal .showModal = true "
@@ -325,6 +326,10 @@ export default {
325326 required: true ,
326327 type: String
327328 },
329+ modalData: {
330+ required: true ,
331+ type: Object
332+ },
328333 shouldRedirect: {
329334 type: Boolean ,
330335 default: true
@@ -419,6 +424,7 @@ export default {
419424 allRelatedDocs: [],
420425 allRelatedDocsKnown: false ,
421426 docTypesSeen: [],
427+ relatedDocTypes: [],
422428 searchField: {
423429 label: this .$t (' apostrophe:searchLocales' ),
424430 placeholder: ` ${ this .$t (' apostrophe:searchLocales' )} ...`
@@ -488,13 +494,6 @@ export default {
488494 isBatchMode () {
489495 return this .batchOptions .enabled ;
490496 },
491- currentLocale () {
492- // We need to grab the locale from the modal data, because it can change
493- // while in modal (switch locale in editor modal).
494- // Exposing `modalData` property breaks the internally used AposModal
495- // component for some unknown reason, so we need to use the attrs.
496- return this .$attrs [' modal-data' ]? .locale ?? this .moduleOptions .locale ;
497- },
498497 action () {
499498 return this .doc .slug .startsWith (' /' )
500499 ? apos .page .action
@@ -518,32 +517,6 @@ export default {
518517 .filter (locale => ! this .isCurrentLocale (locale) && this .canEditLocale (locale))
519518 .length ;
520519 },
521- relatedDocTypes () {
522- if (this .isBatchMode ) {
523- return this .getRelatedSchemaTypes (this .batchOptions .checkedTypes );
524- }
525-
526- const types = {};
527- for (const doc of this .relatedDocs ) {
528- if (! types[doc .type ]) {
529- types[doc .type ] = {
530- value: doc .type ,
531- count: 0 ,
532- readOnly: false
533- };
534- }
535- types[doc .type ].count ++ ;
536- }
537- for (const type of Object .values (types)) {
538- const baseLabel = this .plural (type .value );
539- type .label = {
540- key: ' apostrophe:typeWithCount' ,
541- type: this .$t (baseLabel),
542- count: type .count
543- };
544- }
545- return Object .values (types);
546- },
547520 relatedDocTypesField () {
548521 return {
549522 name: ' related-doc-types-to-localize' ,
@@ -611,17 +584,6 @@ export default {
611584 }
612585 }
613586 }
614- },
615- relatedDocTypes (newVal ) {
616- if (! this .isBatchMode ) {
617- return ;
618- }
619- for (const item of newVal) {
620- if (! this .docTypesSeen .includes (item .value )) {
621- this .docTypesSeen .push (item .value );
622- this .wizard .values .relatedDocTypesToLocalize .data .push (item .value );
623- }
624- }
625587 }
626588 },
627589 async mounted () {
@@ -631,6 +593,7 @@ export default {
631593 if (this .isBatchMode ) {
632594 this .wizard .step = this .visibleStepNames [0 ];
633595 this .wizard .busy = false ;
596+ this .setRelatedDocTypes ();
634597 } else {
635598 try {
636599 this .fullDoc = await apos .http .get (
@@ -659,6 +622,40 @@ export default {
659622 }
660623 },
661624 methods: {
625+ setRelatedDocTypes () {
626+ if (this .isBatchMode ) {
627+ this .relatedDocTypes = this .getRelatedSchemaTypes (this .batchOptions .checkedTypes );
628+ for (const item of this .relatedDocTypes ) {
629+ if (! this .docTypesSeen .includes (item .value )) {
630+ this .docTypesSeen .push (item .value );
631+ this .wizard .values .relatedDocTypesToLocalize .data .push (item .value );
632+ }
633+ }
634+ return ;
635+ }
636+
637+ const types = {};
638+ for (const doc of this .relatedDocs ) {
639+ if (! types[doc .type ]) {
640+ types[doc .type ] = {
641+ value: doc .type ,
642+ count: 0 ,
643+ readOnly: false
644+ };
645+ }
646+ types[doc .type ].count ++ ;
647+ }
648+ for (const type of Object .values (types)) {
649+ const baseLabel = this .plural (type .value );
650+ type .label = {
651+ key: ' apostrophe:typeWithCount' ,
652+ type: this .$t (baseLabel),
653+ count: type .count
654+ };
655+ }
656+ this .relatedDocTypes = Object .values (types);
657+
658+ },
662659 normalizeConfig () {
663660 if (this .isBatchMode ) {
664661 this .toLocalizeChoices = this .toLocalizeChoicesBatch ;
@@ -710,7 +707,7 @@ export default {
710707 return this .wizard .step === name;
711708 },
712709 isCurrentLocale (locale ) {
713- return this .currentLocale === locale .name ;
710+ return this .modalData . locale === locale .name ;
714711 },
715712 canEditLocale (locale ) {
716713 return !! locale ._edit ;
@@ -1158,6 +1155,17 @@ export default {
11581155 }
11591156 this.relatedDocs = relatedDocs;
11601157 this.wizard.busy = status;
1158+
1159+ for (const doc of this.relatedDocs) {
1160+ if (!this.docTypesSeen.includes(doc.type)) {
1161+ this.docTypesSeen.push(doc.type);
1162+ if (apos.modules[doc.type].relatedDocument) {
1163+ this.wizard.values.relatedDocTypesToLocalize.data.push(doc.type);
1164+ }
1165+ }
1166+ }
1167+
1168+ this.setRelatedDocTypes();
11611169 },
11621170 wait(time) {
11631171 return new Promise((resolve) => {
@@ -1180,7 +1188,7 @@ export default {
11801188 this.wizard.values.translateTargets.data = [];
11811189 return;
11821190 }
1183- const sourceLocale = this.currentLocale ;
1191+ const sourceLocale = this.modalData.locale ;
11841192 const targets = this.wizard.values.toLocales.data;
11851193
11861194 let response;
0 commit comments