Comparing version 4.0.0-beta-c8eb4ad to 4.0.0-beta-ca3fcd5
@@ -1,3 +0,3 @@ | ||
import { r as resolveNamespace, e as createBaseTranslator, d as createCache, b as createIntlFormatters, f as defaultGetMessageFallback, g as defaultOnError } from './initializeConfig-DSmAVNvj.js'; | ||
export { I as IntlError, a as IntlErrorCode, c as createFormatter, i as initializeConfig } from './initializeConfig-DSmAVNvj.js'; | ||
import { r as resolveNamespace, e as createBaseTranslator, d as createCache, b as createIntlFormatters, f as defaultGetMessageFallback, g as defaultOnError } from './initializeConfig-CRD6euuK.js'; | ||
export { I as IntlError, a as IntlErrorCode, c as createFormatter, i as initializeConfig } from './initializeConfig-CRD6euuK.js'; | ||
@@ -23,2 +23,5 @@ | ||
// This type is slightly more loose than `AbstractIntlMessages` | ||
// in order to avoid a type error. | ||
/** | ||
@@ -62,20 +65,5 @@ * Translates messages from the given namespace by using the ICU syntax. | ||
* | ||
* Additionally, in development, the provided locales are validated to | ||
* ensure they follow the Unicode language identifier standard. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale | ||
*/ | ||
function hasLocale(locales, candidate) { | ||
{ | ||
for (const locale of locales) { | ||
try { | ||
const constructed = new Intl.Locale(locale); | ||
if (!constructed.language) { | ||
throw new Error('Language is required'); | ||
} | ||
} catch { | ||
console.error(`Found invalid locale within provided \`locales\`: "${locale}"\nPlease ensure you're using a valid Unicode locale identifier (e.g. "en-US").`); | ||
} | ||
} | ||
} | ||
return locales.includes(candidate); | ||
@@ -82,0 +70,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export { I as IntlError, a as IntlErrorCode, d as _createCache, b as _createIntlFormatters, c as createFormatter, i as initializeConfig } from './initializeConfig-DSmAVNvj.js'; | ||
export { I as IntlError, a as IntlErrorCode, d as _createCache, b as _createIntlFormatters, c as createFormatter, i as initializeConfig } from './initializeConfig-CRD6euuK.js'; | ||
export { createTranslator, hasLocale } from './core.js'; | ||
@@ -3,0 +3,0 @@ export { IntlProvider, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations } from './react.js'; |
import { createContext, useContext, useMemo, useState, useEffect } from 'react'; | ||
import { d as createCache, b as createIntlFormatters, i as initializeConfig, r as resolveNamespace, I as IntlError, a as IntlErrorCode, e as createBaseTranslator, c as createFormatter } from './initializeConfig-DSmAVNvj.js'; | ||
import { d as createCache, b as createIntlFormatters, i as initializeConfig, r as resolveNamespace, I as IntlError, a as IntlErrorCode, e as createBaseTranslator, c as createFormatter } from './initializeConfig-CRD6euuK.js'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
@@ -41,5 +41,5 @@ | ||
// (required by provider) | ||
formats: formats || prevContext?.formats, | ||
formats: formats === undefined ? prevContext?.formats : formats, | ||
getMessageFallback: getMessageFallback || prevContext?.getMessageFallback, | ||
messages: messages || prevContext?.messages, | ||
messages: messages === undefined ? prevContext?.messages : messages, | ||
now: now || prevContext?.now, | ||
@@ -61,3 +61,3 @@ onError: onError || prevContext?.onError, | ||
if (!context) { | ||
throw new Error('No intl context found. Have you configured the provider? See https://next-intl-docs.vercel.app/docs/usage/configuration#server-client-components' ); | ||
throw new Error('No intl context found. Have you configured the provider? See https://next-intl.dev/docs/usage/configuration#server-client-components' ); | ||
} | ||
@@ -87,3 +87,3 @@ return context; | ||
hasWarnedForMissingTimezone = true; | ||
onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, `There is no \`timeZone\` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone` )); | ||
onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, `There is no \`timeZone\` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl.dev/docs/configuration#time-zone` )); | ||
} | ||
@@ -136,3 +136,3 @@ const translate = useMemo(() => createBaseTranslator({ | ||
/** | ||
* @see https://next-intl-docs.vercel.app/docs/usage/dates-times#relative-times-usenow | ||
* @see https://next-intl.dev/docs/usage/dates-times#relative-times-usenow | ||
*/ | ||
@@ -164,3 +164,3 @@ function useNow(options) { | ||
if (!context.messages) { | ||
throw new Error('No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages' ); | ||
throw new Error('No messages found. Have you configured them correctly? See https://next-intl.dev/docs/configuration#messages' ); | ||
} | ||
@@ -167,0 +167,0 @@ return context.messages; |
@@ -1,1 +0,1 @@ | ||
import{r as e,e as s,d as r,b as t,f as o,g as n}from"./initializeConfig-BE7tJS3N.js";export{I as IntlError,a as IntlErrorCode,c as createFormatter,i as initializeConfig}from"./initializeConfig-BE7tJS3N.js";function m({_cache:a=r(),_formatters:i=t(a),getMessageFallback:m=o,messages:c,namespace:f,onError:g=n,...l}){return function({messages:a,namespace:r,...t},o){return a=a[o],r=e(r,o),s({...t,messages:a,namespace:r})}({...l,onError:g,cache:a,formatters:i,getMessageFallback:m,messages:{"!":c},namespace:f?`!.${f}`:"!"},"!")}function f(e,a){return e.includes(a)}export{r as _createCache,t as _createIntlFormatters,m as createTranslator,f as hasLocale}; | ||
import{r as e,e as s,d as r,b as t,f as o,g as n}from"./initializeConfig-zfMDfl5R.js";export{I as IntlError,a as IntlErrorCode,c as createFormatter,i as initializeConfig}from"./initializeConfig-zfMDfl5R.js";function m({_cache:a=r(),_formatters:i=t(a),getMessageFallback:m=o,messages:c,namespace:f,onError:g=n,...l}){return function({messages:a,namespace:r,...t},o){return a=a[o],r=e(r,o),s({...t,messages:a,namespace:r})}({...l,onError:g,cache:a,formatters:i,getMessageFallback:m,messages:{"!":c},namespace:f?`!.${f}`:"!"},"!")}function f(e,a){return e.includes(a)}export{r as _createCache,t as _createIntlFormatters,m as createTranslator,f as hasLocale}; |
@@ -1,1 +0,1 @@ | ||
export{I as IntlError,a as IntlErrorCode,d as _createCache,b as _createIntlFormatters,c as createFormatter,i as initializeConfig}from"./initializeConfig-BE7tJS3N.js";export{createTranslator,hasLocale}from"./core.js";export{IntlProvider,useFormatter,useLocale,useMessages,useNow,useTimeZone,useTranslations}from"./react.js"; | ||
export{I as IntlError,a as IntlErrorCode,d as _createCache,b as _createIntlFormatters,c as createFormatter,i as initializeConfig}from"./initializeConfig-zfMDfl5R.js";export{createTranslator,hasLocale}from"./core.js";export{IntlProvider,useFormatter,useLocale,useMessages,useNow,useTimeZone,useTranslations}from"./react.js"; |
@@ -1,1 +0,1 @@ | ||
import{createContext as e,useContext as r,useMemo as o,useState as t,useEffect as n}from"react";import{d as a,b as s,i as c,r as i,I as m,a as f,e as l,c as u}from"./initializeConfig-BE7tJS3N.js";import{jsx as g}from"react/jsx-runtime";const w=e(void 0);function d({children:e,formats:t,getMessageFallback:n,locale:i,messages:m,now:f,onError:l,timeZone:u}){const d=r(w),E=o((()=>d?.cache||a()),[i,d?.cache]),h=o((()=>d?.formatters||s(E)),[E,d?.formatters]),p=o((()=>({...c({locale:i,formats:t||d?.formats,getMessageFallback:n||d?.getMessageFallback,messages:m||d?.messages,now:f||d?.now,onError:l||d?.onError,timeZone:u||d?.timeZone}),formatters:h,cache:E})),[E,t,h,n,i,m,f,l,d,u]);return g(w.Provider,{value:p,children:e})}function E(){const e=r(w);if(!e)throw new Error(void 0);return e}let h=!1;const p="undefined"==typeof window;function v(e){return function(e,r,t){const{cache:n,formats:a,formatters:s,getMessageFallback:c,locale:u,onError:g,timeZone:w}=E(),d=e[t],v=i(r,t);return w||h||!p||(h=!0,g(new m(f.ENVIRONMENT_FALLBACK,void 0))),o((()=>l({cache:n,formatters:s,getMessageFallback:c,messages:d,namespace:v,onError:g,formats:a,locale:u,timeZone:w})),[n,s,c,d,v,g,a,u,w])}({"!":E().messages},e?`!.${e}`:"!","!")}function Z(){return E().locale}function b(){return new Date}function F(e){const r=e?.updateInterval,{now:o}=E(),[a,s]=t(o||b());return n((()=>{if(!r)return;const e=setInterval((()=>{s(b())}),r);return()=>{clearInterval(e)}}),[o,r]),null==r&&o?o:a}function M(){return E().timeZone}function k(){const e=E();if(!e.messages)throw new Error(void 0);return e.messages}function I(){const{formats:e,formatters:r,locale:t,now:n,onError:a,timeZone:s}=E();return o((()=>u({formats:e,locale:t,now:n,onError:a,timeZone:s,_formatters:r})),[e,r,n,t,a,s])}export{d as IntlProvider,I as useFormatter,Z as useLocale,k as useMessages,F as useNow,M as useTimeZone,v as useTranslations}; | ||
import{createContext as e,useContext as r,useMemo as o,useState as t,useEffect as n}from"react";import{d as a,b as s,i as c,r as i,I as m,a as f,e as l,c as u}from"./initializeConfig-zfMDfl5R.js";import{jsx as g}from"react/jsx-runtime";const d=e(void 0);function w({children:e,formats:t,getMessageFallback:n,locale:i,messages:m,now:f,onError:l,timeZone:u}){const w=r(d),v=o((()=>w?.cache||a()),[i,w?.cache]),E=o((()=>w?.formatters||s(v)),[v,w?.formatters]),h=o((()=>({...c({locale:i,formats:void 0===t?w?.formats:t,getMessageFallback:n||w?.getMessageFallback,messages:void 0===m?w?.messages:m,now:f||w?.now,onError:l||w?.onError,timeZone:u||w?.timeZone}),formatters:E,cache:v})),[v,t,E,n,i,m,f,l,w,u]);return g(d.Provider,{value:h,children:e})}function v(){const e=r(d);if(!e)throw new Error(void 0);return e}let E=!1;const h="undefined"==typeof window;function p(e){return function(e,r,t){const{cache:n,formats:a,formatters:s,getMessageFallback:c,locale:u,onError:g,timeZone:d}=v(),w=e[t],p=i(r,t);return d||E||!h||(E=!0,g(new m(f.ENVIRONMENT_FALLBACK,void 0))),o((()=>l({cache:n,formatters:s,getMessageFallback:c,messages:w,namespace:p,onError:g,formats:a,locale:u,timeZone:d})),[n,s,c,w,p,g,a,u,d])}({"!":v().messages},e?`!.${e}`:"!","!")}function Z(){return v().locale}function b(){return new Date}function F(e){const r=e?.updateInterval,{now:o}=v(),[a,s]=t(o||b());return n((()=>{if(!r)return;const e=setInterval((()=>{s(b())}),r);return()=>{clearInterval(e)}}),[o,r]),null==r&&o?o:a}function M(){return v().timeZone}function k(){const e=v();if(!e.messages)throw new Error(void 0);return e.messages}function I(){const{formats:e,formatters:r,locale:t,now:n,onError:a,timeZone:s}=v();return o((()=>u({formats:e,locale:t,now:n,onError:a,timeZone:s,_formatters:r})),[e,r,n,t,a,s])}export{w as IntlProvider,I as useFormatter,Z as useLocale,k as useMessages,F as useNow,M as useTimeZone,p as useTranslations}; |
@@ -1,1 +0,1 @@ | ||
export * from './core/index.tsx'; | ||
export * from './core/index.js'; |
@@ -5,3 +5,3 @@ /** | ||
* Optionally, messages can be strictly-typed in order to get type safety for message | ||
* namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript | ||
* namespaces and keys. See https://next-intl.dev/docs/usage/typescript | ||
*/ | ||
@@ -8,0 +8,0 @@ type AbstractIntlMessages = { |
import { type Formats as IntlFormats } from 'intl-messageformat'; | ||
import type Formats from './Formats.tsx'; | ||
import type TimeZone from './TimeZone.tsx'; | ||
import type Formats from './Formats.js'; | ||
import type TimeZone from './TimeZone.js'; | ||
/** | ||
@@ -5,0 +5,0 @@ * `intl-messageformat` uses separate keys for `date` and `time`, but there's |
import { type ReactNode } from 'react'; | ||
import type AbstractIntlMessages from './AbstractIntlMessages.tsx'; | ||
import type Formats from './Formats.tsx'; | ||
import type { InitializedIntlConfig } from './IntlConfig.tsx'; | ||
import IntlError from './IntlError.tsx'; | ||
import type { MessageKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.tsx'; | ||
import type { MarkupTranslationValues, RichTranslationValues, TranslationValues } from './TranslationValues.tsx'; | ||
import { type Formatters, type IntlCache } from './formatters.tsx'; | ||
import type AbstractIntlMessages from './AbstractIntlMessages.js'; | ||
import type Formats from './Formats.js'; | ||
import type { InitializedIntlConfig } from './IntlConfig.js'; | ||
import IntlError from './IntlError.js'; | ||
import type { MessageKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js'; | ||
import type { MarkupTranslationValues, RichTranslationValues, TranslationValues } from './TranslationValues.js'; | ||
import { type Formatters, type IntlCache } from './formatters.js'; | ||
export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & { | ||
@@ -10,0 +10,0 @@ cache: IntlCache; |
import type { ReactElement } from 'react'; | ||
import type { FormatNames, Locale } from './AppConfig.tsx'; | ||
import type DateTimeFormatOptions from './DateTimeFormatOptions.tsx'; | ||
import type Formats from './Formats.tsx'; | ||
import IntlError from './IntlError.tsx'; | ||
import type NumberFormatOptions from './NumberFormatOptions.tsx'; | ||
import type RelativeTimeFormatOptions from './RelativeTimeFormatOptions.tsx'; | ||
import type TimeZone from './TimeZone.tsx'; | ||
import { type Formatters, type IntlCache } from './formatters.tsx'; | ||
import type { FormatNames, Locale } from './AppConfig.js'; | ||
import type DateTimeFormatOptions from './DateTimeFormatOptions.js'; | ||
import type Formats from './Formats.js'; | ||
import IntlError from './IntlError.js'; | ||
import type NumberFormatOptions from './NumberFormatOptions.js'; | ||
import type RelativeTimeFormatOptions from './RelativeTimeFormatOptions.js'; | ||
import type TimeZone from './TimeZone.js'; | ||
import { type Formatters, type IntlCache } from './formatters.js'; | ||
type Props = { | ||
@@ -22,8 +22,23 @@ locale: Locale; | ||
export default function createFormatter(props: Props): { | ||
dateTime: (value: Date | number, formatOrOptions?: FormatNames["dateTime"] | DateTimeFormatOptions) => string; | ||
number: (value: number | bigint, formatOrOptions?: FormatNames["number"] | NumberFormatOptions) => string; | ||
relativeTime: (date: number | Date, nowOrOptions?: RelativeTimeFormatOptions["now"] | RelativeTimeFormatOptions) => string; | ||
list: <Value extends string | ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, formatOrOptions?: FormatNames["list"] | Intl.ListFormatOptions) => Value extends string ? string : Iterable<ReactElement>; | ||
dateTimeRange: (start: Date | number, end: Date | number, formatOrOptions?: FormatNames["dateTime"] | DateTimeFormatOptions) => string; | ||
dateTime: { | ||
(value: Date | number, options?: DateTimeFormatOptions): string; | ||
(value: Date | number, format?: FormatNames["dateTime"], options?: DateTimeFormatOptions): string; | ||
}; | ||
number: { | ||
(value: number | bigint, options?: NumberFormatOptions): string; | ||
(value: number | bigint, format?: FormatNames["number"], options?: NumberFormatOptions): string; | ||
}; | ||
relativeTime: { | ||
(date: number | Date, now?: RelativeTimeFormatOptions["now"]): string; | ||
(date: number | Date, options?: RelativeTimeFormatOptions): string; | ||
}; | ||
list: { | ||
<Value extends string | ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<ReactElement>; | ||
<Value extends string | ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, format?: FormatNames["list"], options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<ReactElement>; | ||
}; | ||
dateTimeRange: { | ||
(start: Date | number, end: Date | number, options?: DateTimeFormatOptions): string; | ||
(start: Date | number, end: Date | number, format?: FormatNames["dateTime"], options?: DateTimeFormatOptions): string; | ||
}; | ||
}; | ||
export {}; |
import type { ReactNode } from 'react'; | ||
import type { Messages } from './AppConfig.tsx'; | ||
import type Formats from './Formats.tsx'; | ||
import type ICUArgs from './ICUArgs.tsx'; | ||
import type ICUTags from './ICUTags.tsx'; | ||
import type IntlConfig from './IntlConfig.tsx'; | ||
import type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.tsx'; | ||
import type { ICUArg, MarkupTagsFunction, RichTagsFunction } from './TranslationValues.tsx'; | ||
import { type Formatters, type IntlCache } from './formatters.tsx'; | ||
import type { Prettify } from './types.tsx'; | ||
import type Formats from './Formats.js'; | ||
import type ICUArgs from './ICUArgs.js'; | ||
import type ICUTags from './ICUTags.js'; | ||
import type IntlConfig from './IntlConfig.js'; | ||
import type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js'; | ||
import type { MarkupTagsFunction, RichTagsFunction, TranslationValues } from './TranslationValues.js'; | ||
import { type Formatters, type IntlCache } from './formatters.js'; | ||
import type { Prettify } from './types.js'; | ||
type ICUArgsWithTags<MessageString extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = ICUArgs<MessageString, { | ||
ICUArgument: string | number | boolean | Date; | ||
ICUArgument: string; | ||
ICUNumberArgument: number; | ||
ICUDateArgument: Date | number; | ||
ICUDateArgument: Date; | ||
}> & ([TagsFn] extends [never] ? {} : ICUTags<MessageString, TagsFn>); | ||
type OnlyOptional<T> = Partial<T> extends T ? true : false; | ||
type TranslateArgs<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = string extends Value ? [values?: Record<string, ICUArg | TagsFn>, formats?: Formats] : (Value extends any ? (key: ICUArgsWithTags<Value, TagsFn>) => void : never) extends (key: infer Args) => void ? OnlyOptional<Args> extends true ? [values?: undefined, formats?: Formats] : [values: Prettify<Args>, formats?: Formats] : never; | ||
type NamespacedMessageKeys<TranslatorMessages extends Messages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never> = MessageKeys<NestedValueOf<{ | ||
type TranslateArgs<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = string extends Value ? [ | ||
values?: Record<string, TranslationValues[string] | TagsFn>, | ||
formats?: Formats | ||
] : (Value extends any ? (key: ICUArgsWithTags<Value, TagsFn>) => void : never) extends (key: infer Args) => void ? OnlyOptional<Args> extends true ? [values?: undefined, formats?: Formats] : [values: Prettify<Args>, formats?: Formats] : never; | ||
type IntlMessages = Record<string, any>; | ||
type NamespacedMessageKeys<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never> = MessageKeys<NestedValueOf<{ | ||
'!': TranslatorMessages; | ||
@@ -27,3 +30,3 @@ }, [ | ||
] extends [never] ? '!' : `!.${Namespace}`>>>; | ||
type NamespacedValue<TranslatorMessages extends Messages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>>, TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>> = NestedValueOf<TranslatorMessages, [ | ||
type NamespacedValue<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>>, TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>> = NestedValueOf<TranslatorMessages, [ | ||
Namespace | ||
@@ -39,3 +42,3 @@ ] extends [never] ? TargetKey : `${Namespace}.${TargetKey}`>; | ||
*/ | ||
export default function createTranslator<const TranslatorMessages extends Messages = Messages, const Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<TranslatorMessages>, 'messages'> & { | ||
export default function createTranslator<const TranslatorMessages extends IntlMessages, const Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig, 'messages'> & { | ||
messages?: TranslatorMessages; | ||
@@ -42,0 +45,0 @@ namespace?: Namespace; |
@@ -1,5 +0,5 @@ | ||
import type AbstractIntlMessages from './AbstractIntlMessages.tsx'; | ||
import type { InitializedIntlConfig } from './IntlConfig.tsx'; | ||
import type { NestedKeyOf } from './MessageKeys.tsx'; | ||
import type { Formatters, IntlCache } from './formatters.tsx'; | ||
import type AbstractIntlMessages from './AbstractIntlMessages.js'; | ||
import type { InitializedIntlConfig } from './IntlConfig.js'; | ||
import type { NestedKeyOf } from './MessageKeys.js'; | ||
import type { Formatters, IntlCache } from './formatters.js'; | ||
export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & { | ||
@@ -12,7 +12,7 @@ namespace: string; | ||
export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ messages, namespace, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): { | ||
<TargetKey extends import("./MessageKeys.tsx").MessageKeys<import("./MessageKeys.tsx").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import("./MessageKeys.tsx").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues.tsx").TranslationValues, formats?: import("./Formats.tsx").default): string; | ||
rich: (key: string, values?: import("./TranslationValues.tsx").RichTranslationValues, formats?: import("./Formats.tsx").default) => import("react").ReactNode; | ||
markup(key: Parameters<(key: string, values?: import("./TranslationValues.tsx").RichTranslationValues, formats?: import("./Formats.tsx").default) => import("react").ReactNode>[0], values: import("./TranslationValues.tsx").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.tsx").RichTranslationValues, formats?: import("./Formats.tsx").default) => import("react").ReactNode>[2]): string; | ||
<TargetKey extends import("./MessageKeys.js").MessageKeys<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues.js").TranslationValues, formats?: import("./Formats.js").default): string; | ||
rich: (key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode; | ||
markup(key: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode>[0], values: import("./TranslationValues.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode>[2]): string; | ||
raw(key: string): any; | ||
has(key: string): boolean; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import type TimeZone from './TimeZone.tsx'; | ||
import type TimeZone from './TimeZone.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat |
@@ -1,2 +0,2 @@ | ||
import type IntlError from './IntlError.tsx'; | ||
import type IntlError from './IntlError.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Contains defaults that are used for all entry points into the core. |
@@ -1,3 +0,3 @@ | ||
import type DateTimeFormatOptions from './DateTimeFormatOptions.tsx'; | ||
import type NumberFormatOptions from './NumberFormatOptions.tsx'; | ||
import type DateTimeFormatOptions from './DateTimeFormatOptions.js'; | ||
import type NumberFormatOptions from './NumberFormatOptions.js'; | ||
type Formats = { | ||
@@ -4,0 +4,0 @@ number?: Record<string, NumberFormatOptions>; |
@@ -1,10 +0,7 @@ | ||
import type { Locale } from './AppConfig.tsx'; | ||
import type { Locale } from './AppConfig.js'; | ||
/** | ||
* Checks if a locale exists in a list of locales. | ||
* | ||
* Additionally, in development, the provided locales are validated to | ||
* ensure they follow the Unicode language identifier standard. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale | ||
*/ | ||
export default function hasLocale<LocaleType extends Locale>(locales: ReadonlyArray<LocaleType>, candidate?: string | null): candidate is LocaleType; | ||
export default function hasLocale<LocaleType extends Locale>(locales: ReadonlyArray<LocaleType>, candidate: unknown): candidate is LocaleType; |
@@ -1,20 +0,20 @@ | ||
export type { default as AbstractIntlMessages } from './AbstractIntlMessages.tsx'; | ||
export type { TranslationValues, ICUArg, RichTranslationValues, MarkupTranslationValues, RichTagsFunction, MarkupTagsFunction } from './TranslationValues.tsx'; | ||
export type { default as Formats } from './Formats.tsx'; | ||
export type { default as IntlConfig } from './IntlConfig.tsx'; | ||
export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions.tsx'; | ||
export type { default as NumberFormatOptions } from './NumberFormatOptions.tsx'; | ||
export { default as IntlError } from './IntlError.tsx'; | ||
export { default as IntlErrorCode } from './IntlErrorCode.tsx'; | ||
export { default as createTranslator } from './createTranslator.tsx'; | ||
export { default as createFormatter } from './createFormatter.tsx'; | ||
export { default as initializeConfig } from './initializeConfig.tsx'; | ||
export type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.tsx'; | ||
export { createIntlFormatters as _createIntlFormatters } from './formatters.tsx'; | ||
export { createCache as _createCache } from './formatters.tsx'; | ||
export type { default as AppConfig, Locale, Messages } from './AppConfig.tsx'; | ||
export { default as hasLocale } from './hasLocale.tsx'; | ||
export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatOptions.tsx'; | ||
export type { default as Timezone } from './TimeZone.tsx'; | ||
export type { default as ICUArgs } from './ICUArgs.tsx'; | ||
export type { default as ICUTags } from './ICUTags.tsx'; | ||
export type { default as AbstractIntlMessages } from './AbstractIntlMessages.js'; | ||
export type { TranslationValues, RichTranslationValues, MarkupTranslationValues, RichTagsFunction, MarkupTagsFunction } from './TranslationValues.js'; | ||
export type { default as Formats } from './Formats.js'; | ||
export type { default as IntlConfig } from './IntlConfig.js'; | ||
export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions.js'; | ||
export type { default as NumberFormatOptions } from './NumberFormatOptions.js'; | ||
export { default as IntlError } from './IntlError.js'; | ||
export { default as IntlErrorCode } from './IntlErrorCode.js'; | ||
export { default as createTranslator } from './createTranslator.js'; | ||
export { default as createFormatter } from './createFormatter.js'; | ||
export { default as initializeConfig } from './initializeConfig.js'; | ||
export type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js'; | ||
export { createIntlFormatters as _createIntlFormatters } from './formatters.js'; | ||
export { createCache as _createCache } from './formatters.js'; | ||
export type { default as AppConfig, Locale, Messages } from './AppConfig.js'; | ||
export { default as hasLocale } from './hasLocale.js'; | ||
export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatOptions.js'; | ||
export type { default as Timezone } from './TimeZone.js'; | ||
export type { default as ICUArgs } from './ICUArgs.js'; | ||
export type { default as ICUTags } from './ICUTags.js'; |
@@ -1,10 +0,11 @@ | ||
import type IntlConfig from './IntlConfig.tsx'; | ||
import type IntlConfig from './IntlConfig.js'; | ||
/** | ||
* Enhances the incoming props with defaults. | ||
*/ | ||
export default function initializeConfig<Props extends IntlConfig>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & { | ||
messages: import("./AbstractIntlMessages.tsx").default | undefined; | ||
onError: (error: import("./IntlError.tsx").default) => void; | ||
export default function initializeConfig<Props extends IntlConfig>({ formats, getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "formats" | "messages" | "onError" | "getMessageFallback"> & { | ||
formats: NonNullable<IntlConfig["formats"]> | undefined; | ||
messages: NonNullable<IntlConfig["messages"]> | undefined; | ||
onError: (error: import("./IntlError.js").default) => void; | ||
getMessageFallback: (info: { | ||
error: import("./IntlError.tsx").default; | ||
error: import("./IntlError.js").default; | ||
key: string; | ||
@@ -11,0 +12,0 @@ namespace?: string; |
@@ -1,10 +0,10 @@ | ||
import type AbstractIntlMessages from './AbstractIntlMessages.tsx'; | ||
import type { Locale } from './AppConfig.tsx'; | ||
import type Formats from './Formats.tsx'; | ||
import type IntlError from './IntlError.tsx'; | ||
import type TimeZone from './TimeZone.tsx'; | ||
import type { Locale, Messages } from './AppConfig.js'; | ||
import type Formats from './Formats.js'; | ||
import type IntlError from './IntlError.js'; | ||
import type TimeZone from './TimeZone.js'; | ||
import type { DeepPartial } from './types.js'; | ||
/** | ||
* Should be used for entry points that configure the library. | ||
*/ | ||
type IntlConfig<Messages = AbstractIntlMessages> = { | ||
type IntlConfig = { | ||
/** A valid Unicode locale tag (e.g. "en" or "en-GB"). */ | ||
@@ -14,3 +14,3 @@ locale: Locale; | ||
* formatting across components. */ | ||
formats?: Formats; | ||
formats?: Formats | null; | ||
/** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */ | ||
@@ -42,12 +42,15 @@ timeZone?: TimeZone; | ||
/** All messages that will be available. */ | ||
messages?: Messages; | ||
messages?: DeepPartial<Messages> | null; | ||
}; | ||
/** | ||
/** | ||
* A stricter set of the configuration that should be used internally | ||
* once defaults are assigned to `IntlConfiguration`. | ||
*/ | ||
export type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & { | ||
onError: NonNullable<IntlConfig<Messages>['onError']>; | ||
getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>; | ||
export type InitializedIntlConfig = Omit<IntlConfig, 'formats' | 'messages' | 'onError' | 'getMessageFallback'> & { | ||
formats?: NonNullable<IntlConfig['formats']>; | ||
messages?: NonNullable<IntlConfig['messages']>; | ||
onError: NonNullable<IntlConfig['onError']>; | ||
getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>; | ||
}; | ||
export default IntlConfig; |
@@ -1,2 +0,2 @@ | ||
import type IntlErrorCode from './IntlErrorCode.tsx'; | ||
import type IntlErrorCode from './IntlErrorCode.js'; | ||
export default class IntlError extends Error { | ||
@@ -3,0 +3,0 @@ readonly code: IntlErrorCode; |
import type { ReactNode } from 'react'; | ||
export type ICUArg = string | number | boolean | Date; | ||
export type TranslationValues = Record<string, ICUArg>; | ||
export type TranslationValues = Record<string, string | number | Date>; | ||
export type RichTagsFunction = (chunks: ReactNode) => ReactNode; | ||
export type MarkupTagsFunction = (chunks: string) => string; | ||
export type RichTranslationValues = Record<string, ICUArg | RichTagsFunction>; | ||
export type MarkupTranslationValues = Record<string, ICUArg | MarkupTagsFunction>; | ||
export type RichTranslationValues = Record<string, TranslationValues[string] | RichTagsFunction>; | ||
export type MarkupTranslationValues = Record<string, TranslationValues[string] | MarkupTagsFunction>; |
export type Prettify<T> = { | ||
[K in keyof T]: T[K]; | ||
} & {}; | ||
export type DeepPartial<Type> = { | ||
[Key in keyof Type]?: Type[Key] extends object ? DeepPartial<Type[Key]> : Type[Key]; | ||
}; |
@@ -1,3 +0,3 @@ | ||
import type AbstractIntlMessages from './AbstractIntlMessages.tsx'; | ||
import IntlError from './IntlError.tsx'; | ||
import type AbstractIntlMessages from './AbstractIntlMessages.js'; | ||
import IntlError from './IntlError.js'; | ||
export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void; |
@@ -1,2 +0,2 @@ | ||
export * from './core.tsx'; | ||
export * from './react.tsx'; | ||
export * from './core.js'; | ||
export * from './react.js'; |
@@ -1,1 +0,1 @@ | ||
export * from './react/index.tsx'; | ||
export * from './react/index.js'; |
@@ -1,7 +0,7 @@ | ||
export { default as IntlProvider } from './IntlProvider.tsx'; | ||
export { default as useTranslations } from './useTranslations.tsx'; | ||
export { default as useLocale } from './useLocale.tsx'; | ||
export { default as useNow } from './useNow.tsx'; | ||
export { default as useTimeZone } from './useTimeZone.tsx'; | ||
export { default as useMessages } from './useMessages.tsx'; | ||
export { default as useFormatter } from './useFormatter.tsx'; | ||
export { default as IntlProvider } from './IntlProvider.js'; | ||
export { default as useTranslations } from './useTranslations.js'; | ||
export { default as useLocale } from './useLocale.js'; | ||
export { default as useNow } from './useNow.js'; | ||
export { default as useTimeZone } from './useTimeZone.js'; | ||
export { default as useMessages } from './useMessages.js'; | ||
export { default as useFormatter } from './useFormatter.js'; |
@@ -1,3 +0,3 @@ | ||
import type { InitializedIntlConfig } from '../core/IntlConfig.tsx'; | ||
import type { Formatters, IntlCache } from '../core/formatters.tsx'; | ||
import type { InitializedIntlConfig } from '../core/IntlConfig.js'; | ||
import type { Formatters, IntlCache } from '../core/formatters.js'; | ||
export type IntlContextValue = InitializedIntlConfig & { | ||
@@ -4,0 +4,0 @@ formatters: Formatters; |
import { type ReactNode } from 'react'; | ||
import type IntlConfig from '../core/IntlConfig.tsx'; | ||
import type IntlConfig from '../core/IntlConfig.js'; | ||
type Props = IntlConfig & { | ||
@@ -4,0 +4,0 @@ children: ReactNode; |
@@ -1,2 +0,2 @@ | ||
import createFormatter from '../core/createFormatter.tsx'; | ||
import createFormatter from '../core/createFormatter.js'; | ||
export default function useFormatter(): ReturnType<typeof createFormatter>; |
@@ -1,2 +0,2 @@ | ||
import { type IntlContextValue } from './IntlContext.tsx'; | ||
import { type IntlContextValue } from './IntlContext.js'; | ||
export default function useIntlContext(): IntlContextValue; |
@@ -1,2 +0,2 @@ | ||
import type { Locale } from '../core.tsx'; | ||
import type { Locale } from '../core.js'; | ||
export default function useLocale(): Locale; |
@@ -1,2 +0,2 @@ | ||
import type { Messages } from '../core/AppConfig.tsx'; | ||
import type { Messages } from '../core/AppConfig.js'; | ||
export default function useMessages(): Messages; |
@@ -5,5 +5,5 @@ type Options = { | ||
/** | ||
* @see https://next-intl-docs.vercel.app/docs/usage/dates-times#relative-times-usenow | ||
* @see https://next-intl.dev/docs/usage/dates-times#relative-times-usenow | ||
*/ | ||
export default function useNow(options?: Options): Date; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
export default function useTimeZone(): import("../core.tsx").Timezone | undefined; | ||
export default function useTimeZone(): import("../core.js").Timezone | undefined; |
@@ -1,4 +0,4 @@ | ||
import type { Messages } from '../core/AppConfig.tsx'; | ||
import type { NamespaceKeys, NestedKeyOf } from '../core/MessageKeys.tsx'; | ||
import type createTranslator from '../core/createTranslator.tsx'; | ||
import type { Messages } from '../core/AppConfig.js'; | ||
import type { NamespaceKeys, NestedKeyOf } from '../core/MessageKeys.js'; | ||
import type createTranslator from '../core/createTranslator.js'; | ||
/** | ||
@@ -5,0 +5,0 @@ * Translates messages from the given namespace by using the ICU syntax. |
@@ -1,9 +0,9 @@ | ||
import type AbstractIntlMessages from '../core/AbstractIntlMessages.tsx'; | ||
import type { NestedKeyOf } from '../core/MessageKeys.tsx'; | ||
import type AbstractIntlMessages from '../core/AbstractIntlMessages.js'; | ||
import type { NestedKeyOf } from '../core/MessageKeys.js'; | ||
export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): { | ||
<TargetKey extends unknown>(key: TargetKey, values?: import("../core.tsx").TranslationValues, formats?: import("../core.tsx").Formats): string; | ||
rich: (key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode; | ||
markup(key: Parameters<(key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode>[0], values: import("../core.tsx").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode>[2]): string; | ||
<TargetKey extends unknown>(key: TargetKey, values?: import("../core.js").TranslationValues, formats?: import("../core.js").Formats): string; | ||
rich: (key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode; | ||
markup(key: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode>[0], values: import("../core.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode>[2]): string; | ||
raw(key: string): any; | ||
has(key: string): boolean; | ||
}; |
{ | ||
"name": "use-intl", | ||
"version": "4.0.0-beta-c8eb4ad", | ||
"version": "4.0.0-beta-ca3fcd5", | ||
"sideEffects": false, | ||
@@ -8,3 +8,3 @@ "author": "Jan Amann <jan@amann.work>", | ||
"license": "MIT", | ||
"homepage": "https://next-intl-docs.vercel.app/", | ||
"homepage": "https://next-intl.dev", | ||
"repository": { | ||
@@ -66,5 +66,5 @@ "type": "git", | ||
"peerDependencies": { | ||
"react": "^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0" | ||
"react": "^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0 || ^19.0.0" | ||
}, | ||
"gitHead": "0f3e1b49035abd86291ea92248a9b042e53fc549" | ||
"gitHead": "9ed16adf3aee9906edc15b1b1a29111a8e2cfef9" | ||
} |
@@ -83,2 +83,2 @@ # 🌐 use-intl | ||
### [→ Read the docs](https://next-intl-docs.vercel.app/docs/environments/core-library) | ||
### [→ Read the docs](https://next-intl.dev/docs/environments/core-library) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1489
83223
1