import { Signal } from '@effuse/core'; import * as effect_Cause from 'effect/Cause'; import * as effect_Types from 'effect/Types'; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ type Prev = [never, 0, 1, 2, 3, 4]; type FlattenKeys = Depth extends 0 ? never : T extends string ? never : T extends object ? { [K in keyof T & string]: T[K] extends string ? K : T[K] extends object ? K | `${K}.${FlattenKeys}` : K; }[keyof T & string] : never; type GetNestedType = Path extends keyof T ? T[Path] : Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends object ? GetNestedType : never : never : never; type ExtractVariables = T extends `${string}{{${infer Var}}}${infer Rest}` ? Var | ExtractVariables : never; type ParamsFor = T extends string ? ExtractVariables extends never ? TranslationParams | undefined : { [K in ExtractVariables]: string | number; } & { count?: number; } : TranslationParams | undefined; type InferParams = ParamsFor>; interface Translations { [key: string]: string | Translations; } interface TranslationParams { count?: number; [key: string]: unknown; } interface PluralRules { zero?: string; one?: string; two?: string; few?: string; many?: string; other: string; } type TranslationLoader = (locale: string) => Promise | Translations; interface I18nOptions { defaultLocale?: string; fallbackLocale?: string; translations?: Record; loader?: TranslationLoader; loadPath?: string | ((locale: string) => string); detectLocale?: boolean; persistLocale?: boolean; onMissingKey?: (key: string, locale: string) => string | undefined; } interface TypedI18nOptions { defaultLocale?: string; fallbackLocale?: string; translations: Record; loader?: TranslationLoader; loadPath?: string | ((locale: string) => string); detectLocale?: boolean; persistLocale?: boolean; onMissingKey?: (key: string, locale: string) => string | undefined; } interface TypedI18n { t: >(key: K, params?: InferParams) => string; setLocale: (locale: string) => Promise; getLocale: () => string; locale: Signal; hasKey: (key: FlattenKeys) => boolean; getAvailableLocales: () => string[]; addTranslations: (locale: string, translations: Translations) => void; } interface I18n { t: (key: string, params?: TranslationParams) => string; setLocale: (locale: string) => Promise; getLocale: () => string; locale: Signal; hasKey: (key: string) => boolean; getAvailableLocales: () => string[]; addTranslations: (locale: string, translations: Translations) => void; } interface TypedUseTranslationReturn { t: >(key: K, params?: InferParams) => string; locale: Signal; setLocale: (locale: string) => Promise; hasKey: (key: FlattenKeys) => boolean; } interface UseTranslationReturn { t: (key: string, params?: TranslationParams) => string; locale: Signal; setLocale: (locale: string) => Promise; hasKey: (key: string) => boolean; } declare function defineTranslations(translations: T): T; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ declare function createI18n(options: TypedI18nOptions): TypedI18n; declare function createI18n(options?: I18nOptions): I18n; declare function createI18nInstance(options: TypedI18nOptions): TypedI18n; declare function createI18nInstance(options?: I18nOptions): I18n; declare function withI18n(instance: I18n, fn: () => R): R; declare function withI18n(instance: TypedI18n, fn: () => R): R; declare function getI18n(): I18n; declare function getI18n(): TypedI18n; declare const t: (key: string, params?: TranslationParams) => string; declare const setLocale: (locale: string) => Promise; declare const getLocale: () => string; declare function useTranslation(): UseTranslationReturn; declare function useTranslation(): TypedUseTranslationReturn; declare const resetI18n: () => void; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * Resolves an Accept-Language header against the locales an application * actually ships. Quality values order the candidates, region tags fall back * to their base locale (en-US matches en), the wildcard resolves to the * fallback, and anything unmatched or malformed degrades to the fallback. */ declare const resolveLocale: (header: string | null | undefined, availableLocales: readonly string[], fallbackLocale: string) => string; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ declare const MissingTranslationError_base: new = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & { readonly _tag: "MissingTranslationError"; } & Readonly; declare class MissingTranslationError extends MissingTranslationError_base<{ readonly key: string; readonly locale: string; }> { } declare const LocaleLoadError_base: new = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & { readonly _tag: "LocaleLoadError"; } & Readonly; declare class LocaleLoadError extends LocaleLoadError_base<{ readonly locale: string; readonly cause?: unknown; }> { } declare const InvalidLocaleError_base: new = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & { readonly _tag: "InvalidLocaleError"; } & Readonly; declare class InvalidLocaleError extends InvalidLocaleError_base<{ readonly locale: string; }> { } declare const I18nNotInitializedError_base: new = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & { readonly _tag: "I18nNotInitializedError"; } & Readonly; declare class I18nNotInitializedError extends I18nNotInitializedError_base> { } type I18nError = MissingTranslationError | LocaleLoadError | InvalidLocaleError | I18nNotInitializedError; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ declare const DEFAULT_LOCALE = "en"; declare const DEFAULT_FALLBACK_LOCALE = "en"; declare const LOCALE_STORAGE_KEY = "effuse-i18n-locale"; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ interface I18nConfigValues { defaultLocale: string; fallbackLocale: string; detectLocale: boolean; persistLocale: boolean; } declare const getI18nConfig: () => I18nConfigValues; declare const resetI18nConfigCache: () => void; /** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ declare const getNestedValue: (translations: Translations, key: string) => string | Translations | undefined; declare const hasTranslationKey: (translations: Translations, key: string) => boolean; declare const getPluralSuffix: (count: number, locale: string) => string; declare const interpolate: (template: string, params: TranslationParams) => string; declare const translate: (translations: Translations | undefined, fallbackTranslations: Translations | undefined, key: string, params: TranslationParams | undefined, locale: string) => string; declare const mergeTranslations: (target: Translations, source: Translations) => Translations; declare const flattenTranslations: (translations: Translations, prefix?: string) => Record; export { DEFAULT_FALLBACK_LOCALE, DEFAULT_LOCALE, type ExtractVariables, type FlattenKeys, type I18n, type I18nConfigValues, type I18nError, I18nNotInitializedError, type I18nOptions, type InferParams, InvalidLocaleError, LOCALE_STORAGE_KEY, LocaleLoadError, MissingTranslationError, type PluralRules, type TranslationLoader, type TranslationParams, type Translations, type TypedI18n, type TypedI18nOptions, type TypedUseTranslationReturn, type UseTranslationReturn, createI18n, createI18nInstance, defineTranslations, flattenTranslations, getI18n, getI18nConfig, getLocale, getNestedValue, getPluralSuffix, hasTranslationKey, interpolate, mergeTranslations, resetI18n, resetI18nConfigCache, resolveLocale, setLocale, t, translate, useTranslation, withI18n };