Skip to content

Commit daa9795

Browse files
authored
fix: Improve locale management, fix migration (#364)
!release
1 parent b4ed589 commit daa9795

29 files changed

+1077
-607
lines changed

apps/cms/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
"check-format": "prettier --check ."
1818
},
1919
"dependencies": {
20-
"@payloadcms/db-mongodb": "^3.48.0",
21-
"@payloadcms/email-resend": "^3.48.0",
22-
"@payloadcms/next": "^3.48.0",
23-
"@payloadcms/richtext-lexical": "^3.48.0",
24-
"@payloadcms/storage-s3": "^3.48.0",
25-
"@payloadcms/translations": "^3.48.0",
26-
"@payloadcms/ui": "^3.48.0",
20+
"@payloadcms/db-mongodb": "^3.49.0",
21+
"@payloadcms/email-resend": "^3.49.0",
22+
"@payloadcms/next": "^3.49.0",
23+
"@payloadcms/richtext-lexical": "^3.49.0",
24+
"@payloadcms/storage-s3": "^3.49.0",
25+
"@payloadcms/translations": "^3.49.0",
26+
"@payloadcms/ui": "^3.49.0",
2727
"bson": "^6.10.4",
2828
"cookie": "^1.0.2",
2929
"cross-env": "^7.0.3",
3030
"deepl-node": "^1.19.0",
3131
"jsdom": "^26.1.0",
32-
"next": "^15.4.2",
32+
"next": "^15.4.4",
3333
"openai": "^4.104.0",
34-
"payload": "^3.48.0",
34+
"payload": "^3.49.0",
3535
"react": "^19.1.0",
3636
"react-dom": "^19.1.0",
3737
"sharp": "^0.34.3"
@@ -44,8 +44,8 @@
4444
"@types/node": "^22.16.5",
4545
"@types/react": "^19.1.8",
4646
"@types/react-dom": "^19.1.6",
47-
"eslint": "^9.31.0",
48-
"eslint-config-next": "^15.4.2",
47+
"eslint": "^9.32.0",
48+
"eslint-config-next": "^15.4.4",
4949
"postcss": "^8.5.6",
5050
"prettier": "3.5.3",
5151
"prettier-plugin-tailwindcss": "^0.6.14",
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { adminGroup } from "@/groups";
2+
import { CollectionConfig } from "payload";
3+
import locales from "@/common/locales.json";
4+
import {
5+
deeplSourceLanguageCodes,
6+
deeplTargetLanguage as deeplTargetLanguageCodes,
7+
} from "@/common/translation";
8+
import { googleMapLanguageCodes } from "./google-maps-language-codes";
9+
10+
export const LocaleConfigs: CollectionConfig = {
11+
slug: "locale-configs",
12+
labels: {
13+
singular: {
14+
en: "Locale Configuration",
15+
es: "Configuración de Idioma",
16+
},
17+
plural: {
18+
en: "Locale Configurations",
19+
es: "Configuraciones de Idioma",
20+
},
21+
},
22+
defaultSort: "displayLabel",
23+
defaultPopulate: {
24+
displayLabel: true,
25+
googleMapsLanguage: true,
26+
},
27+
admin: {
28+
useAsTitle: "locale",
29+
group: adminGroup,
30+
listSearchableFields: ["locale", "displayLabel"],
31+
defaultColumns: ["locale", "displayLabel"],
32+
},
33+
hooks: {
34+
beforeChange: [
35+
({ data }) => {
36+
data.id = data.locale;
37+
},
38+
],
39+
},
40+
fields: [
41+
{
42+
name: "id",
43+
label: {
44+
en: "ID",
45+
es: "ID",
46+
},
47+
type: "text",
48+
admin: {
49+
hidden: true,
50+
},
51+
},
52+
{
53+
name: "locale",
54+
label: {
55+
en: "Locale",
56+
es: "Idioma",
57+
},
58+
type: "select",
59+
options: locales
60+
.toSorted((a, b) => a.code.localeCompare(b.code))
61+
.map((locale) => ({
62+
label: Object.fromEntries(
63+
Object.entries(locale.label).map(([key, value]) => [
64+
key,
65+
`${value} (${locale.code})`,
66+
]),
67+
),
68+
value: locale.code,
69+
})),
70+
required: true,
71+
access: {
72+
update: () => false,
73+
},
74+
},
75+
{
76+
name: "displayLabel",
77+
label: {
78+
en: "Display Label",
79+
es: "Etiqueta de Visualización",
80+
},
81+
type: "text",
82+
required: true,
83+
admin: {
84+
description: {
85+
en: "The label to be displayed in the application. This should be the name in the respective language so that it can be easily recognized by speakers of that language. E.g. 'English' for English, 'Español' for Spanish.",
86+
es: "La etiqueta que se mostrará en la aplicación. Debe ser el nombre en el idioma respectivo para que pueda ser fácilmente reconocido por los hablantes de ese idioma. Por ejemplo, 'English' para inglés, 'Español' para español.",
87+
},
88+
},
89+
},
90+
{
91+
name: "deeplSourceLanguage",
92+
label: {
93+
en: "DeepL Source Language",
94+
es: "Idioma de Origen DeepL",
95+
},
96+
type: "select",
97+
options: deeplSourceLanguageCodes
98+
.toSorted((a, b) => a.localeCompare(b))
99+
.map((languageCode) => ({
100+
label: Object.fromEntries(
101+
Object.entries(
102+
locales.find((l) => l.code === languageCode)!.label,
103+
).map(([key, value]) => [key, `${value} (${languageCode})`]),
104+
),
105+
value: languageCode,
106+
})),
107+
},
108+
{
109+
name: "deeplTargetLanguage",
110+
label: {
111+
en: "DeepL Target Language",
112+
es: "Idioma de Destino DeepL",
113+
},
114+
type: "select",
115+
options: deeplTargetLanguageCodes
116+
.toSorted((a, b) => a.localeCompare(b))
117+
.map((languageCode) => ({
118+
label: Object.fromEntries(
119+
Object.entries(
120+
locales.find((l) => l.code === languageCode)!.label,
121+
).map(([key, value]) => [key, `${value} (${languageCode})`]),
122+
),
123+
value: languageCode,
124+
})),
125+
},
126+
{
127+
name: "googleMapsLanguage",
128+
label: {
129+
en: "Google Maps Language",
130+
es: "Idioma de Google Maps",
131+
},
132+
type: "select",
133+
134+
options: googleMapLanguageCodes
135+
.toSorted((a, b) => a.localeCompare(b))
136+
.map((languageCode) => ({
137+
label: Object.fromEntries(
138+
Object.entries(
139+
locales.find((l) => l.code === languageCode)!.label,
140+
).map(([key, value]) => [key, `${value} (${languageCode})`]),
141+
),
142+
value: languageCode,
143+
})),
144+
},
145+
],
146+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
export const googleMapLanguageCodes = [
2+
"af",
3+
"am",
4+
"ar",
5+
"hy",
6+
"az",
7+
"bn",
8+
"bg",
9+
"my",
10+
"zh",
11+
"zh-CN",
12+
"zh-HK",
13+
"zh-TW",
14+
"hr",
15+
"cs",
16+
"da",
17+
"nl",
18+
"en",
19+
"en-AU",
20+
"en-GB",
21+
"et",
22+
"fa",
23+
"fi",
24+
"fr",
25+
"fr-CA",
26+
"ka",
27+
"de",
28+
"el",
29+
"gu",
30+
"hi",
31+
"hu",
32+
"id",
33+
"it",
34+
"ja",
35+
"kk",
36+
"km",
37+
"ko",
38+
"lo",
39+
"lv",
40+
"lt",
41+
"ms",
42+
"ml",
43+
"mr",
44+
"mn",
45+
"ne",
46+
"no",
47+
"pl",
48+
"pt",
49+
"pt-BR",
50+
"pt-PT",
51+
"pa",
52+
"ro",
53+
"ru",
54+
"sr",
55+
"si",
56+
"sk",
57+
"sl",
58+
"es",
59+
"es-419",
60+
"sw",
61+
"sv",
62+
"ta",
63+
"te",
64+
"th",
65+
"tr",
66+
"uk",
67+
"ur",
68+
"uz",
69+
"vi",
70+
];

apps/cms/src/collections/locales/config.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

apps/cms/src/collections/pages/localized-pathname.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Locale } from "@/payload-types";
1+
import { LocaleConfig } from "@/payload-types";
22
import { addLocalesToRequestFromData, Endpoint, PayloadRequest } from "payload";
33

44
export const getLocalizedPathnameEndpoint: Endpoint = {
@@ -60,9 +60,11 @@ export async function getPagesForPathname(
6060
const result = await req.payload.find({
6161
collection: "pages",
6262
where: {
63-
or: (settings.publishedLocales.publishedLocales as Locale[]).map((l) => ({
64-
[`pathname.${l.locale}`]: { equals: pathnameToFind },
65-
})),
63+
or: (settings.publishedLocales.publishedLocales as LocaleConfig[]).map(
64+
(l) => ({
65+
[`pathname.${l.id}`]: { equals: pathnameToFind },
66+
}),
67+
),
6668
},
6769
req,
6870
limit: 1,

0 commit comments

Comments
 (0)