UNPKG

alepha

Version:

Alepha is a convention-driven TypeScript framework for building robust, end-to-end type-safe applications, from serverless APIs to full-stack React apps.

112 lines (109 loc) 3.48 kB
import * as _alepha_core1 from "alepha"; import * as _alepha_core0 from "alepha"; import { Alepha, Descriptor, KIND } from "alepha"; import * as _alepha_server_cookies0 from "alepha/server/cookies"; import * as _sinclair_typebox0 from "@sinclair/typebox"; //#region src/providers/I18nProvider.d.ts declare class I18nProvider { logger: _alepha_core1.Logger; alepha: Alepha; cookie: _alepha_server_cookies0.AbstractCookieDescriptor<_sinclair_typebox0.TString>; registry: Array<{ name: string; lang: string; loader: () => Promise<Record<string, string>>; translations: Record<string, string>; }>; options: { fallbackLang: string; }; get languages(): string[]; onRender: _alepha_core1.HookDescriptor<"server:onRequest">; onStart: _alepha_core1.HookDescriptor<"start">; setLang(lang: string): Promise<void>; get lang(): string; translate: (key: string, args?: string[]) => string; protected render(item: string, args: string[]): string; } //# sourceMappingURL=I18nProvider.d.ts.map //#endregion //#region src/descriptors/$dictionary.d.ts /** * Register a dictionary entry for translations. * * It allows you to define a set of translations for a specific language. * Entry can be lazy-loaded, which is useful for large dictionaries or when translations are not needed immediately. * * @example * ```ts * import { $dictionary } from "alepha/react/i18n"; * * const Example = () => { * const { tr } = useI18n<App, "en">(); * return <div>{tr("hello")}</div>; // * } * * class App { * * en = $dictionary({ * // { default: { hello: "Hey" } } * lazy: () => import("./translations/en.ts"), * }); * * home = $page({ * path: "/", * component: Example, * }) * } * * run(App); * ``` */ declare const $dictionary: { <T extends Record<string, string>>(options: DictionaryDescriptorOptions<T>): DictionaryDescriptor<T>; [KIND]: typeof DictionaryDescriptor; }; interface DictionaryDescriptorOptions<T extends Record<string, string>> { lang?: string; name?: string; lazy: () => Promise<{ default: T; }>; } declare class DictionaryDescriptor<T extends Record<string, string>> extends Descriptor<DictionaryDescriptorOptions<T>> { protected provider: I18nProvider; protected onInit(): void; } //# sourceMappingURL=$dictionary.d.ts.map //#endregion //#region src/hooks/useI18n.d.ts /** * Hook to access the i18n service. */ declare const useI18n: <S extends object, K extends keyof ServiceDictionary<S>>() => { lang: string; setLang: (lang: string) => Promise<void>; tr: (key: keyof ServiceDictionary<S>[K] | string, args?: string[]) => string; languages: string[]; }; type ServiceDictionary<T extends object> = { [K in keyof T]: T[K] extends DictionaryDescriptor<infer U> ? U : never }; //# sourceMappingURL=useI18n.d.ts.map //#endregion //#region src/index.d.ts declare module "alepha" { interface State { "react.i18n.lang"?: string; } } /** * Add i18n support to your Alepha React application. SSR and CSR compatible. * * It supports lazy loading of translations and provides a context to access the current language. * * @module alepha.react.i18n */ declare const AlephaReactI18n: _alepha_core0.Service<_alepha_core0.Module>; //# sourceMappingURL=index.d.ts.map //#endregion export { $dictionary, AlephaReactI18n, DictionaryDescriptor, DictionaryDescriptorOptions, I18nProvider, ServiceDictionary, useI18n }; //# sourceMappingURL=index.d.ts.map