Skip to content

Commit 74dc1d7

Browse files
authored
Merge pull request #244 from pluginpal/feature/i18n
Feature/i18n
2 parents 95208ca + d2f52ac commit 74dc1d7

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

.changeset/funny-turkeys-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"strapi-plugin-webtools": patch
3+
---
4+
5+
fix: make the locale filter actually work by rewriting the URL params

.changeset/social-hands-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"strapi-plugin-webtools": patch
3+
---
4+
5+
fix: make sure the edit URL respects the alias locale

.changeset/wet-taxis-send.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"strapi-plugin-webtools": patch
3+
---
4+
5+
fix: actually return the localized entity in the router endpoint

packages/core/admin/hooks/useQueryParams.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from 'react';
2+
import qs from 'qs';
23
import { useLocation } from 'react-router-dom';
34

45
const useQueryParams = () => {
@@ -23,9 +24,22 @@ const useQueryParams = () => {
2324
searchParams.append('pagination[pageSize]', pageSize);
2425
}
2526

26-
setParams(searchParams.toString());
27-
}, [location]);
27+
const paramsObj = qs.parse(searchParams.toString());
28+
// @ts-expect-error
29+
const filters = paramsObj?.filters?.$and as Array<{ [key: string]: any }>;
30+
const localeFilterIndex = filters?.findIndex((filter) => filter.locale !== undefined);
31+
const localeFilter = filters?.[localeFilterIndex];
32+
33+
if (localeFilter) {
34+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
35+
paramsObj.locale = localeFilter.locale.$eq as string;
36+
filters.splice(localeFilterIndex, 1);
37+
// @ts-expect-error
38+
paramsObj.filters.$and = filters;
39+
}
2840

41+
setParams(qs.stringify(paramsObj));
42+
}, [location]);
2943

3044
return params;
3145
};

packages/core/server/controllers/url-alias.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ export default factories.createCoreController(contentTypeSlug, ({ strapi }) => (
2626
const contentTypeObj = strapi.contentTypes[contentType];
2727
const contentTypeUrlPartial = contentTypeObj.kind === 'singleType' ? 'single-types' : 'collection-types';
2828

29+
const model = strapi.getModel(contentType);
30+
// @ts-expect-error
31+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
32+
const isLocalized = model.pluginOptions.i18n?.localized as boolean;
33+
2934
ctx.body = {
30-
link: `/content-manager/${contentTypeUrlPartial}/${contentType}/${contentTypeObj.kind === 'collectionType' ? entity.documentId : ''}`,
35+
link: `/content-manager/${contentTypeUrlPartial}/${contentType}/${contentTypeObj.kind === 'collectionType' ? entity.documentId : ''}${isLocalized ? `?plugins[i18n][locale]=${entity.locale}` : ''}`,
3136
};
3237
},
3338
generate: async (

packages/core/server/services/url-alias.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ const customServices = () => ({
1616
}
1717

1818
const contentTypeUid = urlAliasEntity.contenttype as UID.ContentType;
19+
const model = strapi.getModel(contentTypeUid);
20+
// @ts-expect-error
21+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
22+
const isLocalized = model.pluginOptions.i18n?.localized as boolean;
1923

2024
const entity = await strapi.documents(contentTypeUid as 'api::test.test').findFirst({
2125
status: 'published',
2226
...query,
27+
...(isLocalized ? { locale: urlAliasEntity.locale } : {}),
2328
filters: {
2429
...query?.filters,
2530
url_alias: { documentId: urlAliasEntity.documentId },

0 commit comments

Comments
 (0)