import { T as _T } from './server-dir/buildtime/T'; import { useLocalizeHref as _useLocalizeHref } from './link/useLocalizeHref'; import type { GetServerSideProps, GetServerSidePropsContext, PreviewData } from 'next'; import type { ParsedUrlQuery } from 'querystring'; import type { WithGTServerSideProps } from './pages-dir/withGTServerSideProps'; import type { WithGTStaticProps, WithGTStaticPropsFunction } from './pages-dir/withGTStaticProps'; import { useTranslations as _useTranslations, useLocale as _useLocale, useRegion as _useRegion, useLocales as _useLocales, useDefaultLocale as _useDefaultLocale, useLocaleProperties as _useLocaleProperties, Currency as _Currency, DateTime as _DateTime, GtInternalTranslateJsx as _GtInternalTranslateJsx, GtInternalVar as _GtInternalVar, RelativeTime as _RelativeTime, Num as _Num, Var as _Var, Branch as _Branch, Plural as _Plural, Derive as _Derive, useLocaleDirection as _useLocaleDirection } from 'gt-react'; import { LocaleSelector as _LocaleSelector, RegionSelector as _RegionSelector, useSetLocale as _useSetLocale, useLocaleSelector as _useLocaleSelector, getTranslationsSnapshot, getDefaultLocale, getLocaleProperties, getLocales, resolveCanonicalLocale, getVersionId } from 'gt-react'; import { GTProvider as _GTProvider } from 'gt-react'; import type { GTTranslationOptions, RuntimeTranslationOptions } from 'gt-react'; import type { StringFormat } from '@generaltranslation/format/types'; import { msg, decodeMsg, decodeOptions, derive, declareVar, decodeVars, mFallback, gtFallback } from '@generaltranslation/react-core/pure'; type Message = { message: string; $id?: string; $context?: string; $maxChars?: number; $_hash?: string; }; type Messages = Message[]; /** * Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`. * * @param {React.ReactNode} children - The children components that will use the translation context. * @param {string} id - ID of a nested dictionary, so that only a subset of a large dictionary needs to be sent to the client. * @param {string} locale - The locale to use for the translation context. * * @returns {JSX.Element} The provider component for General Translation context. */ export declare function GTProvider(_: { id?: string; } & Partial[0]>): React.ReactNode; /** * Build-time translation component that renders its children in the user's given locale. * * @example * ```jsx * // Basic usage: * * Hello, {name}! * * ``` * * @example * ```jsx * // Translating a plural * * You have item.}> * You have items. * * * ``` * * @param {React.ReactNode} children - The content to be translated or displayed. * @param {string} [id] - Optional identifier for the translation string. If not provided, a hash will be generated from the content. * @param {any} [context] - Additional context for translation key generation. * * @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration. * * @throws {Error} If a plural translation is requested but the `n` option is not provided. */ export declare const T: typeof _T; export declare const GtInternalTranslateJsx: typeof _GtInternalTranslateJsx; /** * The `` component renders a formatted currency string, allowing customization of name, default value, currency type, and formatting options. * * @example * ```jsx * * 1000 * * ``` * * @param {any} [children] - Optional content to render inside the currency component. * @param {string} [currency] - The currency type (e.g., USD, EUR, etc.). * @param {Intl.NumberFormatOptions} [options] - Optional formatting options to customize how the currency is displayed. * @returns {React.JSX.Element} The formatted currency component. */ export declare const Currency: typeof _Currency; /** * The `` component renders a formatted date or time string, allowing customization of the name, default value, and formatting options. * It utilizes the current locale and optional format settings to display the date. * * @example * ```jsx * * {new Date()} * * ``` * * @param {any} [children] - Optional content (typically a date) to render inside the component. * @param {Intl.DateTimeFormatOptions} [options={}] - Optional formatting options for the date, following `Intl.DateTimeFormatOptions` specifications. * @returns {Promise} The formatted date or time component. */ export declare const DateTime: typeof _DateTime; /** * The `` component renders a localized relative time string * (e.g., "2 hours ago", "in 3 days") using `Intl.RelativeTimeFormat`. * * @example * ```jsx * * ``` * * @param {Date} [date] - A date to compute relative time from now. * @param {number} [value] - Explicit numeric value. Requires `unit`. * @param {Intl.RelativeTimeFormatUnit} [unit] - The unit of time. * @param {Date} [baseDate] - Base date for computing relative time. Defaults to `new Date()` at render time. Required for hydration safety. * @param {Intl.RelativeTimeFormatOptions} [options={}] - Formatting options. * @returns {Promise} The formatted relative time component. */ export declare const RelativeTime: typeof _RelativeTime; /** * The `` component renders a formatted number string, allowing customization of the name, default value, and formatting options. * It formats the number according to the current locale and optionally passed formatting options. * * @example * ```jsx * * 1000 * * ``` * * @param {any} [children] - Optional content (typically a number) to render inside the component. * @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options for the number, following `Intl.NumberFormatOptions` specifications. * @returns {React.JSX.Element} The formatted number component. */ export declare const Num: typeof _Num; /** * The `` component renders a variable value, which can either be passed as `children` or a `value`. * If `children` is provided, it will be used; otherwise, the `value` is rendered. * * @example * ```jsx * * John * * ``` * * @param {any} [children] - The content to render inside the component. If provided, it will take precedence over `value`. * @returns {React.JSX.Element} The rendered variable component with either `children` or `value`. */ export declare const Var: typeof _Var; export declare const GtInternalVar: typeof _GtInternalVar; /** * Marks JSX children as derivable by the GT compiler and CLI. * * Use `` inside translated JSX when child content is computed from * source code, but should still be discovered during extraction instead of * treated as a runtime interpolation variable. The CLI attempts to resolve the * derivable children into every possible static value and includes those values * in the source content that gets translated. * * `` renders its children unchanged at runtime. * * Run `gt validate` after adding or changing `` usage to verify that * each derivable expression can be resolved by the CLI before translating or * building. * * @example * ```jsx * function getSubject() { * return (Math.random() > 0.5) ? "Alice" : "Brian"; * } * ... * * * {getSubject()} * * is going to school today. * * ``` * * @param {T extends React.ReactNode} children - JSX content to derive for translation extraction. * @returns {T} The same children, unchanged at runtime. */ export declare const Derive: typeof _Derive; /** * The `` component dynamically renders a specified branch of content or a fallback child component. * It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`). * If the specified `branch` is present in the `branches` object, it renders the content of that branch. * If the `branch` is not found, it renders the provided `children` as fallback content. * * @example * ```jsx * This is a summary

} * details={

Details here

} * > *

Fallback content

*
* ``` * If the `branch` prop is set to `"summary"`, it will render `

This is a summary

`. If the `branch` is not set or does not match any keys in the branches object, it renders the fallback content `

Fallback content

`. * * @param {any} [children] - Fallback content to render if no matching branch is found. * @param {string} [name="branch"] - Optional name for the component, used for metadata or tracking purposes. * @param {string} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object. * @param {...{[key: string]: any}} [branches] - A spread object containing possible branches as keys and their corresponding content as values. * @returns {React.JSX.Element} The rendered branch or fallback content. */ export declare const Branch: typeof _Branch; /** * The `` component dynamically renders content based on the plural form of the given number (`n`). * It determines which content to display by matching the value of `n` to the appropriate pluralization branch, * based on the current locale or a default locale. If no matching plural branch is found, the component renders * the fallback `children` content. * * @example * ```jsx * * ``` * In this example, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders * `"There are {n} items"`. * * @param {any} [children] - Fallback content to render if no matching plural branch is found. * @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work. * @param {string} [locale] - Optional parameter, the locale to use for pluralization format. * @param {...{[key: string]: any}} [branches] - A spread object containing possible plural branches, typically including `one` for singular * and `other` for plural forms, but it may vary depending on the locale. * @returns {React.JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content. * @throws {Error} If `n` is not provided or not a valid number. */ export declare const Plural: typeof _Plural; /** * A dropdown component that allows users to select a locale. * @param {string[]} locales - An optional list of locales to use for the dropdown. If not provided, the list of locales from the `` context is used. * @param {object} customNames - An optional object to map locales to custom names. * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering. */ export declare const LocaleSelector: typeof _LocaleSelector; /** * A dropdown component that allows users to select a region. * @param {string[]} regions - An optional list of ISO 3166 region codes to use for the dropdown. If not provided, regions are inferred from the supported locales in the `` context. * @returns {React.ReactElement | null} The rendered region dropdown component or null to prevent rendering. */ export declare const RegionSelector: typeof _RegionSelector; /** * Read the active locale resolved by Next.js internationalized routing. * * @param context - The GetServerSideProps context for the request. * @returns The active Next.js locale, or the legacy request-detected locale * when Next.js does not provide one. */ export declare function parseLocale(_: GetServerSidePropsContext): string; /** * Wraps a Pages Router `getServerSideProps` function and adds the resolved GT * locale and translations snapshot to returned page props. */ export declare function withGTServerSideProps = Record, Params extends ParsedUrlQuery = ParsedUrlQuery, Preview extends PreviewData = PreviewData>(_?: GetServerSideProps): GetServerSideProps, Params, Preview>; /** * Wraps a Pages Router `getStaticProps` function and adds the generated locale * and its translation snapshot. The default locale uses an empty snapshot. */ export declare const withGTStaticProps: WithGTStaticPropsFunction; /** * Checks whether a locale is valid and supported by the current gt-next config. * * @param locale - The locale candidate to validate. * @returns True when the locale resolves to one of the configured locales. */ export declare function isLocaleSupported(_: unknown): boolean; /** * Returns the string translation function `t`. * * @returns {Function} A translation function that accepts an ICU format string and returns that ICU format string translated. * @param {GTTranslationOptions} [options] - Translation options including variables and special `$`-prefixed options. * @param {string} [options.$context] - Additional context for the translation. * @param {string} [options.$id] - Optional identifier for the translation string. * @param {number} [options.$maxChars] - Maximum number of characters for the translated message. * @param {boolean} [options.$requiresReview] - Whether the translated message requires approval before use. Must be a boolean literal. * @param {StringFormat} [options.$format] - The data format for the message (e.g., 'ICU', 'STRING'). Defaults to 'ICU'. * * @example * const t = useGT(); * console.log(t('To be or not to be...')); * * const t = useGT(); * return (<> * { * t('My name is {customName}', { customName: "Brian" } ) * } * ); * */ export declare const useGT: (_messages?: Messages) => (message: string, options?: GTTranslationOptions) => string; /** * Returns the dictionary access function `t`. * * @param {string} [id] - Optional prefix to prepend to the translation keys. * @returns {Function} A translation function that accepts a key string and returns the translated value. * The returned function accepts interpolation variables. * * @example * const t = useTranslations('user'); * console.log(t('name')); // Translates item 'user.name' * * const t = useTranslations(); * console.log(t('hello')); // Translates item 'hello' */ export declare const useTranslations: typeof _useTranslations; /** * Returns the user's current locale. * * @returns {string} BCP 47 locale tag, e.g., 'en-US'. * * @example * const locale = useLocale(); * console.log(locale); // 'en-US' */ export declare const useLocale: typeof _useLocale; /** * Returns a function that localizes hrefs the same way `gt-next/link` does, * for navigation that does not render a ``, such as `router.push()` or * a Button `href`. Works in Server and Client Components. * * @example * const localizeHref = useLocalizeHref(); * localizeHref('/checkout'); // '/fr/checkout', or '/checkout' for the default locale */ export declare const useLocalizeHref: typeof _useLocalizeHref; export declare const useSetLocale: typeof _useSetLocale; export declare const useLocaleSelector: typeof _useLocaleSelector; /** * Returns the user's current region. * * @returns {string | undefined} ISO 3166 region code, e.g., 'US', or undefined if not set. * * @example * const region = useRegion(); * console.log(region); // 'US' */ export declare const useRegion: typeof _useRegion; /** * Returns the user's list of supported locales. * * @returns {string[]} List of BCP 47 locale tags, e.g., ['en-US', 'fr', 'jp']. * * @example * const locales = useLocales(); * console.log(locale); // ['en-US', 'fr', 'jp] */ export declare const useLocales: typeof _useLocales; /** * Returns the application's default locale. * * If no default locale is provided, it uses the library default locale. * * @returns {string} A BCP 47 locale tag, e.g., 'en-US'. * * @example * const locale = useDefaultLocale(); * console.log(locale); // 'en-US' */ export declare const useDefaultLocale: typeof _useDefaultLocale; /** * Returns the locale properties for the given locale. * * @param {string} locale - The locale to get the properties for. * @returns {LocaleProperties} The locale properties for the given locale. * * @example * const localeProperties = useLocaleProperties('en-US'); * console.log(localeProperties); */ export declare const useLocaleProperties: typeof _useLocaleProperties; /** * Retrieves the text direction ('ltr' or 'rtl') for the current or specified locale from the `` context. * * If no locale is provided, the direction for the current user's locale is returned. * * @param {string} [locale] - Optional locale code (e.g., 'ar', 'en-US'). If omitted, uses the current locale from context. * @returns {'ltr' | 'rtl'} The text direction for the locale: 'rtl' for right-to-left languages, otherwise 'ltr'. * * @example * const dir = useLocaleDirection(); // e.g., 'ltr' * const arabicDir = useLocaleDirection('ar'); // 'rtl' */ export declare const useLocaleDirection: typeof _useLocaleDirection; /** * Registers a message to be translated. Returns the message unchanged if no options are provided. * @param {string | string[]} message The message to encode. * @param {GTTranslationOptions} [options] The options to encode. * @returns The message or array of messages. * * @note - This function registers the message before the build process. The actual translation does not * occur until the m() function is invoked. * * @note - Message format * A message is broken into two parts separated by colons: * - interpolated content - the content with interpolated variables * - hash + options - a unique identifier for the source content and options for the translation * * @example - Basic usage * * const message1 = msg('Hello, World!'); * console.log(message1); // "Hello, World!" * * const message2 = msg('Hello, {name}!', { name: 'Brian' }); * console.log(message2); // "Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9" * * @example - Array usage * * const messages = msg(['Hello, Alice!', 'Hello, Bob!']); * console.log(messages); // ["Hello, Alice!", "Hello, Bob!"] * * @example - When specifying an id for an array, each message will have a unique id of `${id}.${index}` * const messages = msg(['Hello, Alice!', 'Hello, Bob!'], { $id: 'greetings' }); * // "Hello, Alice!" id: "greetings.0" * // "Hello, Bob!" id: "greetings.1" */ export declare const useMessages: (_messages?: Messages) => (encodedMsg: T, options?: GTTranslationOptions) => T extends string ? string : T; export type { GTTranslationOptions, RuntimeTranslationOptions, WithGTServerSideProps, WithGTStaticProps, }; export type { StringFormat }; export { msg, decodeMsg, decodeOptions, mFallback, gtFallback, derive, declareVar, decodeVars, getTranslationsSnapshot, getDefaultLocale, getLocaleProperties, getLocales, resolveCanonicalLocale, getVersionId, }; //# sourceMappingURL=index.types.d.ts.map