@strapi/i18n 5.0.0-rc.9 → 5.0.0
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/dist/_chunks/{SettingsPage-CbEn7zF5.mjs → SettingsPage-DbRFoF_H.mjs} +4 -4
- package/dist/_chunks/SettingsPage-DbRFoF_H.mjs.map +1 -0
- package/dist/_chunks/{SettingsPage-C0l7c5fn.js → SettingsPage-uGJv15wR.js} +4 -4
- package/dist/_chunks/SettingsPage-uGJv15wR.js.map +1 -0
- package/dist/_chunks/{en-CM6Pjfyv.mjs → en-BYRZFDBV.mjs} +9 -2
- package/dist/_chunks/en-BYRZFDBV.mjs.map +1 -0
- package/dist/_chunks/{en-BsOU9o5z.js → en-Dk9At9_Z.js} +9 -2
- package/dist/_chunks/en-Dk9At9_Z.js.map +1 -0
- package/dist/_chunks/{index-CkrCiZyq.mjs → index-7_EUScSl.mjs} +390 -143
- package/dist/_chunks/index-7_EUScSl.mjs.map +1 -0
- package/dist/_chunks/{index-C0i3v7QQ.js → index-BGtXLYX-.js} +383 -136
- package/dist/_chunks/index-BGtXLYX-.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/BulkLocaleActionModal.d.ts +2 -1
- package/dist/admin/src/components/CMHeaderActions.d.ts +29 -3
- package/dist/admin/src/components/CreateLocale.d.ts +6 -6
- package/dist/admin/src/utils/clean.d.ts +4 -0
- package/dist/server/index.js +367 -486
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +368 -487
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts +1 -4
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +1 -11
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +0 -8
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +0 -2
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/_chunks/SettingsPage-C0l7c5fn.js.map +0 -1
- package/dist/_chunks/SettingsPage-CbEn7zF5.mjs.map +0 -1
- package/dist/_chunks/en-BsOU9o5z.js.map +0 -1
- package/dist/_chunks/en-CM6Pjfyv.mjs.map +0 -1
- package/dist/_chunks/index-C0i3v7QQ.js.map +0 -1
- package/dist/_chunks/index-CkrCiZyq.mjs.map +0 -1
- package/dist/server/src/migrations/content-type/disable/index.d.ts +0 -3
- package/dist/server/src/migrations/content-type/disable/index.d.ts.map +0 -1
- package/dist/server/src/migrations/content-type/enable/index.d.ts +0 -3
- package/dist/server/src/migrations/content-type/enable/index.d.ts.map +0 -1
- package/dist/server/src/services/entity-service-decorator.d.ts +0 -29
- package/dist/server/src/services/entity-service-decorator.d.ts.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.js
CHANGED
@@ -51,7 +51,7 @@ const registerModelsHooks = () => {
|
|
51
51
|
const attributesToPopulate = getNestedPopulateOfNonLocalizedAttributes2(schema2.uid);
|
52
52
|
const result = await next();
|
53
53
|
let resultID;
|
54
|
-
if (Array.isArray(result?.entries)) {
|
54
|
+
if (Array.isArray(result?.entries) && result.entries[0]?.id) {
|
55
55
|
resultID = result.entries[0].id;
|
56
56
|
} else if (result?.id) {
|
57
57
|
resultID = result.id;
|
@@ -65,12 +65,10 @@ const registerModelsHooks = () => {
|
|
65
65
|
return result;
|
66
66
|
});
|
67
67
|
};
|
68
|
-
const bootstrap = async (
|
68
|
+
const bootstrap = async () => {
|
69
69
|
const { sendDidInitializeEvent: sendDidInitializeEvent2 } = getService("metrics");
|
70
|
-
const { decorator: decorator2 } = getService("entity-service-decorator");
|
71
70
|
const { initDefaultLocale: initDefaultLocale2 } = getService("locales");
|
72
71
|
const { sectionsBuilder, actions: actions2, engine } = getService("permissions");
|
73
|
-
strapi2.entityService.decorate(decorator2);
|
74
72
|
await initDefaultLocale2();
|
75
73
|
sectionsBuilder.registerLocalesPropertyHandler();
|
76
74
|
await actions2.registerI18nActions();
|
@@ -197,6 +195,350 @@ const getI18nLocaleArgPlugin = ({ nexus, typeRegistry }) => {
|
|
197
195
|
}
|
198
196
|
});
|
199
197
|
};
|
198
|
+
const register = ({ strapi: strapi2 }) => {
|
199
|
+
extendContentTypes(strapi2);
|
200
|
+
addContentManagerLocaleMiddleware(strapi2);
|
201
|
+
};
|
202
|
+
const addContentManagerLocaleMiddleware = (strapi2) => {
|
203
|
+
strapi2.server.router.use("/content-manager/collection-types/:model", (ctx, next) => {
|
204
|
+
if (ctx.method === "POST" || ctx.method === "PUT") {
|
205
|
+
return validateLocaleCreation(ctx, next);
|
206
|
+
}
|
207
|
+
return next();
|
208
|
+
});
|
209
|
+
strapi2.server.router.use("/content-manager/single-types/:model", (ctx, next) => {
|
210
|
+
if (ctx.method === "POST" || ctx.method === "PUT") {
|
211
|
+
return validateLocaleCreation(ctx, next);
|
212
|
+
}
|
213
|
+
return next();
|
214
|
+
});
|
215
|
+
};
|
216
|
+
const extendContentTypes = (strapi2) => {
|
217
|
+
Object.values(strapi2.contentTypes).forEach((contentType) => {
|
218
|
+
const { attributes: attributes2 } = contentType;
|
219
|
+
___default.default.set(attributes2, "locale", {
|
220
|
+
writable: true,
|
221
|
+
private: false,
|
222
|
+
configurable: false,
|
223
|
+
visible: false,
|
224
|
+
type: "string"
|
225
|
+
});
|
226
|
+
___default.default.set(attributes2, "localizations", {
|
227
|
+
type: "relation",
|
228
|
+
relation: "oneToMany",
|
229
|
+
target: contentType.uid,
|
230
|
+
writable: false,
|
231
|
+
private: false,
|
232
|
+
configurable: false,
|
233
|
+
visible: false,
|
234
|
+
unstable_virtual: true,
|
235
|
+
joinColumn: {
|
236
|
+
name: "document_id",
|
237
|
+
referencedColumn: "document_id",
|
238
|
+
referencedTable: strapi2.db.metadata.identifiers.getTableName(contentType.collectionName),
|
239
|
+
// ensure the population will not include the results we already loaded
|
240
|
+
on({ results }) {
|
241
|
+
return {
|
242
|
+
id: {
|
243
|
+
$notIn: results.map((r) => r.id)
|
244
|
+
}
|
245
|
+
};
|
246
|
+
}
|
247
|
+
}
|
248
|
+
});
|
249
|
+
});
|
250
|
+
if (strapi2.plugin("graphql")) {
|
251
|
+
graphqlProvider({ strapi: strapi2 }).register();
|
252
|
+
}
|
253
|
+
};
|
254
|
+
const info = {
|
255
|
+
singularName: "locale",
|
256
|
+
pluralName: "locales",
|
257
|
+
collectionName: "locales",
|
258
|
+
displayName: "Locale",
|
259
|
+
description: ""
|
260
|
+
};
|
261
|
+
const options = {};
|
262
|
+
const pluginOptions = {
|
263
|
+
"content-manager": {
|
264
|
+
visible: false
|
265
|
+
},
|
266
|
+
"content-type-builder": {
|
267
|
+
visible: false
|
268
|
+
}
|
269
|
+
};
|
270
|
+
const attributes = {
|
271
|
+
name: {
|
272
|
+
type: "string",
|
273
|
+
min: 1,
|
274
|
+
max: 50,
|
275
|
+
configurable: false
|
276
|
+
},
|
277
|
+
code: {
|
278
|
+
type: "string",
|
279
|
+
unique: true,
|
280
|
+
configurable: false
|
281
|
+
}
|
282
|
+
};
|
283
|
+
const schema = {
|
284
|
+
info,
|
285
|
+
options,
|
286
|
+
pluginOptions,
|
287
|
+
attributes
|
288
|
+
};
|
289
|
+
const locale = {
|
290
|
+
schema
|
291
|
+
};
|
292
|
+
const contentTypes$1 = {
|
293
|
+
locale
|
294
|
+
};
|
295
|
+
const actions = [
|
296
|
+
{
|
297
|
+
section: "settings",
|
298
|
+
category: "Internationalization",
|
299
|
+
subCategory: "Locales",
|
300
|
+
pluginName: "i18n",
|
301
|
+
displayName: "Create",
|
302
|
+
uid: "locale.create"
|
303
|
+
},
|
304
|
+
{
|
305
|
+
section: "settings",
|
306
|
+
category: "Internationalization",
|
307
|
+
subCategory: "Locales",
|
308
|
+
pluginName: "i18n",
|
309
|
+
displayName: "Read",
|
310
|
+
uid: "locale.read",
|
311
|
+
aliases: [
|
312
|
+
{ actionId: "plugin::content-manager.explorer.read", subjects: ["plugin::i18n.locale"] }
|
313
|
+
]
|
314
|
+
},
|
315
|
+
{
|
316
|
+
section: "settings",
|
317
|
+
category: "Internationalization",
|
318
|
+
subCategory: "Locales",
|
319
|
+
pluginName: "i18n",
|
320
|
+
displayName: "Update",
|
321
|
+
uid: "locale.update"
|
322
|
+
},
|
323
|
+
{
|
324
|
+
section: "settings",
|
325
|
+
category: "Internationalization",
|
326
|
+
subCategory: "Locales",
|
327
|
+
pluginName: "i18n",
|
328
|
+
displayName: "Delete",
|
329
|
+
uid: "locale.delete"
|
330
|
+
}
|
331
|
+
];
|
332
|
+
const addLocalesPropertyIfNeeded = ({ value: action }) => {
|
333
|
+
const {
|
334
|
+
section,
|
335
|
+
options: { applyToProperties }
|
336
|
+
} = action;
|
337
|
+
if (section !== "contentTypes") {
|
338
|
+
return;
|
339
|
+
}
|
340
|
+
if (fp.isArray(applyToProperties) && applyToProperties.includes("locales")) {
|
341
|
+
return;
|
342
|
+
}
|
343
|
+
action.options.applyToProperties = fp.isArray(applyToProperties) ? applyToProperties.concat("locales") : ["locales"];
|
344
|
+
};
|
345
|
+
const shouldApplyLocalesPropertyToSubject = ({ property, subject }) => {
|
346
|
+
if (property === "locales") {
|
347
|
+
const model = strapi.getModel(subject);
|
348
|
+
return getService("content-types").isLocalizedContentType(model);
|
349
|
+
}
|
350
|
+
return true;
|
351
|
+
};
|
352
|
+
const addAllLocalesToPermissions = async (permissions2) => {
|
353
|
+
const { actionProvider } = strapi.service("admin::permission");
|
354
|
+
const { find: findAllLocales } = getService("locales");
|
355
|
+
const allLocales = await findAllLocales();
|
356
|
+
const allLocalesCode = allLocales.map(fp.prop("code"));
|
357
|
+
return Promise.all(
|
358
|
+
permissions2.map(async (permission) => {
|
359
|
+
const { action, subject } = permission;
|
360
|
+
const appliesToLocalesProperty = await actionProvider.appliesToProperty(
|
361
|
+
"locales",
|
362
|
+
action,
|
363
|
+
subject
|
364
|
+
);
|
365
|
+
if (!appliesToLocalesProperty) {
|
366
|
+
return permission;
|
367
|
+
}
|
368
|
+
const oldPermissionProperties = fp.getOr({}, "properties", permission);
|
369
|
+
return { ...permission, properties: { ...oldPermissionProperties, locales: allLocalesCode } };
|
370
|
+
})
|
371
|
+
);
|
372
|
+
};
|
373
|
+
const syncSuperAdminPermissionsWithLocales = async () => {
|
374
|
+
const roleService = strapi.service("admin::role");
|
375
|
+
const permissionService = strapi.service("admin::permission");
|
376
|
+
const superAdminRole = await roleService.getSuperAdmin();
|
377
|
+
if (!superAdminRole) {
|
378
|
+
return;
|
379
|
+
}
|
380
|
+
const superAdminPermissions = await permissionService.findMany({
|
381
|
+
where: {
|
382
|
+
role: {
|
383
|
+
id: superAdminRole.id
|
384
|
+
}
|
385
|
+
}
|
386
|
+
});
|
387
|
+
const newSuperAdminPermissions = await addAllLocalesToPermissions(superAdminPermissions);
|
388
|
+
await roleService.assignPermissions(superAdminRole.id, newSuperAdminPermissions);
|
389
|
+
};
|
390
|
+
const registerI18nActions = async () => {
|
391
|
+
const { actionProvider } = strapi.service("admin::permission");
|
392
|
+
await actionProvider.registerMany(actions);
|
393
|
+
};
|
394
|
+
const registerI18nActionsHooks = () => {
|
395
|
+
const { actionProvider } = strapi.service("admin::permission");
|
396
|
+
const { hooks } = strapi.service("admin::role");
|
397
|
+
actionProvider.hooks.appliesPropertyToSubject.register(shouldApplyLocalesPropertyToSubject);
|
398
|
+
hooks.willResetSuperAdminPermissions.register(addAllLocalesToPermissions);
|
399
|
+
};
|
400
|
+
const updateActionsProperties = () => {
|
401
|
+
const { actionProvider } = strapi.service("admin::permission");
|
402
|
+
actionProvider.hooks.willRegister.register(addLocalesPropertyIfNeeded);
|
403
|
+
actionProvider.values().forEach((action) => addLocalesPropertyIfNeeded({ value: action }));
|
404
|
+
};
|
405
|
+
const i18nActionsService = {
|
406
|
+
actions,
|
407
|
+
registerI18nActions,
|
408
|
+
registerI18nActionsHooks,
|
409
|
+
updateActionsProperties,
|
410
|
+
syncSuperAdminPermissionsWithLocales
|
411
|
+
};
|
412
|
+
const localesPropertyHandler = async ({ action, section }) => {
|
413
|
+
const { actionProvider } = strapi.service("admin::permission");
|
414
|
+
const locales2 = await getService("locales").find();
|
415
|
+
if (fp.isEmpty(locales2)) {
|
416
|
+
return;
|
417
|
+
}
|
418
|
+
for (const subject of section.subjects) {
|
419
|
+
const applies = await actionProvider.appliesToProperty("locales", action.actionId, subject.uid);
|
420
|
+
const hasLocalesProperty = subject.properties.find(
|
421
|
+
(property) => property.value === "locales"
|
422
|
+
);
|
423
|
+
if (applies && !hasLocalesProperty) {
|
424
|
+
subject.properties.push({
|
425
|
+
label: "Locales",
|
426
|
+
value: "locales",
|
427
|
+
children: locales2.map(({ name, code }) => ({ label: name || code, value: code }))
|
428
|
+
});
|
429
|
+
}
|
430
|
+
}
|
431
|
+
};
|
432
|
+
const registerLocalesPropertyHandler = () => {
|
433
|
+
const { sectionsBuilder } = strapi.service("admin::permission");
|
434
|
+
sectionsBuilder.addHandler("singleTypes", localesPropertyHandler);
|
435
|
+
sectionsBuilder.addHandler("collectionTypes", localesPropertyHandler);
|
436
|
+
};
|
437
|
+
const sectionsBuilderService = {
|
438
|
+
localesPropertyHandler,
|
439
|
+
registerLocalesPropertyHandler
|
440
|
+
};
|
441
|
+
const willRegisterPermission = (context) => {
|
442
|
+
const { permission, condition, user } = context;
|
443
|
+
const { subject, properties } = permission;
|
444
|
+
const isSuperAdmin = strapi.service("admin::role").hasSuperAdminRole(user);
|
445
|
+
if (isSuperAdmin) {
|
446
|
+
return;
|
447
|
+
}
|
448
|
+
const { locales: locales2 } = properties || {};
|
449
|
+
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
450
|
+
if (!subject) {
|
451
|
+
return;
|
452
|
+
}
|
453
|
+
const ct = strapi.contentTypes[subject];
|
454
|
+
if (!isLocalizedContentType2(ct)) {
|
455
|
+
return;
|
456
|
+
}
|
457
|
+
if (locales2 === null) {
|
458
|
+
return;
|
459
|
+
}
|
460
|
+
condition.and({
|
461
|
+
locale: {
|
462
|
+
$in: locales2 || []
|
463
|
+
}
|
464
|
+
});
|
465
|
+
};
|
466
|
+
const registerI18nPermissionsHandlers = () => {
|
467
|
+
const { engine } = strapi.service("admin::permission");
|
468
|
+
engine.hooks["before-register.permission"].register(willRegisterPermission);
|
469
|
+
};
|
470
|
+
const engineService = {
|
471
|
+
willRegisterPermission,
|
472
|
+
registerI18nPermissionsHandlers
|
473
|
+
};
|
474
|
+
const permissions = () => ({
|
475
|
+
actions: i18nActionsService,
|
476
|
+
sectionsBuilder: sectionsBuilderService,
|
477
|
+
engine: engineService
|
478
|
+
});
|
479
|
+
const sendDidInitializeEvent = async () => {
|
480
|
+
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
481
|
+
const numberOfContentTypes = fp.reduce(
|
482
|
+
(sum, contentType) => isLocalizedContentType2(contentType) ? sum + 1 : sum,
|
483
|
+
0
|
484
|
+
)(strapi.contentTypes);
|
485
|
+
await strapi.telemetry.send("didInitializeI18n", { groupProperties: { numberOfContentTypes } });
|
486
|
+
};
|
487
|
+
const sendDidUpdateI18nLocalesEvent = async () => {
|
488
|
+
const numberOfLocales = await getService("locales").count();
|
489
|
+
await strapi.telemetry.send("didUpdateI18nLocales", {
|
490
|
+
groupProperties: { numberOfLocales }
|
491
|
+
});
|
492
|
+
};
|
493
|
+
const metrics = () => ({
|
494
|
+
sendDidInitializeEvent,
|
495
|
+
sendDidUpdateI18nLocalesEvent
|
496
|
+
});
|
497
|
+
const syncNonLocalizedAttributes = async (sourceEntry, model) => {
|
498
|
+
const { copyNonLocalizedAttributes: copyNonLocalizedAttributes2 } = getService("content-types");
|
499
|
+
const nonLocalizedAttributes = copyNonLocalizedAttributes2(model, sourceEntry);
|
500
|
+
if (fp.isEmpty(nonLocalizedAttributes)) {
|
501
|
+
return;
|
502
|
+
}
|
503
|
+
const uid = model.uid;
|
504
|
+
const documentId = sourceEntry.documentId;
|
505
|
+
const locale2 = sourceEntry.locale;
|
506
|
+
const status = sourceEntry?.publishedAt ? "published" : "draft";
|
507
|
+
const localeEntriesToUpdate = await strapi.db.query(uid).findMany({
|
508
|
+
where: {
|
509
|
+
documentId,
|
510
|
+
publishedAt: status === "published" ? { $ne: null } : null,
|
511
|
+
locale: { $ne: locale2 }
|
512
|
+
},
|
513
|
+
select: ["locale", "id"]
|
514
|
+
});
|
515
|
+
const entryData = await strapi.documents(uid).omitComponentData(nonLocalizedAttributes);
|
516
|
+
await utils.async.map(localeEntriesToUpdate, async (entry) => {
|
517
|
+
const transformedData = await strapi.documents.utils.transformData(
|
518
|
+
fp.cloneDeep(nonLocalizedAttributes),
|
519
|
+
{
|
520
|
+
uid,
|
521
|
+
status,
|
522
|
+
locale: entry.locale,
|
523
|
+
allowMissingId: true
|
524
|
+
}
|
525
|
+
);
|
526
|
+
const componentData = await strapi.documents(uid).updateComponents(entry, transformedData);
|
527
|
+
await strapi.db.query(uid).update({
|
528
|
+
where: {
|
529
|
+
documentId,
|
530
|
+
publishedAt: status === "published" ? { $ne: null } : null,
|
531
|
+
locale: { $eq: entry.locale }
|
532
|
+
},
|
533
|
+
// The data we send to the update function is the entry data merged with
|
534
|
+
// the updated component data
|
535
|
+
data: Object.assign(fp.cloneDeep(entryData), componentData)
|
536
|
+
});
|
537
|
+
});
|
538
|
+
};
|
539
|
+
const localizations = () => ({
|
540
|
+
syncNonLocalizedAttributes
|
541
|
+
});
|
200
542
|
const isoLocales = [
|
201
543
|
{
|
202
544
|
code: "af",
|
@@ -2595,410 +2937,35 @@ const isoLocales = [
|
|
2595
2937
|
name: "Zarma (dje)"
|
2596
2938
|
},
|
2597
2939
|
{
|
2598
|
-
code: "dje-NE",
|
2599
|
-
name: "Zarma (Niger) (dje-NE)"
|
2600
|
-
},
|
2601
|
-
{
|
2602
|
-
code: "zu",
|
2603
|
-
name: "Zulu (zu)"
|
2604
|
-
},
|
2605
|
-
{
|
2606
|
-
code: "zu-ZA",
|
2607
|
-
name: "Zulu (South Africa) (zu-ZA)"
|
2608
|
-
}
|
2609
|
-
];
|
2610
|
-
const getInitLocale = () => {
|
2611
|
-
const envLocaleCode = process.env.STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE;
|
2612
|
-
if (envLocaleCode) {
|
2613
|
-
const matchingLocale = isoLocales.find(({ code }) => code === envLocaleCode);
|
2614
|
-
if (!matchingLocale) {
|
2615
|
-
throw new Error(
|
2616
|
-
"Unknown locale code provided in the environment variable STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE"
|
2617
|
-
);
|
2618
|
-
}
|
2619
|
-
return { ...matchingLocale };
|
2620
|
-
}
|
2621
|
-
return {
|
2622
|
-
code: "en",
|
2623
|
-
name: "English (en)"
|
2624
|
-
};
|
2625
|
-
};
|
2626
|
-
const DEFAULT_LOCALE = getInitLocale();
|
2627
|
-
const enableContentType = async ({ oldContentTypes, contentTypes: contentTypes2 }) => {
|
2628
|
-
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
2629
|
-
const { getDefaultLocale: getDefaultLocale2 } = getService("locales");
|
2630
|
-
if (!oldContentTypes) {
|
2631
|
-
return;
|
2632
|
-
}
|
2633
|
-
for (const uid in contentTypes2) {
|
2634
|
-
if (!oldContentTypes[uid]) {
|
2635
|
-
continue;
|
2636
|
-
}
|
2637
|
-
const oldContentType = oldContentTypes[uid];
|
2638
|
-
const contentType = contentTypes2[uid];
|
2639
|
-
if (!isLocalizedContentType2(oldContentType) && isLocalizedContentType2(contentType)) {
|
2640
|
-
const defaultLocale = await getDefaultLocale2() || DEFAULT_LOCALE.code;
|
2641
|
-
await strapi.db.query(uid).updateMany({
|
2642
|
-
where: { locale: null },
|
2643
|
-
data: { locale: defaultLocale }
|
2644
|
-
});
|
2645
|
-
}
|
2646
|
-
}
|
2647
|
-
};
|
2648
|
-
const disableContentType = async ({ oldContentTypes, contentTypes: contentTypes2 }) => {
|
2649
|
-
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
2650
|
-
const { getDefaultLocale: getDefaultLocale2 } = getService("locales");
|
2651
|
-
if (!oldContentTypes) {
|
2652
|
-
return;
|
2653
|
-
}
|
2654
|
-
for (const uid in contentTypes2) {
|
2655
|
-
if (!oldContentTypes[uid]) {
|
2656
|
-
continue;
|
2657
|
-
}
|
2658
|
-
const oldContentType = oldContentTypes[uid];
|
2659
|
-
const contentType = contentTypes2[uid];
|
2660
|
-
if (isLocalizedContentType2(oldContentType) && !isLocalizedContentType2(contentType)) {
|
2661
|
-
const defaultLocale = await getDefaultLocale2() || DEFAULT_LOCALE.code;
|
2662
|
-
await Promise.all([
|
2663
|
-
// Delete all entities that are not in the default locale
|
2664
|
-
strapi.db.query(uid).deleteMany({
|
2665
|
-
where: { locale: { $ne: defaultLocale } }
|
2666
|
-
}),
|
2667
|
-
// Set locale to null for the rest
|
2668
|
-
strapi.db.query(uid).updateMany({
|
2669
|
-
where: { locale: { $eq: defaultLocale } },
|
2670
|
-
data: { locale: null }
|
2671
|
-
})
|
2672
|
-
]);
|
2673
|
-
}
|
2674
|
-
}
|
2675
|
-
};
|
2676
|
-
const register = ({ strapi: strapi2 }) => {
|
2677
|
-
extendContentTypes(strapi2);
|
2678
|
-
addContentManagerLocaleMiddleware(strapi2);
|
2679
|
-
addContentTypeSyncHooks(strapi2);
|
2680
|
-
};
|
2681
|
-
const addContentManagerLocaleMiddleware = (strapi2) => {
|
2682
|
-
strapi2.server.router.use("/content-manager/collection-types/:model", (ctx, next) => {
|
2683
|
-
if (ctx.method === "POST" || ctx.method === "PUT") {
|
2684
|
-
return validateLocaleCreation(ctx, next);
|
2685
|
-
}
|
2686
|
-
return next();
|
2687
|
-
});
|
2688
|
-
strapi2.server.router.use("/content-manager/single-types/:model", (ctx, next) => {
|
2689
|
-
if (ctx.method === "POST" || ctx.method === "PUT") {
|
2690
|
-
return validateLocaleCreation(ctx, next);
|
2691
|
-
}
|
2692
|
-
return next();
|
2693
|
-
});
|
2694
|
-
};
|
2695
|
-
const addContentTypeSyncHooks = (strapi2) => {
|
2696
|
-
strapi2.hook("strapi::content-types.beforeSync").register(disableContentType);
|
2697
|
-
strapi2.hook("strapi::content-types.afterSync").register(enableContentType);
|
2698
|
-
};
|
2699
|
-
const extendContentTypes = (strapi2) => {
|
2700
|
-
Object.values(strapi2.contentTypes).forEach((contentType) => {
|
2701
|
-
const { attributes: attributes2 } = contentType;
|
2702
|
-
___default.default.set(attributes2, "locale", {
|
2703
|
-
writable: true,
|
2704
|
-
private: false,
|
2705
|
-
configurable: false,
|
2706
|
-
visible: false,
|
2707
|
-
type: "string"
|
2708
|
-
});
|
2709
|
-
});
|
2710
|
-
if (strapi2.plugin("graphql")) {
|
2711
|
-
graphqlProvider({ strapi: strapi2 }).register();
|
2712
|
-
}
|
2713
|
-
};
|
2714
|
-
const info = {
|
2715
|
-
singularName: "locale",
|
2716
|
-
pluralName: "locales",
|
2717
|
-
collectionName: "locales",
|
2718
|
-
displayName: "Locale",
|
2719
|
-
description: ""
|
2720
|
-
};
|
2721
|
-
const options = {};
|
2722
|
-
const pluginOptions = {
|
2723
|
-
"content-manager": {
|
2724
|
-
visible: false
|
2725
|
-
},
|
2726
|
-
"content-type-builder": {
|
2727
|
-
visible: false
|
2728
|
-
}
|
2729
|
-
};
|
2730
|
-
const attributes = {
|
2731
|
-
name: {
|
2732
|
-
type: "string",
|
2733
|
-
min: 1,
|
2734
|
-
max: 50,
|
2735
|
-
configurable: false
|
2736
|
-
},
|
2737
|
-
code: {
|
2738
|
-
type: "string",
|
2739
|
-
unique: true,
|
2740
|
-
configurable: false
|
2741
|
-
}
|
2742
|
-
};
|
2743
|
-
const schema = {
|
2744
|
-
info,
|
2745
|
-
options,
|
2746
|
-
pluginOptions,
|
2747
|
-
attributes
|
2748
|
-
};
|
2749
|
-
const locale = {
|
2750
|
-
schema
|
2751
|
-
};
|
2752
|
-
const contentTypes$1 = {
|
2753
|
-
locale
|
2754
|
-
};
|
2755
|
-
const actions = [
|
2756
|
-
{
|
2757
|
-
section: "settings",
|
2758
|
-
category: "Internationalization",
|
2759
|
-
subCategory: "Locales",
|
2760
|
-
pluginName: "i18n",
|
2761
|
-
displayName: "Create",
|
2762
|
-
uid: "locale.create"
|
2763
|
-
},
|
2764
|
-
{
|
2765
|
-
section: "settings",
|
2766
|
-
category: "Internationalization",
|
2767
|
-
subCategory: "Locales",
|
2768
|
-
pluginName: "i18n",
|
2769
|
-
displayName: "Read",
|
2770
|
-
uid: "locale.read",
|
2771
|
-
aliases: [
|
2772
|
-
{ actionId: "plugin::content-manager.explorer.read", subjects: ["plugin::i18n.locale"] }
|
2773
|
-
]
|
2774
|
-
},
|
2775
|
-
{
|
2776
|
-
section: "settings",
|
2777
|
-
category: "Internationalization",
|
2778
|
-
subCategory: "Locales",
|
2779
|
-
pluginName: "i18n",
|
2780
|
-
displayName: "Update",
|
2781
|
-
uid: "locale.update"
|
2940
|
+
code: "dje-NE",
|
2941
|
+
name: "Zarma (Niger) (dje-NE)"
|
2782
2942
|
},
|
2783
2943
|
{
|
2784
|
-
|
2785
|
-
|
2786
|
-
|
2787
|
-
|
2788
|
-
|
2789
|
-
|
2944
|
+
code: "zu",
|
2945
|
+
name: "Zulu (zu)"
|
2946
|
+
},
|
2947
|
+
{
|
2948
|
+
code: "zu-ZA",
|
2949
|
+
name: "Zulu (South Africa) (zu-ZA)"
|
2790
2950
|
}
|
2791
2951
|
];
|
2792
|
-
const
|
2793
|
-
const
|
2794
|
-
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
}
|
2800
|
-
if (fp.isArray(applyToProperties) && applyToProperties.includes("locales")) {
|
2801
|
-
return;
|
2802
|
-
}
|
2803
|
-
action.options.applyToProperties = fp.isArray(applyToProperties) ? applyToProperties.concat("locales") : ["locales"];
|
2804
|
-
};
|
2805
|
-
const shouldApplyLocalesPropertyToSubject = ({ property, subject }) => {
|
2806
|
-
if (property === "locales") {
|
2807
|
-
const model = strapi.getModel(subject);
|
2808
|
-
return getService("content-types").isLocalizedContentType(model);
|
2809
|
-
}
|
2810
|
-
return true;
|
2811
|
-
};
|
2812
|
-
const addAllLocalesToPermissions = async (permissions2) => {
|
2813
|
-
const { actionProvider } = strapi.service("admin::permission");
|
2814
|
-
const { find: findAllLocales } = getService("locales");
|
2815
|
-
const allLocales = await findAllLocales();
|
2816
|
-
const allLocalesCode = allLocales.map(fp.prop("code"));
|
2817
|
-
return Promise.all(
|
2818
|
-
permissions2.map(async (permission) => {
|
2819
|
-
const { action, subject } = permission;
|
2820
|
-
const appliesToLocalesProperty = await actionProvider.appliesToProperty(
|
2821
|
-
"locales",
|
2822
|
-
action,
|
2823
|
-
subject
|
2952
|
+
const getInitLocale = () => {
|
2953
|
+
const envLocaleCode = process.env.STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE;
|
2954
|
+
if (envLocaleCode) {
|
2955
|
+
const matchingLocale = isoLocales.find(({ code }) => code === envLocaleCode);
|
2956
|
+
if (!matchingLocale) {
|
2957
|
+
throw new Error(
|
2958
|
+
"Unknown locale code provided in the environment variable STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE"
|
2824
2959
|
);
|
2825
|
-
if (!appliesToLocalesProperty) {
|
2826
|
-
return permission;
|
2827
|
-
}
|
2828
|
-
const oldPermissionProperties = fp.getOr({}, "properties", permission);
|
2829
|
-
return { ...permission, properties: { ...oldPermissionProperties, locales: allLocalesCode } };
|
2830
|
-
})
|
2831
|
-
);
|
2832
|
-
};
|
2833
|
-
const syncSuperAdminPermissionsWithLocales = async () => {
|
2834
|
-
const roleService = strapi.service("admin::role");
|
2835
|
-
const permissionService = strapi.service("admin::permission");
|
2836
|
-
const superAdminRole = await roleService.getSuperAdmin();
|
2837
|
-
if (!superAdminRole) {
|
2838
|
-
return;
|
2839
|
-
}
|
2840
|
-
const superAdminPermissions = await permissionService.findMany({
|
2841
|
-
where: {
|
2842
|
-
role: {
|
2843
|
-
id: superAdminRole.id
|
2844
|
-
}
|
2845
|
-
}
|
2846
|
-
});
|
2847
|
-
const newSuperAdminPermissions = await addAllLocalesToPermissions(superAdminPermissions);
|
2848
|
-
await roleService.assignPermissions(superAdminRole.id, newSuperAdminPermissions);
|
2849
|
-
};
|
2850
|
-
const registerI18nActions = async () => {
|
2851
|
-
const { actionProvider } = strapi.service("admin::permission");
|
2852
|
-
await actionProvider.registerMany(actions);
|
2853
|
-
};
|
2854
|
-
const registerI18nActionsHooks = () => {
|
2855
|
-
const { actionProvider } = strapi.service("admin::permission");
|
2856
|
-
const { hooks } = strapi.service("admin::role");
|
2857
|
-
actionProvider.hooks.appliesPropertyToSubject.register(shouldApplyLocalesPropertyToSubject);
|
2858
|
-
hooks.willResetSuperAdminPermissions.register(addAllLocalesToPermissions);
|
2859
|
-
};
|
2860
|
-
const updateActionsProperties = () => {
|
2861
|
-
const { actionProvider } = strapi.service("admin::permission");
|
2862
|
-
actionProvider.hooks.willRegister.register(addLocalesPropertyIfNeeded);
|
2863
|
-
actionProvider.values().forEach((action) => addLocalesPropertyIfNeeded({ value: action }));
|
2864
|
-
};
|
2865
|
-
const i18nActionsService = {
|
2866
|
-
actions,
|
2867
|
-
registerI18nActions,
|
2868
|
-
registerI18nActionsHooks,
|
2869
|
-
updateActionsProperties,
|
2870
|
-
syncSuperAdminPermissionsWithLocales
|
2871
|
-
};
|
2872
|
-
const localesPropertyHandler = async ({ action, section }) => {
|
2873
|
-
const { actionProvider } = strapi.service("admin::permission");
|
2874
|
-
const locales2 = await getService("locales").find();
|
2875
|
-
if (fp.isEmpty(locales2)) {
|
2876
|
-
return;
|
2877
|
-
}
|
2878
|
-
for (const subject of section.subjects) {
|
2879
|
-
const applies = await actionProvider.appliesToProperty("locales", action.actionId, subject.uid);
|
2880
|
-
const hasLocalesProperty = subject.properties.find(
|
2881
|
-
(property) => property.value === "locales"
|
2882
|
-
);
|
2883
|
-
if (applies && !hasLocalesProperty) {
|
2884
|
-
subject.properties.push({
|
2885
|
-
label: "Locales",
|
2886
|
-
value: "locales",
|
2887
|
-
children: locales2.map(({ name, code }) => ({ label: name || code, value: code }))
|
2888
|
-
});
|
2889
|
-
}
|
2890
|
-
}
|
2891
|
-
};
|
2892
|
-
const registerLocalesPropertyHandler = () => {
|
2893
|
-
const { sectionsBuilder } = strapi.service("admin::permission");
|
2894
|
-
sectionsBuilder.addHandler("singleTypes", localesPropertyHandler);
|
2895
|
-
sectionsBuilder.addHandler("collectionTypes", localesPropertyHandler);
|
2896
|
-
};
|
2897
|
-
const sectionsBuilderService = {
|
2898
|
-
localesPropertyHandler,
|
2899
|
-
registerLocalesPropertyHandler
|
2900
|
-
};
|
2901
|
-
const willRegisterPermission = (context) => {
|
2902
|
-
const { permission, condition, user } = context;
|
2903
|
-
const { subject, properties } = permission;
|
2904
|
-
const isSuperAdmin = strapi.service("admin::role").hasSuperAdminRole(user);
|
2905
|
-
if (isSuperAdmin) {
|
2906
|
-
return;
|
2907
|
-
}
|
2908
|
-
const { locales: locales2 } = properties || {};
|
2909
|
-
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
2910
|
-
if (!subject) {
|
2911
|
-
return;
|
2912
|
-
}
|
2913
|
-
const ct = strapi.contentTypes[subject];
|
2914
|
-
if (!isLocalizedContentType2(ct)) {
|
2915
|
-
return;
|
2916
|
-
}
|
2917
|
-
if (locales2 === null) {
|
2918
|
-
return;
|
2919
|
-
}
|
2920
|
-
condition.and({
|
2921
|
-
locale: {
|
2922
|
-
$in: locales2 || []
|
2923
2960
|
}
|
2924
|
-
|
2925
|
-
};
|
2926
|
-
const registerI18nPermissionsHandlers = () => {
|
2927
|
-
const { engine } = strapi.service("admin::permission");
|
2928
|
-
engine.hooks["before-register.permission"].register(willRegisterPermission);
|
2929
|
-
};
|
2930
|
-
const engineService = {
|
2931
|
-
willRegisterPermission,
|
2932
|
-
registerI18nPermissionsHandlers
|
2933
|
-
};
|
2934
|
-
const permissions = () => ({
|
2935
|
-
actions: i18nActionsService,
|
2936
|
-
sectionsBuilder: sectionsBuilderService,
|
2937
|
-
engine: engineService
|
2938
|
-
});
|
2939
|
-
const sendDidInitializeEvent = async () => {
|
2940
|
-
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
2941
|
-
const numberOfContentTypes = fp.reduce(
|
2942
|
-
(sum, contentType) => isLocalizedContentType2(contentType) ? sum + 1 : sum,
|
2943
|
-
0
|
2944
|
-
)(strapi.contentTypes);
|
2945
|
-
await strapi.telemetry.send("didInitializeI18n", { groupProperties: { numberOfContentTypes } });
|
2946
|
-
};
|
2947
|
-
const sendDidUpdateI18nLocalesEvent = async () => {
|
2948
|
-
const numberOfLocales = await getService("locales").count();
|
2949
|
-
await strapi.telemetry.send("didUpdateI18nLocales", {
|
2950
|
-
groupProperties: { numberOfLocales }
|
2951
|
-
});
|
2952
|
-
};
|
2953
|
-
const metrics = () => ({
|
2954
|
-
sendDidInitializeEvent,
|
2955
|
-
sendDidUpdateI18nLocalesEvent
|
2956
|
-
});
|
2957
|
-
const syncNonLocalizedAttributes = async (sourceEntry, model) => {
|
2958
|
-
const { copyNonLocalizedAttributes: copyNonLocalizedAttributes2 } = getService("content-types");
|
2959
|
-
const nonLocalizedAttributes = copyNonLocalizedAttributes2(model, sourceEntry);
|
2960
|
-
if (fp.isEmpty(nonLocalizedAttributes)) {
|
2961
|
-
return;
|
2961
|
+
return { ...matchingLocale };
|
2962
2962
|
}
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
const localeEntriesToUpdate = await strapi.db.query(uid).findMany({
|
2968
|
-
where: {
|
2969
|
-
documentId,
|
2970
|
-
publishedAt: status === "published" ? { $ne: null } : null,
|
2971
|
-
locale: { $ne: locale2 }
|
2972
|
-
},
|
2973
|
-
select: ["locale", "id"]
|
2974
|
-
});
|
2975
|
-
const entryData = await strapi.documents(uid).omitComponentData(nonLocalizedAttributes);
|
2976
|
-
await utils.async.map(localeEntriesToUpdate, async (entry) => {
|
2977
|
-
const transformedData = await strapi.documents.utils.transformData(
|
2978
|
-
fp.cloneDeep(nonLocalizedAttributes),
|
2979
|
-
{
|
2980
|
-
uid,
|
2981
|
-
status,
|
2982
|
-
locale: entry.locale,
|
2983
|
-
allowMissingId: true
|
2984
|
-
}
|
2985
|
-
);
|
2986
|
-
const componentData = await strapi.documents(uid).updateComponents(entry, transformedData);
|
2987
|
-
await strapi.db.query(uid).update({
|
2988
|
-
where: {
|
2989
|
-
documentId,
|
2990
|
-
publishedAt: status === "published" ? { $ne: null } : null,
|
2991
|
-
locale: { $eq: entry.locale }
|
2992
|
-
},
|
2993
|
-
// The data we send to the update function is the entry data merged with
|
2994
|
-
// the updated component data
|
2995
|
-
data: Object.assign(fp.cloneDeep(entryData), componentData)
|
2996
|
-
});
|
2997
|
-
});
|
2963
|
+
return {
|
2964
|
+
code: "en",
|
2965
|
+
name: "English (en)"
|
2966
|
+
};
|
2998
2967
|
};
|
2999
|
-
const
|
3000
|
-
syncNonLocalizedAttributes
|
3001
|
-
});
|
2968
|
+
const DEFAULT_LOCALE = getInitLocale();
|
3002
2969
|
const find = (params = {}) => strapi.db.query("plugin::i18n.locale").findMany({ where: params });
|
3003
2970
|
const findById = (id) => strapi.db.query("plugin::i18n.locale").findOne({ where: { id } });
|
3004
2971
|
const findByCode = (code) => strapi.db.query("plugin::i18n.locale").findOne({ where: { code } });
|
@@ -3066,91 +3033,6 @@ const getIsoLocales = () => isoLocales;
|
|
3066
3033
|
const isoLocalesService = () => ({
|
3067
3034
|
getIsoLocales
|
3068
3035
|
});
|
3069
|
-
const LOCALE_QUERY_FILTER = "locale";
|
3070
|
-
const SINGLE_ENTRY_ACTIONS = ["findOne", "update", "delete"];
|
3071
|
-
const BULK_ACTIONS = ["delete"];
|
3072
|
-
const paramsContain = (key, params) => {
|
3073
|
-
return fp.has(key, params.filters) || fp.isArray(params.filters) && params.filters.some((clause) => fp.has(key, clause)) || fp.isArray(fp.get("$and", params.filters)) && params.filters.$and.some((clause) => fp.has(key, clause));
|
3074
|
-
};
|
3075
|
-
const wrapParams = async (params = {}, ctx = {}) => {
|
3076
|
-
const { action } = ctx;
|
3077
|
-
if (fp.has(LOCALE_QUERY_FILTER, params)) {
|
3078
|
-
if (params[LOCALE_QUERY_FILTER] === "all") {
|
3079
|
-
return fp.omit(LOCALE_QUERY_FILTER, params);
|
3080
|
-
}
|
3081
|
-
return {
|
3082
|
-
...fp.omit(LOCALE_QUERY_FILTER, params),
|
3083
|
-
filters: {
|
3084
|
-
$and: [{ locale: params[LOCALE_QUERY_FILTER] }].concat(params.filters || [])
|
3085
|
-
}
|
3086
|
-
};
|
3087
|
-
}
|
3088
|
-
const entityDefinedById = paramsContain("id", params) && SINGLE_ENTRY_ACTIONS.includes(action);
|
3089
|
-
const entitiesDefinedByIds = paramsContain("id.$in", params) && BULK_ACTIONS.includes(action);
|
3090
|
-
if (entityDefinedById || entitiesDefinedByIds) {
|
3091
|
-
return params;
|
3092
|
-
}
|
3093
|
-
const { getDefaultLocale: getDefaultLocale2 } = getService("locales");
|
3094
|
-
return {
|
3095
|
-
...params,
|
3096
|
-
filters: {
|
3097
|
-
$and: [{ locale: await getDefaultLocale2() }].concat(params.filters || [])
|
3098
|
-
}
|
3099
|
-
};
|
3100
|
-
};
|
3101
|
-
const decorator = (service) => ({
|
3102
|
-
/**
|
3103
|
-
* Wraps result
|
3104
|
-
* @param {object} result - result object of query
|
3105
|
-
* @param {object} ctx - Query context
|
3106
|
-
* @param {object} ctx.model - Model that is being used
|
3107
|
-
*/
|
3108
|
-
async wrapResult(result = {}, ctx = {}) {
|
3109
|
-
return service.wrapResult.call(this, result, ctx);
|
3110
|
-
},
|
3111
|
-
/**
|
3112
|
-
* Wraps query options. In particular will add default locale to query params
|
3113
|
-
* @param {object} params - Query options object (params, data, files, populate)
|
3114
|
-
* @param {object} ctx - Query context
|
3115
|
-
* @param {object} ctx.model - Model that is being used
|
3116
|
-
*/
|
3117
|
-
async wrapParams(params = {}, ctx = {}) {
|
3118
|
-
const wrappedParams = await service.wrapParams.call(this, params, ctx);
|
3119
|
-
const model = strapi.getModel(ctx.uid);
|
3120
|
-
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
3121
|
-
if (!isLocalizedContentType2(model)) {
|
3122
|
-
return wrappedParams;
|
3123
|
-
}
|
3124
|
-
return wrapParams(wrappedParams, ctx);
|
3125
|
-
},
|
3126
|
-
/**
|
3127
|
-
* Find an entry or several if fetching all locales
|
3128
|
-
* @param {string} uid - Model uid
|
3129
|
-
* @param {object} opts - Query options object (params, data, files, populate)
|
3130
|
-
*/
|
3131
|
-
async findMany(uid, opts) {
|
3132
|
-
const model = strapi.getModel(uid);
|
3133
|
-
const { isLocalizedContentType: isLocalizedContentType2 } = getService("content-types");
|
3134
|
-
if (!isLocalizedContentType2(model)) {
|
3135
|
-
return service.findMany.call(this, uid, opts);
|
3136
|
-
}
|
3137
|
-
const { kind } = model;
|
3138
|
-
if (kind === "singleType") {
|
3139
|
-
if (opts[LOCALE_QUERY_FILTER] === "all") {
|
3140
|
-
const wrappedParams = await this.wrapParams(opts, { uid, action: "findMany" });
|
3141
|
-
const query = strapi.get("query-params").transform(uid, wrappedParams);
|
3142
|
-
const entities = await strapi.db.query(uid).findMany(query);
|
3143
|
-
return this.wrapResult(entities, { uid, action: "findMany" });
|
3144
|
-
}
|
3145
|
-
return service.findMany.call(this, uid, opts);
|
3146
|
-
}
|
3147
|
-
return service.findMany.call(this, uid, opts);
|
3148
|
-
}
|
3149
|
-
});
|
3150
|
-
const entityServiceDecorator = () => ({
|
3151
|
-
decorator,
|
3152
|
-
wrapParams
|
3153
|
-
});
|
3154
3036
|
const {
|
3155
3037
|
isRelationalAttribute,
|
3156
3038
|
getVisibleAttributes,
|
@@ -3281,7 +3163,6 @@ const services = {
|
|
3281
3163
|
localizations,
|
3282
3164
|
locales,
|
3283
3165
|
"iso-locales": isoLocalesService,
|
3284
|
-
"entity-service-decorator": entityServiceDecorator,
|
3285
3166
|
"content-types": contentTypes
|
3286
3167
|
};
|
3287
3168
|
const admin = {
|