nextjs-cms 0.6.8 → 0.6.9
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/core/config/config-loader.d.ts +4 -10
- package/dist/core/config/config-loader.d.ts.map +1 -1
- package/dist/core/config/config-loader.js +14 -14
- package/dist/core/sections/category.d.ts +32 -32
- package/dist/core/sections/hasItems.d.ts +32 -32
- package/dist/core/sections/section.d.ts +16 -16
- package/dist/core/sections/simple.d.ts +8 -8
- package/dist/translations/client.d.ts +5178 -1
- package/dist/translations/client.d.ts.map +1 -1
- package/dist/translations/client.js +29 -4
- package/dist/translations/dict-store.d.ts +5 -1
- package/dist/translations/dict-store.d.ts.map +1 -1
- package/dist/translations/dict-store.js +30 -3
- package/dist/translations/index.d.ts +1 -1
- package/dist/translations/index.js +1 -1
- package/dist/translations/server.d.ts +5171 -1
- package/dist/translations/server.d.ts.map +1 -1
- package/dist/translations/server.js +26 -4
- package/package.json +3 -3
- package/dist/core/helpers/i18n.d.ts +0 -2
- package/dist/core/helpers/i18n.d.ts.map +0 -1
- package/dist/core/helpers/i18n.js +0 -3
- package/dist/core/localization.d.ts +0 -40
- package/dist/core/localization.d.ts.map +0 -1
- package/dist/core/localization.js +0 -48
- package/dist/logging/audit.d.ts +0 -20
- package/dist/logging/audit.d.ts.map +0 -1
- package/dist/logging/audit.js +0 -48
- package/dist/translations/localized-string.d.ts +0 -17
- package/dist/translations/localized-string.d.ts.map +0 -1
- package/dist/translations/localized-string.js +0 -32
- package/dist/translations/use-project-translation.d.ts +0 -19
- package/dist/translations/use-project-translation.d.ts.map +0 -1
- package/dist/translations/use-project-translation.js +0 -25
- package/dist/validators/types.d.ts +0 -7
- package/dist/validators/types.d.ts.map +0 -1
- package/dist/validators/types.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/translations/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAE,eAAe;;GAAqD,CAAA;AAE3G,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAMvG"}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { createI18nServer } from 'next-international/server';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { getAllDicts, getDict } from './dict-store.js';
|
|
3
|
+
function createDynamicLocaleImporters() {
|
|
4
|
+
return new Proxy({}, {
|
|
5
|
+
get: (_target, prop) => {
|
|
6
|
+
if (typeof prop !== 'string')
|
|
7
|
+
return undefined;
|
|
8
|
+
return async () => ({ default: getDict(prop) });
|
|
9
|
+
},
|
|
10
|
+
ownKeys: () => Object.keys(getAllDicts()),
|
|
11
|
+
getOwnPropertyDescriptor: (_target, prop) => {
|
|
12
|
+
if (typeof prop !== 'string')
|
|
13
|
+
return undefined;
|
|
14
|
+
if (!(prop in getAllDicts()))
|
|
15
|
+
return undefined;
|
|
16
|
+
return { enumerable: true, configurable: true };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export const { getI18n, getScopedI18n, getStaticParams } = createI18nServer(createDynamicLocaleImporters());
|
|
21
|
+
export function getClientDictionaries(locales) {
|
|
22
|
+
const dicts = {};
|
|
23
|
+
for (const locale of locales) {
|
|
24
|
+
dicts[locale] = getDict(locale);
|
|
25
|
+
}
|
|
26
|
+
return dicts;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-cms",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -192,8 +192,8 @@
|
|
|
192
192
|
"tsx": "^4.20.6",
|
|
193
193
|
"typescript": "^5.9.2",
|
|
194
194
|
"@lzcms/eslint-config": "0.3.0",
|
|
195
|
-
"@lzcms/
|
|
196
|
-
"@lzcms/
|
|
195
|
+
"@lzcms/prettier-config": "0.1.0",
|
|
196
|
+
"@lzcms/tsconfig": "0.1.0"
|
|
197
197
|
},
|
|
198
198
|
"license": "MIT",
|
|
199
199
|
"keywords": [
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/logging/audit.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type AuditEventType = 'auth.login' | 'auth.logout' | 'section.item.create' | 'section.item.update' | 'section.item.delete' | 'admin.section.create' | 'admin.section.update' | 'admin.section.delete' | 'admin.username.change' | 'admin.settings.change';
|
|
2
|
-
export type RequestMetadata = {
|
|
3
|
-
ipAddress?: string | null;
|
|
4
|
-
userAgent?: string | null;
|
|
5
|
-
source?: string | null;
|
|
6
|
-
};
|
|
7
|
-
export type AuditLogInput = {
|
|
8
|
-
eventType: AuditEventType;
|
|
9
|
-
actorId?: string | number | null;
|
|
10
|
-
actorUsername?: string | null;
|
|
11
|
-
entityType?: string | null;
|
|
12
|
-
entityId?: string | number | null;
|
|
13
|
-
entityLabel?: string | null;
|
|
14
|
-
sectionName?: string | null;
|
|
15
|
-
metadata?: Record<string, unknown>;
|
|
16
|
-
requestMetadata?: RequestMetadata;
|
|
17
|
-
};
|
|
18
|
-
export declare const getRequestMetadataFromHeaders: (headers?: Headers | null) => RequestMetadata;
|
|
19
|
-
export declare const recordAuditLog: (input: AuditLogInput) => Promise<void>;
|
|
20
|
-
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/logging/audit.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GACpB,YAAY,GACZ,aAAa,GACb,qBAAqB,GACrB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,sBAAsB,GACtB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAA;AAE7B,MAAM,MAAM,eAAe,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,SAAS,EAAE,cAAc,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAChC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACjC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;CACpC,CAAA;AAcD,eAAO,MAAM,6BAA6B,GAAI,UAAU,OAAO,GAAG,IAAI,KAAG,eAaxE,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,OAAO,aAAa,KAAG,OAAO,CAAC,IAAI,CAqBvE,CAAA"}
|
package/dist/logging/audit.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { db } from '../db/client.js';
|
|
2
|
-
import { AuditLogsTable } from '../db/schema.js';
|
|
3
|
-
const toNullableString = (value) => value === null || value === undefined ? null : String(value);
|
|
4
|
-
const safeJsonStringify = (value) => {
|
|
5
|
-
if (!value)
|
|
6
|
-
return null;
|
|
7
|
-
try {
|
|
8
|
-
return JSON.stringify(value);
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
return JSON.stringify({ error: 'metadata_serialization_failed' });
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
export const getRequestMetadataFromHeaders = (headers) => {
|
|
15
|
-
if (!headers)
|
|
16
|
-
return {};
|
|
17
|
-
const forwardedFor = headers.get('x-forwarded-for');
|
|
18
|
-
const realIp = headers.get('x-real-ip');
|
|
19
|
-
const cfIp = headers.get('cf-connecting-ip');
|
|
20
|
-
const ipAddress = (forwardedFor?.split(',')[0] || realIp || cfIp || '').trim() || null;
|
|
21
|
-
return {
|
|
22
|
-
ipAddress,
|
|
23
|
-
userAgent: headers.get('user-agent') || null,
|
|
24
|
-
source: headers.get('x-trpc-source') || headers.get('x-requested-with') || null,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export const recordAuditLog = async (input) => {
|
|
28
|
-
const metadata = safeJsonStringify(input.metadata);
|
|
29
|
-
const request = input.requestMetadata ?? {};
|
|
30
|
-
try {
|
|
31
|
-
await db.insert(AuditLogsTable).values({
|
|
32
|
-
eventType: input.eventType,
|
|
33
|
-
actorId: toNullableString(input.actorId),
|
|
34
|
-
actorUsername: input.actorUsername ?? null,
|
|
35
|
-
entityType: input.entityType ?? null,
|
|
36
|
-
entityId: toNullableString(input.entityId),
|
|
37
|
-
entityLabel: input.entityLabel ?? null,
|
|
38
|
-
sectionName: input.sectionName ?? null,
|
|
39
|
-
metadata,
|
|
40
|
-
ipAddress: request.ipAddress ?? null,
|
|
41
|
-
userAgent: request.userAgent ?? null,
|
|
42
|
-
source: request.source ?? null,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error('Failed to write audit log entry', error);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LocalizedString represents a translation object keyed by locale codes.
|
|
3
|
-
* Example: { en: 'Title', ar: 'العنوان' }
|
|
4
|
-
*/
|
|
5
|
-
export type LocalizedString = Record<string, string>;
|
|
6
|
-
/**
|
|
7
|
-
* Resolves a localized string to the current locale.
|
|
8
|
-
* If input is a string, returns it as-is (for single-language projects).
|
|
9
|
-
* If input is a LocalizedString (Record<string, string>), returns the value for the current locale or fallback.
|
|
10
|
-
*
|
|
11
|
-
* @param input - Either a simple string or a LocalizedString object
|
|
12
|
-
* @param locale - The current locale code (e.g., 'en', 'ar')
|
|
13
|
-
* @param fallbackLocale - The fallback locale code (default: 'en')
|
|
14
|
-
* @returns The resolved string for the current locale
|
|
15
|
-
*/
|
|
16
|
-
export declare function resolveTranslation(input: string | LocalizedString, locale: string, fallbackLocale?: string): string;
|
|
17
|
-
//# sourceMappingURL=localized-string.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localized-string.d.ts","sourceRoot":"","sources":["../../src/translations/localized-string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEpD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,MAAM,GAAG,eAAe,EAC/B,MAAM,EAAE,MAAM,EACd,cAAc,GAAE,MAAa,GAC9B,MAAM,CAyBR"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves a localized string to the current locale.
|
|
3
|
-
* If input is a string, returns it as-is (for single-language projects).
|
|
4
|
-
* If input is a LocalizedString (Record<string, string>), returns the value for the current locale or fallback.
|
|
5
|
-
*
|
|
6
|
-
* @param input - Either a simple string or a LocalizedString object
|
|
7
|
-
* @param locale - The current locale code (e.g., 'en', 'ar')
|
|
8
|
-
* @param fallbackLocale - The fallback locale code (default: 'en')
|
|
9
|
-
* @returns The resolved string for the current locale
|
|
10
|
-
*/
|
|
11
|
-
export function resolveTranslation(input, locale, fallbackLocale = 'en') {
|
|
12
|
-
// If input is a simple string, return it as-is
|
|
13
|
-
if (typeof input === 'string') {
|
|
14
|
-
return input;
|
|
15
|
-
}
|
|
16
|
-
// input is LocalizedString (Record<string, string>)
|
|
17
|
-
// Try current locale first
|
|
18
|
-
if (input[locale]) {
|
|
19
|
-
return input[locale];
|
|
20
|
-
}
|
|
21
|
-
// Fall back to fallback locale
|
|
22
|
-
if (input[fallbackLocale]) {
|
|
23
|
-
return input[fallbackLocale];
|
|
24
|
-
}
|
|
25
|
-
// Fall back to first available translation
|
|
26
|
-
const firstKey = Object.keys(input)[0];
|
|
27
|
-
if (firstKey) {
|
|
28
|
-
return input[firstKey];
|
|
29
|
-
}
|
|
30
|
-
// Last resort: return empty string
|
|
31
|
-
return '';
|
|
32
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { LocalizedString } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Hook for resolving project translations (section/field labels) on the client side.
|
|
4
|
-
* Most labels are resolved server-side, but this hook is available for edge cases
|
|
5
|
-
* where client-side resolution is needed.
|
|
6
|
-
*
|
|
7
|
-
* @param fallbackLocale - Optional fallback locale (defaults to 'en')
|
|
8
|
-
* @returns A function that resolves LocalizedString to the current locale
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const resolveLabel = useProjectTranslation()
|
|
13
|
-
* const displayLabel = resolveLabel(field.label)
|
|
14
|
-
* // If field.label is LocalizedString: resolves to current locale
|
|
15
|
-
* // If field.label is string: returns as-is
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function useProjectTranslation(fallbackLocale?: string): (input: string | LocalizedString) => string;
|
|
19
|
-
//# sourceMappingURL=use-project-translation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-project-translation.d.ts","sourceRoot":"","sources":["../../src/translations/use-project-translation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,GAAE,MAAa,IAGvD,OAAO,MAAM,GAAG,eAAe,KAAG,MAAM,CAGnD"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useI18n } from './client.js';
|
|
3
|
-
import { resolveTranslation } from './localized-string.js';
|
|
4
|
-
/**
|
|
5
|
-
* Hook for resolving project translations (section/field labels) on the client side.
|
|
6
|
-
* Most labels are resolved server-side, but this hook is available for edge cases
|
|
7
|
-
* where client-side resolution is needed.
|
|
8
|
-
*
|
|
9
|
-
* @param fallbackLocale - Optional fallback locale (defaults to 'en')
|
|
10
|
-
* @returns A function that resolves LocalizedString to the current locale
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* const resolveLabel = useProjectTranslation()
|
|
15
|
-
* const displayLabel = resolveLabel(field.label)
|
|
16
|
-
* // If field.label is LocalizedString: resolves to current locale
|
|
17
|
-
* // If field.label is string: returns as-is
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function useProjectTranslation(fallbackLocale = 'en') {
|
|
21
|
-
const { locale } = useI18n();
|
|
22
|
-
return (input) => {
|
|
23
|
-
return resolveTranslation(input, locale, fallbackLocale);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Translation function type for localized validation messages.
|
|
3
|
-
* @param key - The translation key
|
|
4
|
-
* @param params - Optional interpolation parameters
|
|
5
|
-
*/
|
|
6
|
-
export type TranslationFn = (key: string, params?: Record<string, string | number>) => string;
|
|
7
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validators/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,MAAM,CAAA"}
|
package/dist/validators/types.js
DELETED
|
File without changes
|