nextjs-cms 0.9.29 → 0.9.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +279 -279
- package/dist/api/actions/pages.d.ts +3 -3
- package/dist/api/index.d.ts +974 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +13 -0
- package/dist/api/lib/serverActions.d.ts +49 -13
- package/dist/api/lib/serverActions.d.ts.map +1 -1
- package/dist/api/lib/serverActions.js +31 -103
- package/dist/api/root.d.ts +1916 -18
- package/dist/api/root.d.ts.map +1 -1
- package/dist/api/root.js +83 -18
- package/dist/api/routers/config.d.ts.map +1 -1
- package/dist/api/routers/gallery.d.ts +0 -1
- package/dist/api/routers/gallery.d.ts.map +1 -1
- package/dist/api/routers/gallery.js +8 -36
- package/dist/api/routers/hasItemsSection.d.ts +30 -5
- package/dist/api/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/routers/navigation.d.ts +3 -3
- package/dist/api/routers/simpleSection.d.ts +15 -3
- package/dist/api/routers/simpleSection.d.ts.map +1 -1
- package/dist/api/trpc/root.d.ts +3 -3
- package/dist/api/trpc/root.d.ts.map +1 -1
- package/dist/api/trpc/routers/config.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/trpc/routers/navigation.d.ts +3 -3
- package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -1
- package/dist/api/trpc/server.d.ts +9 -9
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/auth/trpc.d.ts +1 -1
- package/dist/auth/trpc.d.ts.map +1 -1
- package/dist/auth/trpc.js +1 -0
- package/dist/cli/lib/db-config.js +10 -10
- package/dist/cli/lib/update-sections.d.ts.map +1 -1
- package/dist/cli/lib/update-sections.js +24 -29
- package/dist/core/db/table-checker/MysqlTable.js +10 -10
- package/dist/core/factories/section-factory-with-esbuild.js +9 -9
- package/dist/core/factories/section-factory-with-jiti.js +9 -9
- package/dist/core/fields/dateRange.d.ts +115 -0
- package/dist/core/fields/dateRange.d.ts.map +1 -0
- package/dist/core/fields/dateRange.js +149 -0
- package/dist/core/sections/category.d.ts +42 -42
- package/dist/core/sections/hasItems.d.ts +42 -42
- package/dist/core/sections/section.d.ts +22 -22
- package/dist/core/sections/simple.d.ts +8 -8
- package/dist/plugins/derive.d.ts +0 -8
- package/dist/plugins/derive.d.ts.map +1 -1
- package/dist/plugins/derive.js +0 -32
- package/dist/plugins/server.d.ts +1 -1
- package/dist/plugins/server.d.ts.map +1 -1
- package/dist/plugins/server.js +1 -1
- package/dist/translations/client.d.ts +4 -4
- package/dist/translations/locale-cookie.d.ts +24 -0
- package/dist/translations/locale-cookie.d.ts.map +1 -0
- package/dist/translations/locale-cookie.js +44 -0
- package/dist/translations/locale-utils.d.ts +8 -0
- package/dist/translations/locale-utils.d.ts.map +1 -0
- package/dist/translations/locale-utils.js +11 -0
- package/dist/translations/localization.d.ts +40 -0
- package/dist/translations/localization.d.ts.map +1 -0
- package/dist/translations/localization.js +48 -0
- package/dist/validators/dateRange.d.ts +11 -0
- package/dist/validators/dateRange.d.ts.map +1 -0
- package/dist/validators/dateRange.js +16 -0
- package/package.json +1 -1
- package/dist/api/client.d.ts +0 -30
- package/dist/api/client.d.ts.map +0 -1
- package/dist/api/client.js +0 -82
- package/dist/api/server.d.ts +0 -2748
- package/dist/api/server.d.ts.map +0 -1
- package/dist/api/server.js +0 -100
- package/dist/api/utils/async-caller-proxy.d.ts +0 -2
- package/dist/api/utils/async-caller-proxy.d.ts.map +0 -1
- package/dist/api/utils/async-caller-proxy.js +0 -36
- package/dist/api/utils/lazy-caller-proxy.d.ts +0 -2
- package/dist/api/utils/lazy-caller-proxy.d.ts.map +0 -1
- package/dist/api/utils/lazy-caller-proxy.js +0 -36
- package/dist/api/utils/router-types.d.ts +0 -7
- package/dist/api/utils/router-types.d.ts.map +0 -1
- package/dist/api/utils/router-types.js +0 -0
- package/dist/plugins/manifest.d.ts +0 -28
- package/dist/plugins/manifest.d.ts.map +0 -1
- package/dist/plugins/manifest.js +0 -83
- package/dist/plugins/registry.d.ts +0 -22
- package/dist/plugins/registry.d.ts.map +0 -1
- package/dist/plugins/registry.js +0 -25
- package/dist/utils/log.d.ts +0 -18
- package/dist/utils/log.d.ts.map +0 -1
- package/dist/utils/log.js +0 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverActions.d.ts","sourceRoot":"","sources":["../../../src/api/lib/serverActions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serverActions.d.ts","sourceRoot":"","sources":["../../../src/api/lib/serverActions.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AASlD,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAKxE,eAAO,MAAM,eAAe,GAAU,gCAInC;IACC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACjB,qBAmBA,CAAA;AACD,eAAO,MAAM,WAAW,GACpB,SAAS,OAAO,EAChB,OAAO;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE;;;EA4GlE,CAAA;AAyDD,eAAO,MAAM,QAAQ,GAAU,OAAO;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,oBAgDxF,CAAA;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,wDAyB3F;AAED,eAAO,MAAM,QAAQ,GAAU,SAAS,OAAO,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AS,OAAO,EAAE,aAAa,MAAM,EAAE,OAAM,MAAU,EAAE,IAAI,MAAM;;;;;;;;;;;;;;YAuInF,MAAM,GAAG,MAAM;sBACL,MAAM;oBACR,MAAM,GAAG,IAAI;mBACd,MAAM;mBACN,MAAM;oBACL,MAAM;;;;EAKjC,CAAA;AAED,eAAO,MAAM,UAAU,GAAU,SAAS,OAAO;;;;;;;;;;;;;;;;;;;;;EAqFhD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACnB,MAAM,MAAM,EACZ,UAAU;IACN,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACf,KACF,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAGpC,CAAA"}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
// import 'server-only'
|
|
2
|
+
import { db } from '../../db/client.js';
|
|
3
|
+
import { AdminPrivilegesTable, AdminsTable, EditorPhotosTable } from '../../db/schema.js';
|
|
4
|
+
import { and, eq, sql } from 'drizzle-orm';
|
|
5
|
+
import { TRPCError } from '@trpc/server';
|
|
6
|
+
import { FieldFactory, SectionFactory } from '../../core/factories/index.js';
|
|
7
|
+
import { SelectField } from '../../core/fields/index.js';
|
|
8
|
+
import { MysqlTableChecker } from '../../core/db/index.js';
|
|
2
9
|
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
10
|
import { Readable } from 'stream';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { fileTypeFromBuffer } from 'file-type';
|
|
8
|
-
import { readChunk } from 'read-chunk';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { sanitizeFileName, sanitizeFolderOrFileName } from '../../utils/index.js';
|
|
9
13
|
import sharp from 'sharp';
|
|
10
|
-
import
|
|
14
|
+
import { readChunk } from 'read-chunk';
|
|
15
|
+
import { fileTypeFromBuffer } from 'file-type';
|
|
11
16
|
import { getCMSConfig } from '../../core/config/index.js';
|
|
12
|
-
import { MysqlTableChecker } from '../../core/db/index.js';
|
|
13
|
-
import { FieldFactory, SectionFactory } from '../../core/factories/index.js';
|
|
14
|
-
import { SelectField } from '../../core/fields/index.js';
|
|
15
17
|
import { resolveLocale } from '../../core/localization/index.js';
|
|
16
|
-
import { db } from '../../db/client.js';
|
|
17
|
-
import { AdminPrivilegesTable, AdminsTable, EditorPhotosTable } from '../../db/schema.js';
|
|
18
|
-
import { recordLog } from '../../logging/index.js';
|
|
19
18
|
import { getPluginRoutes } from '../../plugins/loader.js';
|
|
19
|
+
import through2 from 'through2';
|
|
20
|
+
import { recordLog } from '../../logging/index.js';
|
|
20
21
|
import getString from '../../translations/index.js';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
22
|
+
import { resolveMultilingualString } from '../../translations/language-utils.js';
|
|
23
|
+
import { resolveLanguage } from '../../translations/language-utils.js';
|
|
23
24
|
export const isAccessAllowed = async ({ sectionName, role, userId, }) => {
|
|
24
25
|
/**
|
|
25
26
|
* Check admin privileges
|
|
@@ -38,35 +39,6 @@ export const isAccessAllowed = async ({ sectionName, role, userId, }) => {
|
|
|
38
39
|
}
|
|
39
40
|
return true;
|
|
40
41
|
};
|
|
41
|
-
async function deleteGalleryFiles({ uploadsFolder, sectionName, photos, }) {
|
|
42
|
-
for (const photo of photos) {
|
|
43
|
-
try {
|
|
44
|
-
await fs.promises.unlink(path.join(uploadsFolder, '.photos', sectionName, photo));
|
|
45
|
-
await fs.promises.unlink(path.join(uploadsFolder, '.thumbs', sectionName, photo));
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error('Error deleting gallery photo', error);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async function deleteLocalizedGalleryRows({ section, gallery, sectionItemId, locale, uploadsFolder, }) {
|
|
53
|
-
if (!gallery.localized)
|
|
54
|
-
return;
|
|
55
|
-
const { tableName, referenceIdentifierField, photoNameField } = gallery.db;
|
|
56
|
-
const columns = await MysqlTableChecker.getColumns(tableName);
|
|
57
|
-
if (!columns.includes(referenceIdentifierField) ||
|
|
58
|
-
!columns.includes(photoNameField) ||
|
|
59
|
-
!columns.includes('locale')) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const [rows] = await db.execute(sql `SELECT \`${sql.raw(photoNameField)}\` AS photo FROM \`${sql.raw(tableName)}\` WHERE \`${sql.raw(referenceIdentifierField)}\` = ${sectionItemId} AND \`locale\` = ${locale}`);
|
|
63
|
-
const photos = (rows ?? []).map((row) => row.photo).filter(Boolean);
|
|
64
|
-
await deleteGalleryFiles({ uploadsFolder, sectionName: section.name, photos });
|
|
65
|
-
await db.execute(sql `DELETE FROM \`${sql.raw(tableName)}\` WHERE \`${sql.raw(referenceIdentifierField)}\` = ${sectionItemId} AND \`locale\` = ${locale}`);
|
|
66
|
-
}
|
|
67
|
-
function sectionHasLocalizedContent(section) {
|
|
68
|
-
return section.hasLocalizedContent ?? section.hasLocalizedFields ?? false;
|
|
69
|
-
}
|
|
70
42
|
export const getDocument = async (session, input) => {
|
|
71
43
|
const { name, sectionName, fieldName } = input;
|
|
72
44
|
// Sanitize the inputs
|
|
@@ -301,11 +273,11 @@ export const getAllPrivileges = async (session) => {
|
|
|
301
273
|
// Now, let's add the rest of the privileges to the list
|
|
302
274
|
sections.forEach((section, index) => {
|
|
303
275
|
let title;
|
|
304
|
-
if (
|
|
305
|
-
title = resolveMultilingualString(section.title
|
|
276
|
+
if (typeof section.title === 'string') {
|
|
277
|
+
title = resolveMultilingualString(section.title, language, cmsConfig.i18n.fallbackLanguage);
|
|
306
278
|
}
|
|
307
279
|
else {
|
|
308
|
-
title = resolveMultilingualString(section.title, language, cmsConfig.i18n.fallbackLanguage);
|
|
280
|
+
title = resolveMultilingualString(section.title.section, language, cmsConfig.i18n.fallbackLanguage);
|
|
309
281
|
}
|
|
310
282
|
privilegesList.push({
|
|
311
283
|
title,
|
|
@@ -408,8 +380,7 @@ export const createSimpleSectionPage = async (session, sectionName, locale) => {
|
|
|
408
380
|
let localizationData = null;
|
|
409
381
|
if (localeResult.localizationEnabled) {
|
|
410
382
|
let existingTranslations = [];
|
|
411
|
-
|
|
412
|
-
if (hasLocalizedContent) {
|
|
383
|
+
if (sectionInfo.hasLocalizedFields) {
|
|
413
384
|
const localesTableName = sectionInfo.localesTableName;
|
|
414
385
|
const localeColumns = await MysqlTableChecker.getColumns(localesTableName);
|
|
415
386
|
const localeTableExists = localeColumns.length > 0;
|
|
@@ -457,9 +428,6 @@ export const createSimpleSectionPage = async (session, sectionName, locale) => {
|
|
|
457
428
|
: [];
|
|
458
429
|
field.setValue(tags.join(','));
|
|
459
430
|
}
|
|
460
|
-
else if (field.type === 'date_range' && typeof f.setRangeValues === 'function') {
|
|
461
|
-
f.setRangeValues(localeRow ? (localeRow[f.startName] ?? null) : null, localeRow ? (localeRow[f.endName] ?? null) : null);
|
|
462
|
-
}
|
|
463
431
|
else {
|
|
464
432
|
// Simple field: override from locale row
|
|
465
433
|
field.setValue(localeRow ? (localeRow[field.name] ?? null) : null);
|
|
@@ -468,22 +436,11 @@ export const createSimpleSectionPage = async (session, sectionName, locale) => {
|
|
|
468
436
|
}
|
|
469
437
|
}
|
|
470
438
|
}
|
|
471
|
-
// Show the locale switcher when multiple locales are configured AND either:
|
|
472
|
-
// - the section has localized fields (production case), or
|
|
473
|
-
// - the app is in development mode (so devs can preview the switcher
|
|
474
|
-
// while wiring up localization on a section).
|
|
475
|
-
// The developer note is rendered in dev-mode only, when the switcher is
|
|
476
|
-
// visible but the section itself has no localized content yet.
|
|
477
|
-
const localeSwitcherEnabled = localeResult.availableLocales.length > 1 &&
|
|
478
|
-
(hasLocalizedContent === true || process.env.NODE_ENV === 'development');
|
|
479
|
-
const developerNoteEnabled = localeSwitcherEnabled && hasLocalizedContent === false;
|
|
480
439
|
localizationData = {
|
|
481
440
|
defaultLocale: localeResult.defaultLocale,
|
|
482
441
|
currentLocale: localeResult.resolvedLocale ?? localeResult.defaultLocale,
|
|
483
442
|
existingTranslations,
|
|
484
443
|
locales: localeResult.availableLocales,
|
|
485
|
-
localeSwitcherEnabled,
|
|
486
|
-
developerNoteEnabled,
|
|
487
444
|
};
|
|
488
445
|
}
|
|
489
446
|
return {
|
|
@@ -563,7 +520,7 @@ export const deleteSectionItem = async (session, sectionName, sectionItemId, rec
|
|
|
563
520
|
* Use deleteLocaleTranslation per locale to ensure localized files are cleaned up from disk.
|
|
564
521
|
*/
|
|
565
522
|
const cmsConfig = await getCMSConfig();
|
|
566
|
-
if (cmsConfig.localization?.enabled &&
|
|
523
|
+
if (cmsConfig.localization?.enabled && section.hasLocalizedFields) {
|
|
567
524
|
const localesTableName = section.localesTableName;
|
|
568
525
|
const localeColumns = await MysqlTableChecker.getColumns(localesTableName);
|
|
569
526
|
if (localeColumns.length > 0) {
|
|
@@ -766,7 +723,7 @@ export const deleteLocaleTranslation = async (session, sectionName, sectionItemI
|
|
|
766
723
|
};
|
|
767
724
|
}
|
|
768
725
|
const cmsConfig = await getCMSConfig();
|
|
769
|
-
if (!cmsConfig.localization?.enabled || !
|
|
726
|
+
if (!cmsConfig.localization?.enabled || !section.hasLocalizedFields) {
|
|
770
727
|
return {
|
|
771
728
|
error: {
|
|
772
729
|
message: getString('localizationNotEnabledForSection', session.user.language),
|
|
@@ -837,21 +794,11 @@ export const deleteLocaleTranslation = async (session, sectionName, sectionItemI
|
|
|
837
794
|
}
|
|
838
795
|
}
|
|
839
796
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
sectionItemId,
|
|
846
|
-
locale,
|
|
847
|
-
uploadsFolder: cmsConfig.media.upload.path,
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
// Delete locale-scoped editor photos for localized rich_text fields.
|
|
851
|
-
// Uses raw SQL because the `locale` column only exists on the DB table when
|
|
852
|
-
// localization is enabled; the Drizzle schema no longer declares it.
|
|
853
|
-
const [editorPhotoRows] = await db.execute(sql `SELECT \`photo\` as \`name\` FROM \`editor_photos\` WHERE \`section\` = ${sectionName} AND \`item_id\` = ${sectionItemId.toString()} AND \`locale\` = ${locale}`);
|
|
854
|
-
const editorPhotos = editorPhotoRows ?? [];
|
|
797
|
+
// Delete locale-scoped editor photos for localized rich_text fields
|
|
798
|
+
const editorPhotos = await db
|
|
799
|
+
.select()
|
|
800
|
+
.from(EditorPhotosTable)
|
|
801
|
+
.where(and(eq(EditorPhotosTable.section, sectionName), eq(EditorPhotosTable.itemId, sectionItemId.toString()), eq(EditorPhotosTable.locale, locale)));
|
|
855
802
|
if (editorPhotos.length > 0) {
|
|
856
803
|
const uploadsFolder = cmsConfig.media.upload.path;
|
|
857
804
|
for (const photo of editorPhotos) {
|
|
@@ -862,7 +809,9 @@ export const deleteLocaleTranslation = async (session, sectionName, sectionItemI
|
|
|
862
809
|
console.error('Error deleting editor photo', error);
|
|
863
810
|
}
|
|
864
811
|
}
|
|
865
|
-
await db
|
|
812
|
+
await db
|
|
813
|
+
.delete(EditorPhotosTable)
|
|
814
|
+
.where(and(eq(EditorPhotosTable.section, sectionName), eq(EditorPhotosTable.itemId, sectionItemId.toString()), eq(EditorPhotosTable.locale, locale)));
|
|
866
815
|
}
|
|
867
816
|
// Delete locale-scoped junction table rows for localized select/tags fields
|
|
868
817
|
const localizedJunctionFields = section.fieldConfigs.filter((f) => f.localized === true &&
|
|
@@ -993,19 +942,13 @@ export const createEditPage = async (session, sectionName, sectionItemId, locale
|
|
|
993
942
|
if (columns.includes(photoNameField) &&
|
|
994
943
|
columns.includes(referenceIdentifierField) &&
|
|
995
944
|
columns.includes(metaField)) {
|
|
996
|
-
const
|
|
997
|
-
const currentLocale = localeResult.resolvedLocale?.code;
|
|
998
|
-
const localeFilter = galleryIsLocalized && currentLocale && columns.includes('locale')
|
|
999
|
-
? sql ` AND \`locale\` = ${currentLocale}`
|
|
1000
|
-
: sql ``;
|
|
1001
|
-
const [items] = await db.execute(sql `select * from \`${sql.raw(tableName)}\` where \`${sql.raw(referenceIdentifierField)}\` = ${sectionItemId}${localeFilter}`);
|
|
945
|
+
const [items, fields] = await db.execute(sql `select * from \`${sql.raw(tableName)}\` where \`${sql.raw(referenceIdentifierField)}\` = ${sectionItemId}`);
|
|
1002
946
|
const galleryPhotos = items;
|
|
1003
947
|
galleryPhotos?.map((item) => {
|
|
1004
948
|
galleryItems.push({
|
|
1005
949
|
referenceId: item[referenceIdentifierField],
|
|
1006
950
|
photo: item[photoNameField],
|
|
1007
951
|
meta: item[metaField],
|
|
1008
|
-
locale: item.locale,
|
|
1009
952
|
});
|
|
1010
953
|
});
|
|
1011
954
|
}
|
|
@@ -1024,8 +967,7 @@ export const createEditPage = async (session, sectionName, sectionItemId, locale
|
|
|
1024
967
|
let localizationData = null;
|
|
1025
968
|
if (localeResult.localizationEnabled) {
|
|
1026
969
|
let existingTranslations = [];
|
|
1027
|
-
|
|
1028
|
-
if (hasLocalizedContent) {
|
|
970
|
+
if (sectionInfo.hasLocalizedFields) {
|
|
1029
971
|
const localesTableName = sectionInfo.localesTableName;
|
|
1030
972
|
const localeColumns = await MysqlTableChecker.getColumns(localesTableName);
|
|
1031
973
|
const localeTableExists = localeColumns.length > 0;
|
|
@@ -1071,9 +1013,6 @@ export const createEditPage = async (session, sectionName, sectionItemId, locale
|
|
|
1071
1013
|
: [];
|
|
1072
1014
|
field.setValue(tags.join(','));
|
|
1073
1015
|
}
|
|
1074
|
-
else if (field.type === 'date_range' && typeof f.setRangeValues === 'function') {
|
|
1075
|
-
f.setRangeValues(localeRow ? (localeRow[f.startName] ?? null) : null, localeRow ? (localeRow[f.endName] ?? null) : null);
|
|
1076
|
-
}
|
|
1077
1016
|
else {
|
|
1078
1017
|
// Simple field: override from locale row
|
|
1079
1018
|
field.setValue(localeRow ? (localeRow[field.name] ?? null) : null);
|
|
@@ -1082,22 +1021,11 @@ export const createEditPage = async (session, sectionName, sectionItemId, locale
|
|
|
1082
1021
|
}
|
|
1083
1022
|
}
|
|
1084
1023
|
}
|
|
1085
|
-
// Show the locale switcher when multiple locales are configured AND either:
|
|
1086
|
-
// - the section has localized fields (production case), or
|
|
1087
|
-
// - the app is in development mode (so devs can preview the switcher
|
|
1088
|
-
// while wiring up localization on a section).
|
|
1089
|
-
// The developer note is rendered in dev-mode only, when the switcher is
|
|
1090
|
-
// visible but the section itself has no localized content yet.
|
|
1091
|
-
const localeSwitcherEnabled = localeResult.availableLocales.length > 1 &&
|
|
1092
|
-
(hasLocalizedContent === true || process.env.NODE_ENV === 'development');
|
|
1093
|
-
const developerNoteEnabled = localeSwitcherEnabled && hasLocalizedContent === false;
|
|
1094
1024
|
localizationData = {
|
|
1095
1025
|
defaultLocale: localeResult.defaultLocale,
|
|
1096
1026
|
currentLocale: localeResult.resolvedLocale ?? localeResult.defaultLocale,
|
|
1097
1027
|
existingTranslations,
|
|
1098
1028
|
locales: localeResult.availableLocales,
|
|
1099
|
-
localeSwitcherEnabled,
|
|
1100
|
-
developerNoteEnabled,
|
|
1101
1029
|
};
|
|
1102
1030
|
}
|
|
1103
1031
|
return {
|