App reorganization
This commit is contained in:
@@ -26,31 +26,3 @@ export function getTranslation(messages: Messages, key: string): string {
|
||||
|
||||
return typeof value === "string" ? value : key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe helper to get nested values from messages
|
||||
* Usage: getNested(messages, "heroBanner", "title")
|
||||
*/
|
||||
export function getNested<T extends keyof Messages>(
|
||||
messages: Messages,
|
||||
namespace: T,
|
||||
key: string,
|
||||
): string {
|
||||
const namespaceObj = messages[namespace];
|
||||
if (!namespaceObj || typeof namespaceObj !== "object") {
|
||||
return key;
|
||||
}
|
||||
|
||||
const keys = key.split(".");
|
||||
let value: unknown = namespaceObj;
|
||||
|
||||
for (const k of keys) {
|
||||
if (value && typeof value === "object" && k in value) {
|
||||
value = (value as Record<string, unknown>)[k];
|
||||
} else {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
return typeof value === "string" ? value : key;
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* Type definitions for translation keys
|
||||
*
|
||||
* These types provide type safety when accessing translation keys.
|
||||
* The actual types are inferred from the JSON files in messages/en/
|
||||
*/
|
||||
|
||||
// Import the message structure to ensure type safety
|
||||
import type messages from "../../messages/en/index";
|
||||
|
||||
export type Messages = typeof messages;
|
||||
|
||||
// Helper type for nested key paths
|
||||
export type NestedKeyOf<ObjectType extends object> = {
|
||||
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object
|
||||
? `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key]>}`
|
||||
: `${Key}`;
|
||||
}[keyof ObjectType & (string | number)];
|
||||
|
||||
// Type for all possible translation keys
|
||||
export type TranslationKey = NestedKeyOf<Messages>;
|
||||
Reference in New Issue
Block a user