nextjs-cms 0.5.99 → 0.5.101
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/api/index.d.ts +42 -4
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/lib/serverActions.d.ts +5 -5
- package/dist/api/lib/serverActions.d.ts.map +1 -1
- package/dist/api/lib/serverActions.js +60 -13
- package/dist/api/root.d.ts +84 -8
- package/dist/api/root.d.ts.map +1 -1
- package/dist/api/root.js +2 -0
- package/dist/api/routers/accountSettings.d.ts +7 -0
- package/dist/api/routers/accountSettings.d.ts.map +1 -1
- package/dist/api/routers/accountSettings.js +32 -0
- package/dist/api/routers/admins.js +2 -2
- package/dist/api/routers/categorySection.d.ts +1 -1
- package/dist/api/routers/config.d.ts +35 -0
- package/dist/api/routers/config.d.ts.map +1 -0
- package/dist/api/routers/config.js +14 -0
- package/dist/api/routers/hasItemsSection.d.ts +2 -2
- package/dist/api/routers/simpleSection.d.ts +1 -1
- package/dist/auth/lib/actions.d.ts +2 -1
- package/dist/auth/lib/actions.d.ts.map +1 -1
- package/dist/auth/lib/actions.js +19 -8
- package/dist/auth/react.d.ts +2 -1
- package/dist/auth/react.d.ts.map +1 -1
- package/dist/auth/react.js +5 -2
- package/dist/core/config/config-loader.d.ts +17 -0
- package/dist/core/config/config-loader.d.ts.map +1 -1
- package/dist/core/config/config-loader.js +54 -0
- package/dist/core/config/index.d.ts +3 -2
- package/dist/core/config/index.d.ts.map +1 -1
- package/dist/core/config/index.js +1 -1
- package/dist/core/config/loader-with-jiti.d.ts.map +1 -1
- package/dist/core/config/loader-with-jiti.js +11 -0
- package/dist/core/factories/FieldFactory.d.ts +10 -3
- package/dist/core/factories/FieldFactory.d.ts.map +1 -1
- package/dist/core/factories/FieldFactory.js +28 -2
- package/dist/core/fields/checkbox.d.ts +3 -3
- package/dist/core/fields/color.d.ts +3 -3
- package/dist/core/fields/date.d.ts +3 -3
- package/dist/core/fields/document.d.ts +3 -3
- package/dist/core/fields/field.d.ts +4 -3
- package/dist/core/fields/field.d.ts.map +1 -1
- package/dist/core/fields/field.js +7 -1
- package/dist/core/fields/map.d.ts +3 -3
- package/dist/core/fields/number.d.ts +5 -5
- package/dist/core/fields/password.d.ts +3 -3
- package/dist/core/fields/photo.d.ts +3 -3
- package/dist/core/fields/richText.d.ts +5 -5
- package/dist/core/fields/select.d.ts +7 -7
- package/dist/core/fields/selectMultiple.d.ts +4 -4
- package/dist/core/fields/tags.d.ts +3 -3
- package/dist/core/fields/text.d.ts +3 -3
- package/dist/core/fields/textArea.d.ts +3 -3
- package/dist/core/fields/video.d.ts +3 -3
- package/dist/core/helpers/i18n.d.ts +2 -0
- package/dist/core/helpers/i18n.d.ts.map +1 -0
- package/dist/core/helpers/i18n.js +3 -0
- package/dist/core/localization.d.ts +40 -0
- package/dist/core/localization.d.ts.map +1 -0
- package/dist/core/localization.js +48 -0
- package/dist/core/sections/category.d.ts +21 -20
- package/dist/core/sections/category.d.ts.map +1 -1
- package/dist/core/sections/category.js +10 -3
- package/dist/core/sections/hasItems.d.ts +39 -38
- package/dist/core/sections/hasItems.d.ts.map +1 -1
- package/dist/core/sections/hasItems.js +10 -3
- package/dist/core/sections/section.d.ts +1 -1
- package/dist/core/sections/simple.d.ts +7 -6
- package/dist/core/sections/simple.d.ts.map +1 -1
- package/dist/core/sections/simple.js +4 -1
- package/dist/translations/client.d.ts +1 -1
- package/dist/translations/client.d.ts.map +1 -1
- package/dist/translations/client.js +1 -1
- package/dist/translations/dict-store.d.ts +12 -0
- package/dist/translations/dict-store.d.ts.map +1 -0
- package/dist/translations/dict-store.js +21 -0
- package/dist/translations/dictionaries/ar.d.ts +2 -0
- package/dist/translations/dictionaries/ar.d.ts.map +1 -1
- package/dist/translations/dictionaries/ar.js +2 -0
- package/dist/translations/dictionaries/en.d.ts +2 -0
- package/dist/translations/dictionaries/en.d.ts.map +1 -1
- package/dist/translations/dictionaries/en.js +2 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.d.ts.map +1 -1
- package/dist/translations/index.js +12 -6
- package/dist/translations/locale-cookie.d.ts +11 -0
- package/dist/translations/locale-cookie.d.ts.map +1 -0
- package/dist/translations/locale-cookie.js +15 -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/translations/localized-string.d.ts +17 -0
- package/dist/translations/localized-string.d.ts.map +1 -0
- package/dist/translations/localized-string.js +32 -0
- package/dist/translations/types.d.ts +6 -0
- package/dist/translations/types.d.ts.map +1 -0
- package/dist/translations/types.js +0 -0
- package/dist/translations/use-project-translation.d.ts +19 -0
- package/dist/translations/use-project-translation.d.ts.map +1 -0
- package/dist/translations/use-project-translation.js +25 -0
- package/package.json +9 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { entityKind } from '../helpers/index.js';
|
|
2
2
|
import type { ConditionalField, ConditionalRule, FieldType } from '../types/index.js';
|
|
3
|
+
import type { LocalizedString } from '../../translations/localization.js';
|
|
3
4
|
import * as z from 'zod';
|
|
4
5
|
/**
|
|
5
6
|
* The Field class is used in the submit class to handle submission of the field
|
|
@@ -9,7 +10,7 @@ export declare abstract class Field<TType extends FieldType = FieldType, TExtraF
|
|
|
9
10
|
static readonly [entityKind]: string;
|
|
10
11
|
readonly type: TType;
|
|
11
12
|
readonly name: string;
|
|
12
|
-
readonly label:
|
|
13
|
+
readonly label: LocalizedString;
|
|
13
14
|
readonly required: boolean;
|
|
14
15
|
/**
|
|
15
16
|
* The default value of the field in the DB table,
|
|
@@ -71,7 +72,7 @@ export declare abstract class Field<TType extends FieldType = FieldType, TExtraF
|
|
|
71
72
|
exportForClient(): {
|
|
72
73
|
type: TType;
|
|
73
74
|
name: string;
|
|
74
|
-
label:
|
|
75
|
+
label: LocalizedString;
|
|
75
76
|
required: boolean;
|
|
76
77
|
conditionalFields: ConditionalField[];
|
|
77
78
|
readonly: boolean;
|
|
@@ -93,7 +94,7 @@ export declare const conditionalRuleSchema: z.ZodCustom<ConditionalRule, Conditi
|
|
|
93
94
|
*/
|
|
94
95
|
export declare const baseFieldConfigSchema: z.ZodObject<{
|
|
95
96
|
name: z.ZodString;
|
|
96
|
-
label: z.ZodOptional<z.ZodString
|
|
97
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
97
98
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
98
99
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
99
100
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/core/fields/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB;;;GAGG;AACH,8BAAsB,KAAK,CAEvB,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,iBAAiB,SAAS,MAAM,GAAG,MAAM,CAC3C,YAAW,QAAQ,CAAC,KAAK,CAAC;IAExB,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,MAAM,CAAU;IAC9C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/core/fields/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB;;;GAGG;AACH,8BAAsB,KAAK,CAEvB,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,iBAAiB,SAAS,MAAM,GAAG,MAAM,CAC3C,YAAW,QAAQ,CAAC,KAAK,CAAC;IAExB,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,MAAM,CAAU;IAC9C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;IAC/B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,gBAAgB,EAAE,eAAe,EAAE,GAAG,SAAS,CAAA;IAExD;;;;OAIG;IACH,cAAc,CAAC,EAAE,IAAI,GAAG,KAAK,GAAG,UAAU,CAAA;IAE1C;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE;QACrB,KAAK,EAAE,MAAM,CAAA;QACb,cAAc,EAAE,MAAM,CAAA;QACtB,gBAAgB,EAAE,MAAM,CAAA;KAC3B,CAAA;IAED;;OAEG;IACI,iBAAiB,EAAE,gBAAgB,EAAE,CAAK;IACnC,KAAK,EAAE,GAAG,CAAA;gBAKZ,MAAM,EAAE,eAAe,CAAC,iBAAiB,CAAC,EAAE,SAAS,EAAE,KAAK;IAaxE,QAAQ,CAAC,aAAa,IAAI,IAAI;IAE9B,QAAQ,CAAC,KAAK,EAAE,GAAG;IAInB;;OAEG;IACU,UAAU,CAAC,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhD;;OAEG;IACH,QAAQ,CAAC,QAAQ,IAAI,GAAG;IAExB,cAAc,IAAI,GAAG;IAIrB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9C;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAY1C,eAAe;;;;;;;;;;IAef,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,aAAa,IAAI,OAAO;CAa3B;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAGpE,eAAO,MAAM,qBAAqB,+CAA8B,CAAA;AAEhE;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;;;;;IAW9B;;;;OAIG;;IAEH;;;;OAIG;;kBAEL,CAAA;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,iBAAiB,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAC1G,iBAAiB,CAAA;AAErB;;GAEG;AACH,UAAU,QAAQ,CAAC,KAAK,SAAS,SAAS,CAAE,SAAQ,eAAe,CAAC,EAAE,CAAC;IACnE,IAAI,EAAE,KAAK,CAAA;CACd"}
|
|
@@ -45,6 +45,7 @@ export class Field {
|
|
|
45
45
|
constructor(config, fieldType) {
|
|
46
46
|
this.type = fieldType;
|
|
47
47
|
this.name = config.name;
|
|
48
|
+
// Store the raw label (can be string or localized object)
|
|
48
49
|
this.label = config.label ?? Field.generateLabel(config.name);
|
|
49
50
|
this.required = config.required ?? false;
|
|
50
51
|
this.defaultValue = config.defaultValue;
|
|
@@ -88,6 +89,8 @@ export class Field {
|
|
|
88
89
|
.replace(/\b\w/g, (char) => char.toUpperCase()));
|
|
89
90
|
}
|
|
90
91
|
exportForClient() {
|
|
92
|
+
// Export the raw label (can be string or localized object)
|
|
93
|
+
// Client components will resolve it based on current locale
|
|
91
94
|
return {
|
|
92
95
|
type: this.type,
|
|
93
96
|
name: this.name,
|
|
@@ -129,7 +132,10 @@ export const conditionalRuleSchema = z.custom();
|
|
|
129
132
|
*/
|
|
130
133
|
export const baseFieldConfigSchema = z.strictObject({
|
|
131
134
|
name: z.string().describe('The name of the field'),
|
|
132
|
-
label: z
|
|
135
|
+
label: z
|
|
136
|
+
.union([z.string(), z.record(z.string(), z.string())])
|
|
137
|
+
.optional()
|
|
138
|
+
.describe('The label of the field. Can be a string or an object with language codes as keys (e.g., { en: "Title", ar: "العنوان" })'),
|
|
133
139
|
required: z.boolean().optional().describe('Whether the field is required'),
|
|
134
140
|
defaultValue: z.any().optional().describe('The default value of the field'),
|
|
135
141
|
order: z.number().optional().describe('The order of the field'),
|
|
@@ -72,7 +72,7 @@ export declare class MapField extends Field<'map', Config> {
|
|
|
72
72
|
} | undefined;
|
|
73
73
|
type: "map";
|
|
74
74
|
name: string;
|
|
75
|
-
label:
|
|
75
|
+
label: import("../../index.js").LocalizedString;
|
|
76
76
|
required: boolean;
|
|
77
77
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
78
78
|
readonly: boolean;
|
|
@@ -114,7 +114,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
114
114
|
east: z.ZodNumber;
|
|
115
115
|
}, z.core.$strict>>;
|
|
116
116
|
name: z.ZodString;
|
|
117
|
-
label: z.ZodOptional<z.ZodString
|
|
117
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
118
118
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
119
119
|
order: z.ZodOptional<z.ZodNumber>;
|
|
120
120
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -145,7 +145,7 @@ declare const mapFieldConfigSchema: z.ZodObject<{
|
|
|
145
145
|
east: z.ZodNumber;
|
|
146
146
|
}, z.core.$strict>>;
|
|
147
147
|
name: z.ZodString;
|
|
148
|
-
label: z.ZodOptional<z.ZodString
|
|
148
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
149
149
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
150
150
|
order: z.ZodOptional<z.ZodNumber>;
|
|
151
151
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -59,7 +59,7 @@ export declare class NumberField extends Field<'number', Config> {
|
|
|
59
59
|
maxLength: number | undefined;
|
|
60
60
|
type: "number";
|
|
61
61
|
name: string;
|
|
62
|
-
label:
|
|
62
|
+
label: import("../../index.js").LocalizedString;
|
|
63
63
|
required: boolean;
|
|
64
64
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
65
65
|
readonly: boolean;
|
|
@@ -90,7 +90,7 @@ declare const optionsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
90
90
|
maxLength: z.ZodOptional<z.ZodNever>;
|
|
91
91
|
defaultValue: z.ZodOptional<z.ZodNever>;
|
|
92
92
|
name: z.ZodString;
|
|
93
|
-
label: z.ZodOptional<z.ZodString
|
|
93
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
94
94
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
95
95
|
order: z.ZodOptional<z.ZodNumber>;
|
|
96
96
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -114,7 +114,7 @@ declare const optionsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
114
114
|
*/
|
|
115
115
|
defaultValue: z.ZodOptional<z.ZodNumber>;
|
|
116
116
|
name: z.ZodString;
|
|
117
|
-
label: z.ZodOptional<z.ZodString
|
|
117
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
118
118
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
119
119
|
order: z.ZodOptional<z.ZodNumber>;
|
|
120
120
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -131,7 +131,7 @@ declare const numberFieldConfigSchema: z.ZodIntersection<z.ZodDiscriminatedUnion
|
|
|
131
131
|
maxLength: z.ZodOptional<z.ZodNever>;
|
|
132
132
|
defaultValue: z.ZodOptional<z.ZodNever>;
|
|
133
133
|
name: z.ZodString;
|
|
134
|
-
label: z.ZodOptional<z.ZodString
|
|
134
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
135
135
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
136
136
|
order: z.ZodOptional<z.ZodNumber>;
|
|
137
137
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -155,7 +155,7 @@ declare const numberFieldConfigSchema: z.ZodIntersection<z.ZodDiscriminatedUnion
|
|
|
155
155
|
*/
|
|
156
156
|
defaultValue: z.ZodOptional<z.ZodNumber>;
|
|
157
157
|
name: z.ZodString;
|
|
158
|
-
label: z.ZodOptional<z.ZodString
|
|
158
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
159
159
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
160
160
|
order: z.ZodOptional<z.ZodNumber>;
|
|
161
161
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -39,7 +39,7 @@ export declare class PasswordField extends Field<'password', Config> {
|
|
|
39
39
|
} | undefined;
|
|
40
40
|
type: "password";
|
|
41
41
|
name: string;
|
|
42
|
-
label:
|
|
42
|
+
label: import("../../index.js").LocalizedString;
|
|
43
43
|
required: boolean;
|
|
44
44
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
45
45
|
readonly: boolean;
|
|
@@ -67,7 +67,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
67
67
|
message: z.ZodString;
|
|
68
68
|
}, z.core.$strict>>;
|
|
69
69
|
name: z.ZodString;
|
|
70
|
-
label: z.ZodOptional<z.ZodString
|
|
70
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
71
71
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
72
72
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
73
73
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -86,7 +86,7 @@ declare const configSchema: z.ZodObject<{
|
|
|
86
86
|
message: z.ZodString;
|
|
87
87
|
}, z.core.$strict>>;
|
|
88
88
|
name: z.ZodString;
|
|
89
|
-
label: z.ZodOptional<z.ZodString
|
|
89
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
90
90
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
91
91
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
92
92
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -121,7 +121,7 @@ export declare class PhotoField extends FileField<'photo', Config> {
|
|
|
121
121
|
mimeType: string[];
|
|
122
122
|
type: "photo";
|
|
123
123
|
name: string;
|
|
124
|
-
label:
|
|
124
|
+
label: import("../../index.js").LocalizedString;
|
|
125
125
|
required: boolean;
|
|
126
126
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
127
127
|
readonly: boolean;
|
|
@@ -212,7 +212,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
212
212
|
*/
|
|
213
213
|
removeExtension: z.ZodOptional<z.ZodBoolean>;
|
|
214
214
|
name: z.ZodString;
|
|
215
|
-
label: z.ZodOptional<z.ZodString
|
|
215
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
216
216
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
217
217
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
218
218
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -284,7 +284,7 @@ declare const photoFieldConfigSchema: z.ZodObject<{
|
|
|
284
284
|
*/
|
|
285
285
|
removeExtension: z.ZodOptional<z.ZodBoolean>;
|
|
286
286
|
name: z.ZodString;
|
|
287
|
-
label: z.ZodOptional<z.ZodString
|
|
287
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
288
288
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
289
289
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
290
290
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -123,7 +123,7 @@ export declare class RichTextField extends Field<'rich_text', Config> {
|
|
|
123
123
|
sanitize: boolean;
|
|
124
124
|
type: "rich_text";
|
|
125
125
|
name: string;
|
|
126
|
-
label:
|
|
126
|
+
label: import("../../index.js").LocalizedString;
|
|
127
127
|
required: boolean;
|
|
128
128
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
129
129
|
readonly: boolean;
|
|
@@ -193,7 +193,7 @@ declare const optionsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
193
193
|
}>>;
|
|
194
194
|
}, z.core.$strict>>;
|
|
195
195
|
name: z.ZodString;
|
|
196
|
-
label: z.ZodOptional<z.ZodString
|
|
196
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
197
197
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
198
198
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
199
199
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -206,7 +206,7 @@ declare const optionsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
206
206
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
207
207
|
allowMedia: z.ZodOptional<z.ZodLiteral<false>>;
|
|
208
208
|
name: z.ZodString;
|
|
209
|
-
label: z.ZodOptional<z.ZodString
|
|
209
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
210
210
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
211
211
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
212
212
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -255,7 +255,7 @@ declare const richTextFieldConfigSchema: z.ZodIntersection<z.ZodDiscriminatedUni
|
|
|
255
255
|
}>>;
|
|
256
256
|
}, z.core.$strict>>;
|
|
257
257
|
name: z.ZodString;
|
|
258
|
-
label: z.ZodOptional<z.ZodString
|
|
258
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
259
259
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
260
260
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
261
261
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -268,7 +268,7 @@ declare const richTextFieldConfigSchema: z.ZodIntersection<z.ZodDiscriminatedUni
|
|
|
268
268
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
269
269
|
allowMedia: z.ZodOptional<z.ZodLiteral<false>>;
|
|
270
270
|
name: z.ZodString;
|
|
271
|
-
label: z.ZodOptional<z.ZodString
|
|
271
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
272
272
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
273
273
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
274
274
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -142,7 +142,7 @@ export declare class SelectField extends Field<'select', SelectFieldConfig> {
|
|
|
142
142
|
}[] | undefined;
|
|
143
143
|
type: "select";
|
|
144
144
|
name: string;
|
|
145
|
-
label:
|
|
145
|
+
label: import("../../index.js").LocalizedString;
|
|
146
146
|
required: boolean;
|
|
147
147
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
148
148
|
readonly: boolean;
|
|
@@ -204,7 +204,7 @@ export declare const selectFieldOptionsSchema: z.ZodUnion<readonly [z.ZodObject<
|
|
|
204
204
|
}, z.core.$strict>;
|
|
205
205
|
section: z.ZodOptional<z.ZodNever>;
|
|
206
206
|
name: z.ZodString;
|
|
207
|
-
label: z.ZodOptional<z.ZodString
|
|
207
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
208
208
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
209
209
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
210
210
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -230,7 +230,7 @@ export declare const selectFieldOptionsSchema: z.ZodUnion<readonly [z.ZodObject<
|
|
|
230
230
|
db: z.ZodOptional<z.ZodNever>;
|
|
231
231
|
section: z.ZodCustom<SelectSectionOption, SelectSectionOption>;
|
|
232
232
|
name: z.ZodString;
|
|
233
|
-
label: z.ZodOptional<z.ZodString
|
|
233
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
234
234
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
235
235
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
236
236
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -256,7 +256,7 @@ export declare const selectFieldOptionsSchema: z.ZodUnion<readonly [z.ZodObject<
|
|
|
256
256
|
db: z.ZodOptional<z.ZodNever>;
|
|
257
257
|
section: z.ZodOptional<z.ZodNever>;
|
|
258
258
|
name: z.ZodString;
|
|
259
|
-
label: z.ZodOptional<z.ZodString
|
|
259
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
260
260
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
261
261
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
262
262
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -285,7 +285,7 @@ declare const selectFieldConfigSchema: z.ZodIntersection<z.ZodUnion<readonly [z.
|
|
|
285
285
|
}, z.core.$strict>;
|
|
286
286
|
section: z.ZodOptional<z.ZodNever>;
|
|
287
287
|
name: z.ZodString;
|
|
288
|
-
label: z.ZodOptional<z.ZodString
|
|
288
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
289
289
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
290
290
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
291
291
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -311,7 +311,7 @@ declare const selectFieldConfigSchema: z.ZodIntersection<z.ZodUnion<readonly [z.
|
|
|
311
311
|
db: z.ZodOptional<z.ZodNever>;
|
|
312
312
|
section: z.ZodCustom<SelectSectionOption, SelectSectionOption>;
|
|
313
313
|
name: z.ZodString;
|
|
314
|
-
label: z.ZodOptional<z.ZodString
|
|
314
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
315
315
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
316
316
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
317
317
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -337,7 +337,7 @@ declare const selectFieldConfigSchema: z.ZodIntersection<z.ZodUnion<readonly [z.
|
|
|
337
337
|
db: z.ZodOptional<z.ZodNever>;
|
|
338
338
|
section: z.ZodOptional<z.ZodNever>;
|
|
339
339
|
name: z.ZodString;
|
|
340
|
-
label: z.ZodOptional<z.ZodString
|
|
340
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
341
341
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
342
342
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
343
343
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -106,7 +106,7 @@ export declare class SelectMultipleField extends Field<'select_multiple', Select
|
|
|
106
106
|
}[] | undefined;
|
|
107
107
|
type: "select_multiple";
|
|
108
108
|
name: string;
|
|
109
|
-
label:
|
|
109
|
+
label: import("../../index.js").LocalizedString;
|
|
110
110
|
required: boolean;
|
|
111
111
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
112
112
|
readonly: boolean;
|
|
@@ -162,7 +162,7 @@ declare const selectMultipleFieldHelperConfigSchema: z.ZodIntersection<z.ZodUnio
|
|
|
162
162
|
}, z.core.$strict>;
|
|
163
163
|
section: z.ZodOptional<z.ZodNever>;
|
|
164
164
|
name: z.ZodString;
|
|
165
|
-
label: z.ZodOptional<z.ZodString
|
|
165
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
166
166
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
167
167
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
168
168
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -192,7 +192,7 @@ declare const selectMultipleFieldHelperConfigSchema: z.ZodIntersection<z.ZodUnio
|
|
|
192
192
|
build(): HasItemsSection | CategorySection;
|
|
193
193
|
}>;
|
|
194
194
|
name: z.ZodString;
|
|
195
|
-
label: z.ZodOptional<z.ZodString
|
|
195
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
196
196
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
197
197
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
198
198
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -212,7 +212,7 @@ declare const selectMultipleFieldHelperConfigSchema: z.ZodIntersection<z.ZodUnio
|
|
|
212
212
|
db: z.ZodOptional<z.ZodNever>;
|
|
213
213
|
section: z.ZodOptional<z.ZodNever>;
|
|
214
214
|
name: z.ZodString;
|
|
215
|
-
label: z.ZodOptional<z.ZodString
|
|
215
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
216
216
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
217
217
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
218
218
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -52,7 +52,7 @@ export declare class TagsField extends Field<'tags', Config> {
|
|
|
52
52
|
sanitize: boolean;
|
|
53
53
|
type: "tags";
|
|
54
54
|
name: string;
|
|
55
|
-
label:
|
|
55
|
+
label: import("../../index.js").LocalizedString;
|
|
56
56
|
required: boolean;
|
|
57
57
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
58
58
|
readonly: boolean;
|
|
@@ -111,7 +111,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
111
111
|
*/
|
|
112
112
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
113
113
|
name: z.ZodString;
|
|
114
|
-
label: z.ZodOptional<z.ZodString
|
|
114
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
115
115
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
116
116
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
117
117
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -143,7 +143,7 @@ declare const tagsFieldConfigSchema: z.ZodObject<{
|
|
|
143
143
|
*/
|
|
144
144
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
145
145
|
name: z.ZodString;
|
|
146
|
-
label: z.ZodOptional<z.ZodString
|
|
146
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
147
147
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
148
148
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
149
149
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -41,7 +41,7 @@ export declare class TextField extends Field<'text', Config> {
|
|
|
41
41
|
sanitize: boolean;
|
|
42
42
|
type: "text";
|
|
43
43
|
name: string;
|
|
44
|
-
label:
|
|
44
|
+
label: import("../../index.js").LocalizedString;
|
|
45
45
|
required: boolean;
|
|
46
46
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
47
47
|
readonly: boolean;
|
|
@@ -78,7 +78,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
78
78
|
*/
|
|
79
79
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
80
80
|
name: z.ZodString;
|
|
81
|
-
label: z.ZodOptional<z.ZodString
|
|
81
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
82
82
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
83
83
|
order: z.ZodOptional<z.ZodNumber>;
|
|
84
84
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -104,7 +104,7 @@ declare const textFieldConfigSchema: z.ZodObject<{
|
|
|
104
104
|
*/
|
|
105
105
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
106
106
|
name: z.ZodString;
|
|
107
|
-
label: z.ZodOptional<z.ZodString
|
|
107
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
108
108
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
109
109
|
order: z.ZodOptional<z.ZodNumber>;
|
|
110
110
|
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
@@ -29,7 +29,7 @@ export declare class TextAreaField extends Field<'textarea', Config> {
|
|
|
29
29
|
sanitize: boolean;
|
|
30
30
|
type: "textarea";
|
|
31
31
|
name: string;
|
|
32
|
-
label:
|
|
32
|
+
label: import("../../index.js").LocalizedString;
|
|
33
33
|
required: boolean;
|
|
34
34
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
35
35
|
readonly: boolean;
|
|
@@ -63,7 +63,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
63
63
|
*/
|
|
64
64
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
65
65
|
name: z.ZodString;
|
|
66
|
-
label: z.ZodOptional<z.ZodString
|
|
66
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
67
67
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
68
68
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
69
69
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -84,7 +84,7 @@ declare const textAreaFieldConfigSchema: z.ZodObject<{
|
|
|
84
84
|
*/
|
|
85
85
|
sanitize: z.ZodOptional<z.ZodBoolean>;
|
|
86
86
|
name: z.ZodString;
|
|
87
|
-
label: z.ZodOptional<z.ZodString
|
|
87
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
88
88
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
89
89
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
90
90
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -50,7 +50,7 @@ export declare class VideoField extends FileField<'video', Config> {
|
|
|
50
50
|
mimeType: string[];
|
|
51
51
|
type: "video";
|
|
52
52
|
name: string;
|
|
53
|
-
label:
|
|
53
|
+
label: import("../../index.js").LocalizedString;
|
|
54
54
|
required: boolean;
|
|
55
55
|
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
56
56
|
readonly: boolean;
|
|
@@ -104,7 +104,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
104
104
|
ogg: "ogg";
|
|
105
105
|
}>>>;
|
|
106
106
|
name: z.ZodString;
|
|
107
|
-
label: z.ZodOptional<z.ZodString
|
|
107
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
108
108
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
109
109
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
110
110
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -134,7 +134,7 @@ declare const videoFieldConfigSchema: z.ZodObject<{
|
|
|
134
134
|
ogg: "ogg";
|
|
135
135
|
}>>>;
|
|
136
136
|
name: z.ZodString;
|
|
137
|
-
label: z.ZodOptional<z.ZodString
|
|
137
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
138
138
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
139
139
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
140
140
|
order: z.ZodOptional<z.ZodNumber>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/i18n.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localization utilities for resolving localized strings.
|
|
3
|
+
* Supports Payload CMS-style translations where developers can provide
|
|
4
|
+
* translations directly in field labels and section titles.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A localized string can be either:
|
|
8
|
+
* - A plain string (backward compatible)
|
|
9
|
+
* - An object with language codes as keys and translated strings as values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Single language (backward compatible)
|
|
14
|
+
* label: 'Title'
|
|
15
|
+
*
|
|
16
|
+
* // Multiple languages
|
|
17
|
+
* label: {
|
|
18
|
+
* en: 'Title',
|
|
19
|
+
* ar: 'العنوان'
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type LocalizedString = string | Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a localized string to a specific locale.
|
|
26
|
+
* If the string is a plain string, it's returned as-is.
|
|
27
|
+
* If it's an object, the value for the given locale is returned.
|
|
28
|
+
* Falls back to the first available language or the fallback locale if the requested locale is not found.
|
|
29
|
+
*
|
|
30
|
+
* @param localized - The localized string (string or object with language codes)
|
|
31
|
+
* @param locale - The target locale code (e.g., 'en', 'ar')
|
|
32
|
+
* @param fallbackLocale - The fallback locale code if the requested locale is not found
|
|
33
|
+
* @returns The resolved string for the given locale
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveLocalizedString(localized: LocalizedString | undefined, locale: string, fallbackLocale?: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a value is a localized string object (not a plain string)
|
|
38
|
+
*/
|
|
39
|
+
export declare function isLocalizedObject(value: LocalizedString | undefined): value is Record<string, string>;
|
|
40
|
+
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/core/localization.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7D;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAClC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,MAAM,EAAE,MAAM,EACd,cAAc,GAAE,MAAa,GAC9B,MAAM,CA8BR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAErG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localization utilities for resolving localized strings.
|
|
3
|
+
* Supports Payload CMS-style translations where developers can provide
|
|
4
|
+
* translations directly in field labels and section titles.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Resolve a localized string to a specific locale.
|
|
8
|
+
* If the string is a plain string, it's returned as-is.
|
|
9
|
+
* If it's an object, the value for the given locale is returned.
|
|
10
|
+
* Falls back to the first available language or the fallback locale if the requested locale is not found.
|
|
11
|
+
*
|
|
12
|
+
* @param localized - The localized string (string or object with language codes)
|
|
13
|
+
* @param locale - The target locale code (e.g., 'en', 'ar')
|
|
14
|
+
* @param fallbackLocale - The fallback locale code if the requested locale is not found
|
|
15
|
+
* @returns The resolved string for the given locale
|
|
16
|
+
*/
|
|
17
|
+
export function resolveLocalizedString(localized, locale, fallbackLocale = 'en') {
|
|
18
|
+
if (!localized) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
// If it's a plain string, return as-is (backward compatible)
|
|
22
|
+
if (typeof localized === 'string') {
|
|
23
|
+
return localized;
|
|
24
|
+
}
|
|
25
|
+
// If it's an object, resolve based on locale
|
|
26
|
+
if (typeof localized === 'object') {
|
|
27
|
+
// Try the requested locale first
|
|
28
|
+
if (localized[locale]) {
|
|
29
|
+
return localized[locale];
|
|
30
|
+
}
|
|
31
|
+
// Try the fallback locale
|
|
32
|
+
if (localized[fallbackLocale]) {
|
|
33
|
+
return localized[fallbackLocale];
|
|
34
|
+
}
|
|
35
|
+
// Fall back to the first available language
|
|
36
|
+
const firstKey = Object.keys(localized)[0];
|
|
37
|
+
if (firstKey) {
|
|
38
|
+
return localized[firstKey];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a value is a localized string object (not a plain string)
|
|
45
|
+
*/
|
|
46
|
+
export function isLocalizedObject(value) {
|
|
47
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|