{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "smj-i18n-optional", "title": "Optional i18n context", "description": "Components fall back to identity strings if no provider is mounted; pass labels prop or wrap with provider.", "files": [ { "path": "registry/lib/use-i18n-optional.ts", "content": "'use client';\n\nimport { createContext, useContext, type ReactNode } from 'react';\n\nexport type Translator = (key: string, fallback?: string) => string;\n\ninterface I18nValue {\n t: Translator;\n locale?: string;\n}\n\nconst I18nCtx = createContext(null);\n\n/**\n * Optional i18n provider. If not present, components fall back to identity strings.\n *\n * @example\n * myDict[k] ?? fb ?? k }}>\n * \n * \n */\nexport function I18nProviderOptional({\n value,\n children,\n}: {\n value: I18nValue;\n children: ReactNode;\n}) {\n return {children};\n}\n\n/**\n * Hook that returns a translator. If no provider is mounted, returns an identity\n * translator that yields the fallback string (or the key when no fallback given).\n *\n * Components in this registry use this so they work *without* requiring consumers\n * to set up i18n — pass an explicit `labels` prop or wrap in a provider as needed.\n */\nexport function useI18nOptional(): I18nValue {\n const ctx = useContext(I18nCtx);\n return ctx ?? { t: (_k, fallback) => fallback ?? _k };\n}\n", "type": "registry:lib", "target": "lib/use-i18n-optional.tsx" } ], "type": "registry:lib" }