use-intl 0.0.0-canary-84fe6d0 → 0.0.0-canary-58b4a57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core.d.ts +2 -1
- package/dist/esm/development/core.js +70 -0
- package/dist/esm/development/index.js +7 -0
- package/dist/{development/createFormatter-QqAaZwGD.js → esm/development/initializeConfig-CRD6euuK.js} +292 -147
- package/dist/esm/development/react.js +184 -0
- package/dist/esm/production/core.js +1 -0
- package/dist/esm/production/index.js +1 -0
- package/dist/esm/production/initializeConfig-zfMDfl5R.js +1 -0
- package/dist/esm/production/react.js +1 -0
- package/dist/types/{src/core → core}/AbstractIntlMessages.d.ts +3 -2
- package/dist/types/core/AppConfig.d.ts +25 -0
- package/dist/types/{src/core → core}/DateTimeFormatOptions.d.ts +1 -1
- package/dist/types/{src/core → core}/Formats.d.ts +2 -2
- package/dist/types/core/ICUArgs.d.ts +3 -0
- package/dist/types/core/ICUTags.d.ts +2 -0
- package/dist/types/{src/core → core}/IntlConfig.d.ts +15 -19
- package/dist/types/core/IntlError.d.ts +6 -0
- package/dist/types/{src/core/IntlError.d.ts → core/IntlErrorCode.d.ts} +2 -6
- package/dist/types/core/MessageKeys.d.ts +10 -0
- package/dist/types/core/TranslationValues.d.ts +6 -0
- package/dist/types/{src/core → core}/convertFormatsToIntlMessageFormat.d.ts +4 -4
- package/dist/types/{src/core → core}/createBaseTranslator.d.ts +9 -12
- package/dist/types/core/createFormatter.d.ts +43 -0
- package/dist/types/core/createTranslator.d.ts +55 -0
- package/dist/types/core/createTranslatorImpl.d.ts +17 -0
- package/dist/types/{src/core → core}/defaults.d.ts +1 -1
- package/dist/types/{src/core → core}/formatters.d.ts +1 -1
- package/dist/types/core/hasLocale.d.ts +7 -0
- package/dist/types/core/index.d.ts +20 -0
- package/dist/types/core/initializeConfig.d.ts +14 -0
- package/dist/types/core/types.d.ts +6 -0
- package/dist/types/{src/core → core}/validateMessages.d.ts +2 -2
- package/dist/types/core.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/{src/react → react}/IntlContext.d.ts +2 -2
- package/dist/types/react/IntlProvider.d.ts +7 -0
- package/dist/types/react/index.d.ts +7 -0
- package/dist/types/{src/react → react}/useFormatter.d.ts +1 -1
- package/dist/types/{src/react → react}/useIntlContext.d.ts +1 -1
- package/dist/types/react/useLocale.d.ts +2 -0
- package/dist/types/react/useMessages.d.ts +2 -0
- package/dist/types/react/useNow.d.ts +8 -0
- package/dist/types/react/useTimeZone.d.ts +1 -0
- package/dist/types/react/useTranslations.d.ts +12 -0
- package/dist/types/react/useTranslationsImpl.d.ts +9 -0
- package/dist/types/react.d.ts +1 -0
- package/package.json +18 -24
- package/react.d.ts +2 -1
- package/_IntlProvider.d.ts +0 -1
- package/_useLocale.d.ts +0 -1
- package/dist/_IntlProvider.js +0 -7
- package/dist/_useLocale.js +0 -7
- package/dist/core.js +0 -7
- package/dist/development/IntlContext-BKfsnzBx.js +0 -7
- package/dist/development/_IntlProvider.js +0 -61
- package/dist/development/_useLocale-BK3jOeaA.js +0 -19
- package/dist/development/_useLocale.js +0 -11
- package/dist/development/core.js +0 -69
- package/dist/development/index.js +0 -31
- package/dist/development/initializeConfig-BhfMSHP7.js +0 -185
- package/dist/development/react.js +0 -151
- package/dist/esm/IntlContext-DoS4CDM3.js +0 -1
- package/dist/esm/_IntlProvider.js +0 -1
- package/dist/esm/_useLocale-7W3qm3h_.js +0 -1
- package/dist/esm/_useLocale.js +0 -1
- package/dist/esm/core.js +0 -1
- package/dist/esm/createFormatter-D4OO35MB.js +0 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/initializeConfig-D2A8plWf.js +0 -1
- package/dist/esm/react.js +0 -1
- package/dist/index.js +0 -7
- package/dist/production/IntlContext-DcFt0tgW.js +0 -1
- package/dist/production/_IntlProvider.js +0 -1
- package/dist/production/_useLocale-CpTrqBDt.js +0 -1
- package/dist/production/_useLocale.js +0 -1
- package/dist/production/core.js +0 -1
- package/dist/production/createFormatter-CZeYe_QF.js +0 -1
- package/dist/production/index.js +0 -1
- package/dist/production/initializeConfig-AbYTngyP.js +0 -1
- package/dist/production/react.js +0 -1
- package/dist/react.js +0 -7
- package/dist/types/src/_IntlProvider.d.ts +0 -1
- package/dist/types/src/_useLocale.d.ts +0 -1
- package/dist/types/src/core/TranslationValues.d.ts +0 -6
- package/dist/types/src/core/createFormatter.d.ts +0 -27
- package/dist/types/src/core/createFormatter.test.d.ts +0 -1
- package/dist/types/src/core/createTranslator.d.ts +0 -71
- package/dist/types/src/core/createTranslator.test.d.ts +0 -1
- package/dist/types/src/core/createTranslatorImpl.d.ts +0 -17
- package/dist/types/src/core/index.d.ts +0 -18
- package/dist/types/src/core/initializeConfig.d.ts +0 -13
- package/dist/types/src/core/utils/MessageKeys.d.ts +0 -5
- package/dist/types/src/core/utils/NamespaceKeys.d.ts +0 -5
- package/dist/types/src/core/utils/NestedKeyOf.d.ts +0 -4
- package/dist/types/src/core/utils/NestedValueOf.d.ts +0 -2
- package/dist/types/src/core.d.ts +0 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/react/IntlProvider.d.ts +0 -7
- package/dist/types/src/react/IntlProvider.test.d.ts +0 -1
- package/dist/types/src/react/index.d.ts +0 -7
- package/dist/types/src/react/index.test.d.ts +0 -1
- package/dist/types/src/react/useFormatter.test.d.ts +0 -1
- package/dist/types/src/react/useLocale.d.ts +0 -1
- package/dist/types/src/react/useLocale.test.d.ts +0 -1
- package/dist/types/src/react/useMessages.d.ts +0 -2
- package/dist/types/src/react/useMessages.test.d.ts +0 -1
- package/dist/types/src/react/useNow.d.ts +0 -23
- package/dist/types/src/react/useNow.test.d.ts +0 -1
- package/dist/types/src/react/useTimeZone.d.ts +0 -1
- package/dist/types/src/react/useTimeZone.test.d.ts +0 -1
- package/dist/types/src/react/useTranslations.d.ts +0 -62
- package/dist/types/src/react/useTranslations.test.d.ts +0 -1
- package/dist/types/src/react/useTranslationsImpl.d.ts +0 -9
- package/dist/types/src/react.d.ts +0 -1
- package/dist/types/test/setup.d.ts +0 -1
- /package/dist/types/{src/core → core}/NumberFormatOptions.d.ts +0 -0
- /package/dist/types/{src/core → core}/RelativeTimeFormatOptions.d.ts +0 -0
- /package/dist/types/{src/core → core}/TimeZone.d.ts +0 -0
- /package/dist/types/{src/core → core}/joinPath.d.ts +0 -0
- /package/dist/types/{src/core → core}/resolveNamespace.d.ts +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, useState, useEffect } from 'react';
|
|
2
|
+
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';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const IntlContext = /*#__PURE__*/createContext(undefined);
|
|
8
|
+
|
|
9
|
+
function IntlProvider({
|
|
10
|
+
children,
|
|
11
|
+
formats,
|
|
12
|
+
getMessageFallback,
|
|
13
|
+
locale,
|
|
14
|
+
messages,
|
|
15
|
+
now,
|
|
16
|
+
onError,
|
|
17
|
+
timeZone
|
|
18
|
+
}) {
|
|
19
|
+
const prevContext = useContext(IntlContext);
|
|
20
|
+
|
|
21
|
+
// The formatter cache is released when the locale changes. For
|
|
22
|
+
// long-running apps with a persistent `IntlProvider` at the root,
|
|
23
|
+
// this can reduce the memory footprint (e.g. in React Native).
|
|
24
|
+
const cache = useMemo(() => {
|
|
25
|
+
return prevContext?.cache || createCache();
|
|
26
|
+
}, [locale, prevContext?.cache]);
|
|
27
|
+
const formatters = useMemo(() => prevContext?.formatters || createIntlFormatters(cache), [cache, prevContext?.formatters]);
|
|
28
|
+
|
|
29
|
+
// Memoizing this value helps to avoid triggering a re-render of all
|
|
30
|
+
// context consumers in case the configuration didn't change. However,
|
|
31
|
+
// if some of the non-primitive values change, a re-render will still
|
|
32
|
+
// be triggered. Note that there's no need to put `memo` on `IntlProvider`
|
|
33
|
+
// itself, because the `children` typically change on every render.
|
|
34
|
+
// There's some burden on the consumer side if it's important to reduce
|
|
35
|
+
// re-renders, put that's how React works.
|
|
36
|
+
// See: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#context-updates-and-render-optimizations
|
|
37
|
+
const value = useMemo(() => ({
|
|
38
|
+
...initializeConfig({
|
|
39
|
+
locale,
|
|
40
|
+
// (required by provider)
|
|
41
|
+
formats: formats === undefined ? prevContext?.formats : formats,
|
|
42
|
+
getMessageFallback: getMessageFallback || prevContext?.getMessageFallback,
|
|
43
|
+
messages: messages === undefined ? prevContext?.messages : messages,
|
|
44
|
+
now: now || prevContext?.now,
|
|
45
|
+
onError: onError || prevContext?.onError,
|
|
46
|
+
timeZone: timeZone || prevContext?.timeZone
|
|
47
|
+
}),
|
|
48
|
+
formatters,
|
|
49
|
+
cache
|
|
50
|
+
}), [cache, formats, formatters, getMessageFallback, locale, messages, now, onError, prevContext, timeZone]);
|
|
51
|
+
return /*#__PURE__*/jsx(IntlContext.Provider, {
|
|
52
|
+
value: value,
|
|
53
|
+
children: children
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function useIntlContext() {
|
|
58
|
+
const context = useContext(IntlContext);
|
|
59
|
+
if (!context) {
|
|
60
|
+
throw new Error('No intl context found. Have you configured the provider? See https://next-intl.dev/docs/usage/configuration#server-client-components' );
|
|
61
|
+
}
|
|
62
|
+
return context;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let hasWarnedForMissingTimezone = false;
|
|
66
|
+
const isServer = typeof window === 'undefined';
|
|
67
|
+
function useTranslationsImpl(allMessagesPrefixed, namespacePrefixed, namespacePrefix) {
|
|
68
|
+
const {
|
|
69
|
+
cache,
|
|
70
|
+
formats: globalFormats,
|
|
71
|
+
formatters,
|
|
72
|
+
getMessageFallback,
|
|
73
|
+
locale,
|
|
74
|
+
onError,
|
|
75
|
+
timeZone
|
|
76
|
+
} = useIntlContext();
|
|
77
|
+
|
|
78
|
+
// The `namespacePrefix` is part of the type system.
|
|
79
|
+
// See the comment in the hook invocation.
|
|
80
|
+
const allMessages = allMessagesPrefixed[namespacePrefix];
|
|
81
|
+
const namespace = resolveNamespace(namespacePrefixed, namespacePrefix);
|
|
82
|
+
if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
|
|
83
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
84
|
+
hasWarnedForMissingTimezone = true;
|
|
85
|
+
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` ));
|
|
86
|
+
}
|
|
87
|
+
const translate = useMemo(() => createBaseTranslator({
|
|
88
|
+
cache,
|
|
89
|
+
formatters,
|
|
90
|
+
getMessageFallback,
|
|
91
|
+
messages: allMessages,
|
|
92
|
+
namespace,
|
|
93
|
+
onError,
|
|
94
|
+
formats: globalFormats,
|
|
95
|
+
locale,
|
|
96
|
+
timeZone
|
|
97
|
+
}), [cache, formatters, getMessageFallback, allMessages, namespace, onError, globalFormats, locale, timeZone]);
|
|
98
|
+
return translate;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
103
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
104
|
+
*
|
|
105
|
+
* If no namespace is provided, all available messages are returned.
|
|
106
|
+
* The namespace can also indicate nesting by using a dot
|
|
107
|
+
* (e.g. `namespace.Component`).
|
|
108
|
+
*/
|
|
109
|
+
function useTranslations(namespace) {
|
|
110
|
+
const context = useIntlContext();
|
|
111
|
+
const messages = context.messages;
|
|
112
|
+
|
|
113
|
+
// We have to wrap the actual hook so the type inference for the optional
|
|
114
|
+
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
115
|
+
// The prefix ("!") is arbitrary.
|
|
116
|
+
// @ts-expect-error Use the explicit annotation instead
|
|
117
|
+
return useTranslationsImpl({
|
|
118
|
+
'!': messages
|
|
119
|
+
},
|
|
120
|
+
// @ts-expect-error
|
|
121
|
+
namespace ? `!.${namespace}` : '!', '!');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function useLocale() {
|
|
125
|
+
return useIntlContext().locale;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getNow() {
|
|
129
|
+
return new Date();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @see https://next-intl.dev/docs/usage/dates-times#relative-times-usenow
|
|
134
|
+
*/
|
|
135
|
+
function useNow(options) {
|
|
136
|
+
const updateInterval = options?.updateInterval;
|
|
137
|
+
const {
|
|
138
|
+
now: globalNow
|
|
139
|
+
} = useIntlContext();
|
|
140
|
+
const [now, setNow] = useState(globalNow || getNow());
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!updateInterval) return;
|
|
143
|
+
const intervalId = setInterval(() => {
|
|
144
|
+
setNow(getNow());
|
|
145
|
+
}, updateInterval);
|
|
146
|
+
return () => {
|
|
147
|
+
clearInterval(intervalId);
|
|
148
|
+
};
|
|
149
|
+
}, [globalNow, updateInterval]);
|
|
150
|
+
return updateInterval == null && globalNow ? globalNow : now;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function useTimeZone() {
|
|
154
|
+
return useIntlContext().timeZone;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function useMessages() {
|
|
158
|
+
const context = useIntlContext();
|
|
159
|
+
if (!context.messages) {
|
|
160
|
+
throw new Error('No messages found. Have you configured them correctly? See https://next-intl.dev/docs/configuration#messages' );
|
|
161
|
+
}
|
|
162
|
+
return context.messages;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function useFormatter() {
|
|
166
|
+
const {
|
|
167
|
+
formats,
|
|
168
|
+
formatters,
|
|
169
|
+
locale,
|
|
170
|
+
now: globalNow,
|
|
171
|
+
onError,
|
|
172
|
+
timeZone
|
|
173
|
+
} = useIntlContext();
|
|
174
|
+
return useMemo(() => createFormatter({
|
|
175
|
+
formats,
|
|
176
|
+
locale,
|
|
177
|
+
now: globalNow,
|
|
178
|
+
onError,
|
|
179
|
+
timeZone,
|
|
180
|
+
_formatters: formatters
|
|
181
|
+
}), [formats, formatters, globalNow, locale, onError, timeZone]);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { IntlProvider, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,e as s,f as r,b as t,d 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=o(),_formatters:i=t(a),getMessageFallback:m=r,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{o as _createCache,t as _createIntlFormatters,m as createTranslator,f as hasLocale};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{IntlMessageFormat as e}from"intl-messageformat";import{isValidElement as t,cloneElement as r}from"react";import{memoize as n,strategies as o}from"@formatjs/fast-memoize";class a extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),this.code=e,t&&(this.originalMessage=t)}}var s=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}(s||{});function i(...e){return e.filter(Boolean).join(".")}function u(e){return i(e.namespace,e.key)}function c(e){console.error(e)}function m(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function f(e,t){return n(e,{cache:(r=t,{create:()=>({get:e=>r[e],set(e,t){r[e]=t}})}),strategy:o.variadic});var r}function l(e,t){return f(((...t)=>new e(...t)),t)}function g(e){return{getDateTimeFormat:l(Intl.DateTimeFormat,e.dateTime),getNumberFormat:l(Intl.NumberFormat,e.number),getPluralRules:l(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:l(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:l(Intl.ListFormat,e.list),getDisplayNames:l(Intl.DisplayNames,e.displayNames)}}function I(e,t,r,n){const o=i(n,r);if(!t)throw new Error(o);let a=t;return r.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(o+` (${e})`);a=r})),a}function E(n){const o=function(e,t,r,n=c){try{if(!t)throw new Error(void 0);const n=r?I(e,t,r):t;if(!n)throw new Error(r);return n}catch(e){const t=new a(s.MISSING_MESSAGE,e.message);return n(t),t}}(n.locale,n.messages,n.namespace,n.onError);return function({cache:n,formats:o,formatters:i,getMessageFallback:c=u,locale:m,messagesOrError:l,namespace:g,onError:E,timeZone:S}){const T=l instanceof a;function N(e,t,r){const n=new a(t,r);return E(n),c({error:n,key:e,namespace:g})}function y(a,u,E){if(T)return c({error:l,key:a,namespace:g});const y=l;let A,M;try{A=I(m,y,a,g)}catch(e){return N(a,s.MISSING_MESSAGE,e.message)}if("object"==typeof A){let e,t;return e=Array.isArray(A)?s.INVALID_MESSAGE:s.INSUFFICIENT_PATH,N(a,e,t)}const F=function(e,t){return t?void 0:e}(A,u);if(F)return F;i.getMessageFormat||(i.getMessageFormat=function(t,r){return f(((...t)=>new e(t[0],t[1],t[2],{formatters:r,...t[3]})),t.message)}(n,i));try{M=i.getMessageFormat(A,m,function(t,r,n){const o=e.formats.date,a=e.formats.time,s={...t?.dateTime,...r?.dateTime},i={date:{...o,...s},time:{...a,...s},number:{...t?.number,...r?.number}};return n&&["date","time"].forEach((e=>{const t=i[e];for(const[e,r]of Object.entries(t))t[e]={timeZone:n,...r}})),i}(o,E,S),{formatters:{...i,getDateTimeFormat:(e,t)=>i.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(e){const t=e;return N(a,s.INVALID_MESSAGE,t.message)}try{const e=M.format(u?function(e){const n={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const n=s(e);return t(n)?r(n,{key:o+a++}):n}:s,n[o]=i})),n}(u):u);if(null==e)throw new Error(void 0);return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return N(a,s.FORMATTING_ERROR,e.message)}}function A(e,t,r){const n=y(e,t,r);return"string"!=typeof n?N(e,s.INVALID_MESSAGE,void 0):n}return A.rich=y,A.markup=(e,t,r)=>y(e,t,r),A.raw=e=>{if(T)return c({error:l,key:e,namespace:g});const t=l;try{return I(m,t,e,g)}catch(t){return N(e,s.MISSING_MESSAGE,t.message)}},A.has=e=>{if(T)return!1;try{return I(m,l,e,g),!0}catch{return!1}},A}({...n,messagesOrError:o})}function S(e,t){return e===t?void 0:e.slice((t+".").length)}const T=3600,N=86400,y=7*N,A=2628e3,M=7884e3,F=365*N,R={second:1,seconds:1,minute:60,minutes:60,hour:T,hours:T,day:N,days:N,week:y,weeks:y,month:A,months:A,quarter:M,quarters:M,year:F,years:F};function d(e){const{_cache:t=m(),_formatters:r=g(t),formats:n,locale:o,onError:i=c,timeZone:u}=e;function f(e){return e?.timeZone||(u?e={...e,timeZone:u}:i(new a(s.ENVIRONMENT_FALLBACK,void 0))),e}function l(e,t,r,n,o){let u;try{u=function(e,t,r){let n;if("string"==typeof t){const r=t;if(n=e?.[r],!n){const e=new a(s.MISSING_FORMAT,void 0);throw i(e),e}}else n=t;return r&&(n={...n,...r}),n}(r,e,t)}catch{return o()}try{return n(u)}catch(e){return i(new a(s.FORMATTING_ERROR,e.message)),o()}}function I(e,t,a){return l(t,a,n?.dateTime,(t=>(t=f(t),r.getDateTimeFormat(o,t).format(e))),(()=>String(e)))}function E(){return e.now?e.now:(i(new a(s.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:I,number:function(e,t,a){return l(t,a,n?.number,(t=>r.getNumberFormat(o,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let n,a;const s={};t instanceof Date||"number"==typeof t?n=new Date(t):t&&(n=null!=t.now?new Date(t.now):E(),a=t.unit,s.style=t.style,s.numberingSystem=t.numberingSystem),n||(n=E());const i=(new Date(e).getTime()-n.getTime())/1e3;a||(a=function(e){const t=Math.abs(e);return t<60?"second":t<T?"minute":t<N?"hour":t<y?"day":t<A?"week":t<F?"month":"year"}(i)),s.numeric="second"===a?"auto":"always";const u=function(e,t){return Math.round(e/R[t])}(i,a);return r.getRelativeTimeFormat(o,s).format(u,a)}catch(t){return i(new a(s.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t,a){const s=[],i=new Map;let u=0;for(const t of e){let e;"object"==typeof t?(e=String(u),i.set(e,t)):e=String(t),s.push(e),u++}return l(t,a,n?.list,(e=>{const t=r.getListFormat(o,e).formatToParts(s).map((e=>"literal"===e.type?e.value:i.get(e.value)||e.value));return i.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,a,s){return l(a,s,n?.dateTime,(n=>(n=f(n),r.getDateTimeFormat(o,n).formatRange(e,t))),(()=>[I(e),I(t)].join(" – ")))}}}function h({formats:e,getMessageFallback:t,messages:r,onError:n,...o}){return{...o,formats:e||void 0,messages:r||void 0,onError:n||c,getMessageFallback:t||u}}export{a as I,s as a,g as b,d as c,m as d,E as e,u as f,c as g,h as i,S as r};
|
|
@@ -0,0 +1 @@
|
|
|
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-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,6 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A generic type that describes the shape of messages.
|
|
2
3
|
*
|
|
3
|
-
* Optionally
|
|
4
|
+
* Optionally, messages can be strictly-typed in order to get type safety for message
|
|
4
5
|
* namespaces and keys. See https://next-intl.dev/docs/usage/typescript
|
|
5
6
|
*/
|
|
6
7
|
type AbstractIntlMessages = {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default interface AppConfig {
|
|
2
|
+
}
|
|
3
|
+
export type Locale = AppConfig extends {
|
|
4
|
+
Locale: infer AppLocale;
|
|
5
|
+
} ? AppLocale : string;
|
|
6
|
+
export type FormatNames = AppConfig extends {
|
|
7
|
+
Formats: infer AppFormats;
|
|
8
|
+
} ? {
|
|
9
|
+
dateTime: AppFormats extends {
|
|
10
|
+
dateTime: infer AppDateTimeFormats;
|
|
11
|
+
} ? keyof AppDateTimeFormats : string;
|
|
12
|
+
number: AppFormats extends {
|
|
13
|
+
number: infer AppNumberFormats;
|
|
14
|
+
} ? keyof AppNumberFormats : string;
|
|
15
|
+
list: AppFormats extends {
|
|
16
|
+
list: infer AppListFormats;
|
|
17
|
+
} ? keyof AppListFormats : string;
|
|
18
|
+
} : {
|
|
19
|
+
dateTime: string;
|
|
20
|
+
number: string;
|
|
21
|
+
list: string;
|
|
22
|
+
};
|
|
23
|
+
export type Messages = AppConfig extends {
|
|
24
|
+
Messages: infer AppMessages;
|
|
25
|
+
} ? AppMessages : Record<string, any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
2
|
-
import NumberFormatOptions from './NumberFormatOptions';
|
|
1
|
+
import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
|
|
2
|
+
import type NumberFormatOptions from './NumberFormatOptions.js';
|
|
3
3
|
type Formats = {
|
|
4
4
|
number?: Record<string, NumberFormatOptions>;
|
|
5
5
|
dateTime?: Record<string, DateTimeFormatOptions>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type Formats from './Formats';
|
|
3
|
-
import type IntlError from './IntlError';
|
|
4
|
-
import type TimeZone from './TimeZone';
|
|
5
|
-
import type {
|
|
1
|
+
import type { Locale, Messages } from './AppConfig.js';
|
|
2
|
+
import type Formats from './Formats.js';
|
|
3
|
+
import type IntlError from './IntlError.js';
|
|
4
|
+
import type TimeZone from './TimeZone.js';
|
|
5
|
+
import type { DeepPartial } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Should be used for entry points that configure the library.
|
|
8
8
|
*/
|
|
9
|
-
type IntlConfig
|
|
9
|
+
type IntlConfig = {
|
|
10
10
|
/** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
|
|
11
|
-
locale:
|
|
11
|
+
locale: Locale;
|
|
12
12
|
/** Global formats can be provided to achieve consistent
|
|
13
13
|
* formatting across components. */
|
|
14
|
-
formats?: Formats;
|
|
14
|
+
formats?: Formats | null;
|
|
15
15
|
/** 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`. */
|
|
16
16
|
timeZone?: TimeZone;
|
|
17
17
|
/** This callback will be invoked when an error is encountered during
|
|
@@ -38,21 +38,17 @@ type IntlConfig<Messages = AbstractIntlMessages> = {
|
|
|
38
38
|
*/
|
|
39
39
|
now?: Date;
|
|
40
40
|
/** All messages that will be available. */
|
|
41
|
-
messages?: Messages;
|
|
42
|
-
/** Global default values for translation values and rich text elements.
|
|
43
|
-
* Can be used for consistent usage or styling of rich text elements.
|
|
44
|
-
* Defaults will be overidden by locally provided values.
|
|
45
|
-
*
|
|
46
|
-
* @deprecated See https://next-intl.dev/docs/usage/messages#rich-text-reuse-tags
|
|
47
|
-
**/
|
|
48
|
-
defaultTranslationValues?: RichTranslationValues;
|
|
41
|
+
messages?: DeepPartial<Messages> | null;
|
|
49
42
|
};
|
|
43
|
+
/**
|
|
50
44
|
/**
|
|
51
45
|
* A stricter set of the configuration that should be used internally
|
|
52
46
|
* once defaults are assigned to `IntlConfiguration`.
|
|
53
47
|
*/
|
|
54
|
-
export type InitializedIntlConfig
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
export type InitializedIntlConfig = Omit<IntlConfig, 'formats' | 'messages' | 'onError' | 'getMessageFallback'> & {
|
|
49
|
+
formats?: NonNullable<IntlConfig['formats']>;
|
|
50
|
+
messages?: NonNullable<IntlConfig['messages']>;
|
|
51
|
+
onError: NonNullable<IntlConfig['onError']>;
|
|
52
|
+
getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>;
|
|
57
53
|
};
|
|
58
54
|
export default IntlConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
declare enum IntlErrorCode {
|
|
2
2
|
MISSING_MESSAGE = "MISSING_MESSAGE",
|
|
3
3
|
MISSING_FORMAT = "MISSING_FORMAT",
|
|
4
4
|
ENVIRONMENT_FALLBACK = "ENVIRONMENT_FALLBACK",
|
|
@@ -7,8 +7,4 @@ export declare enum IntlErrorCode {
|
|
|
7
7
|
INVALID_KEY = "INVALID_KEY",
|
|
8
8
|
FORMATTING_ERROR = "FORMATTING_ERROR"
|
|
9
9
|
}
|
|
10
|
-
export default
|
|
11
|
-
readonly code: IntlErrorCode;
|
|
12
|
-
readonly originalMessage: string | undefined;
|
|
13
|
-
constructor(code: IntlErrorCode, originalMessage?: string);
|
|
14
|
-
}
|
|
10
|
+
export default IntlErrorCode;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type NestedKeyOf<ObjectType> = ObjectType extends object ? {
|
|
2
|
+
[Property in keyof ObjectType]: `${Property & string}` | `${Property & string}.${NestedKeyOf<ObjectType[Property]>}`;
|
|
3
|
+
}[keyof ObjectType] : never;
|
|
4
|
+
export type NestedValueOf<ObjectType, Path extends string> = Path extends `${infer Cur}.${infer Rest}` ? Cur extends keyof ObjectType ? NestedValueOf<ObjectType[Cur], Rest> : never : Path extends keyof ObjectType ? ObjectType[Path] : never;
|
|
5
|
+
export type NamespaceKeys<ObjectType, AllKeys extends string> = {
|
|
6
|
+
[PropertyPath in AllKeys]: NestedValueOf<ObjectType, PropertyPath> extends string ? never : PropertyPath;
|
|
7
|
+
}[AllKeys];
|
|
8
|
+
export type MessageKeys<ObjectType, AllKeys extends string> = {
|
|
9
|
+
[PropertyPath in AllKeys]: NestedValueOf<ObjectType, PropertyPath> extends string ? PropertyPath : never;
|
|
10
|
+
}[AllKeys];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type TranslationValues = Record<string, string | number | Date>;
|
|
3
|
+
export type RichTagsFunction = (chunks: ReactNode) => ReactNode;
|
|
4
|
+
export type MarkupTagsFunction = (chunks: string) => string;
|
|
5
|
+
export type RichTranslationValues = Record<string, TranslationValues[string] | RichTagsFunction>;
|
|
6
|
+
export type MarkupTranslationValues = Record<string, TranslationValues[string] | MarkupTagsFunction>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Formats as IntlFormats } from 'intl-messageformat';
|
|
2
|
-
import Formats from './Formats';
|
|
3
|
-
import TimeZone from './TimeZone';
|
|
1
|
+
import { type Formats as IntlFormats } from 'intl-messageformat';
|
|
2
|
+
import type Formats from './Formats.js';
|
|
3
|
+
import type TimeZone from './TimeZone.js';
|
|
4
4
|
/**
|
|
5
5
|
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
6
6
|
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
@@ -8,4 +8,4 @@ import TimeZone from './TimeZone';
|
|
|
8
8
|
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
9
9
|
* to convert the format before `intl-messageformat` can be used.
|
|
10
10
|
*/
|
|
11
|
-
export default function convertFormatsToIntlMessageFormat(
|
|
11
|
+
export default function convertFormatsToIntlMessageFormat(globalFormats?: Formats, inlineFormats?: Formats, timeZone?: TimeZone): Partial<IntlFormats>;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
3
|
-
import Formats from './Formats';
|
|
4
|
-
import { InitializedIntlConfig } from './IntlConfig';
|
|
5
|
-
import IntlError from './IntlError';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import NestedKeyOf from './utils/NestedKeyOf';
|
|
10
|
-
import NestedValueOf from './utils/NestedValueOf';
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type AbstractIntlMessages from './AbstractIntlMessages.js';
|
|
3
|
+
import type Formats from './Formats.js';
|
|
4
|
+
import type { InitializedIntlConfig } from './IntlConfig.js';
|
|
5
|
+
import IntlError from './IntlError.js';
|
|
6
|
+
import type { MessageKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
|
|
7
|
+
import type { MarkupTranslationValues, RichTranslationValues, TranslationValues } from './TranslationValues.js';
|
|
8
|
+
import { type Formatters, type IntlCache } from './formatters.js';
|
|
11
9
|
export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
|
|
12
10
|
cache: IntlCache;
|
|
13
11
|
formatters: Formatters;
|
|
14
|
-
defaultTranslationValues?: RichTranslationValues;
|
|
15
12
|
namespace?: string;
|
|
16
13
|
messagesOrError: Messages | IntlError;
|
|
17
14
|
};
|
|
@@ -20,5 +17,5 @@ export default function createBaseTranslator<Messages extends AbstractIntlMessag
|
|
|
20
17
|
rich: (key: string, values?: RichTranslationValues, formats?: Formats) => ReactNode;
|
|
21
18
|
markup(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => ReactNode>[0], values: MarkupTranslationValues, formats?: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => ReactNode>[2]): string;
|
|
22
19
|
raw(key: string): any;
|
|
23
|
-
has(key:
|
|
20
|
+
has(key: string): boolean;
|
|
24
21
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { FormatNames, Locale } from './AppConfig.js';
|
|
3
|
+
import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
|
|
4
|
+
import type Formats from './Formats.js';
|
|
5
|
+
import IntlError from './IntlError.js';
|
|
6
|
+
import type NumberFormatOptions from './NumberFormatOptions.js';
|
|
7
|
+
import type RelativeTimeFormatOptions from './RelativeTimeFormatOptions.js';
|
|
8
|
+
import type TimeZone from './TimeZone.js';
|
|
9
|
+
import { type Formatters, type IntlCache } from './formatters.js';
|
|
10
|
+
type Props = {
|
|
11
|
+
locale: Locale;
|
|
12
|
+
timeZone?: TimeZone;
|
|
13
|
+
onError?(error: IntlError): void;
|
|
14
|
+
formats?: Formats;
|
|
15
|
+
now?: Date;
|
|
16
|
+
/** @private */
|
|
17
|
+
_formatters?: Formatters;
|
|
18
|
+
/** @private */
|
|
19
|
+
_cache?: IntlCache;
|
|
20
|
+
};
|
|
21
|
+
export default function createFormatter(props: Props): {
|
|
22
|
+
dateTime: {
|
|
23
|
+
(value: Date | number, options?: DateTimeFormatOptions): string;
|
|
24
|
+
(value: Date | number, format?: FormatNames["dateTime"], options?: DateTimeFormatOptions): string;
|
|
25
|
+
};
|
|
26
|
+
number: {
|
|
27
|
+
(value: number | bigint, options?: NumberFormatOptions): string;
|
|
28
|
+
(value: number | bigint, format?: FormatNames["number"], options?: NumberFormatOptions): string;
|
|
29
|
+
};
|
|
30
|
+
relativeTime: {
|
|
31
|
+
(date: number | Date, now?: RelativeTimeFormatOptions["now"]): string;
|
|
32
|
+
(date: number | Date, options?: RelativeTimeFormatOptions): string;
|
|
33
|
+
};
|
|
34
|
+
list: {
|
|
35
|
+
<Value extends string | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<ReactElement>;
|
|
36
|
+
<Value extends string | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, format?: FormatNames["list"], options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<ReactElement>;
|
|
37
|
+
};
|
|
38
|
+
dateTimeRange: {
|
|
39
|
+
(start: Date | number, end: Date | number, options?: DateTimeFormatOptions): string;
|
|
40
|
+
(start: Date | number, end: Date | number, format?: FormatNames["dateTime"], options?: DateTimeFormatOptions): string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type Formats from './Formats.js';
|
|
3
|
+
import type ICUArgs from './ICUArgs.js';
|
|
4
|
+
import type ICUTags from './ICUTags.js';
|
|
5
|
+
import type IntlConfig from './IntlConfig.js';
|
|
6
|
+
import type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
|
|
7
|
+
import type { MarkupTagsFunction, RichTagsFunction, TranslationValues } from './TranslationValues.js';
|
|
8
|
+
import { type Formatters, type IntlCache } from './formatters.js';
|
|
9
|
+
import type { Prettify } from './types.js';
|
|
10
|
+
type ICUArgsWithTags<MessageString extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = ICUArgs<MessageString, {
|
|
11
|
+
ICUArgument: string;
|
|
12
|
+
ICUNumberArgument: number;
|
|
13
|
+
ICUDateArgument: Date;
|
|
14
|
+
}> & ([TagsFn] extends [never] ? {} : ICUTags<MessageString, TagsFn>);
|
|
15
|
+
type OnlyOptional<T> = Partial<T> extends T ? true : false;
|
|
16
|
+
type TranslateArgs<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = string extends Value ? [
|
|
17
|
+
values?: Record<string, TranslationValues[string] | TagsFn>,
|
|
18
|
+
formats?: Formats
|
|
19
|
+
] : (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;
|
|
20
|
+
type IntlMessages = Record<string, any>;
|
|
21
|
+
type NamespacedMessageKeys<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never> = MessageKeys<NestedValueOf<{
|
|
22
|
+
'!': TranslatorMessages;
|
|
23
|
+
}, [
|
|
24
|
+
Namespace
|
|
25
|
+
] extends [never] ? '!' : `!.${Namespace}`>, NestedKeyOf<NestedValueOf<{
|
|
26
|
+
'!': TranslatorMessages;
|
|
27
|
+
}, [
|
|
28
|
+
Namespace
|
|
29
|
+
] extends [never] ? '!' : `!.${Namespace}`>>>;
|
|
30
|
+
type NamespacedValue<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>>, TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>> = NestedValueOf<TranslatorMessages, [
|
|
31
|
+
Namespace
|
|
32
|
+
] extends [never] ? TargetKey : `${Namespace}.${TargetKey}`>;
|
|
33
|
+
/**
|
|
34
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
35
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
36
|
+
*
|
|
37
|
+
* If no namespace is provided, all available messages are returned.
|
|
38
|
+
* The namespace can also indicate nesting by using a dot
|
|
39
|
+
* (e.g. `namespace.Component`).
|
|
40
|
+
*/
|
|
41
|
+
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'> & {
|
|
42
|
+
messages?: TranslatorMessages;
|
|
43
|
+
namespace?: Namespace;
|
|
44
|
+
/** @private */
|
|
45
|
+
_formatters?: Formatters;
|
|
46
|
+
/** @private */
|
|
47
|
+
_cache?: IntlCache;
|
|
48
|
+
}): {
|
|
49
|
+
<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>>): string;
|
|
50
|
+
rich<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, RichTagsFunction>): ReactNode;
|
|
51
|
+
markup<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, MarkupTagsFunction>): string;
|
|
52
|
+
raw<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): any;
|
|
53
|
+
has<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): boolean;
|
|
54
|
+
};
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type AbstractIntlMessages from './AbstractIntlMessages.js';
|
|
2
|
+
import type { InitializedIntlConfig } from './IntlConfig.js';
|
|
3
|
+
import type { NestedKeyOf } from './MessageKeys.js';
|
|
4
|
+
import type { Formatters, IntlCache } from './formatters.js';
|
|
5
|
+
export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
|
|
6
|
+
namespace: string;
|
|
7
|
+
messages: Messages;
|
|
8
|
+
formatters: Formatters;
|
|
9
|
+
cache: IntlCache;
|
|
10
|
+
};
|
|
11
|
+
export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ messages, namespace, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
|
|
12
|
+
<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;
|
|
13
|
+
rich: (key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode;
|
|
14
|
+
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;
|
|
15
|
+
raw(key: string): any;
|
|
16
|
+
has(key: string): boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Locale } from './AppConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a locale exists in a list of locales.
|
|
4
|
+
*
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
|
|
6
|
+
*/
|
|
7
|
+
export default function hasLocale<LocaleType extends Locale>(locales: ReadonlyArray<LocaleType>, candidate: unknown): candidate is LocaleType;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type { default as AbstractIntlMessages } from './AbstractIntlMessages.js';
|
|
2
|
+
export type { TranslationValues, RichTranslationValues, MarkupTranslationValues, RichTagsFunction, MarkupTagsFunction } from './TranslationValues.js';
|
|
3
|
+
export type { default as Formats } from './Formats.js';
|
|
4
|
+
export type { default as IntlConfig } from './IntlConfig.js';
|
|
5
|
+
export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions.js';
|
|
6
|
+
export type { default as NumberFormatOptions } from './NumberFormatOptions.js';
|
|
7
|
+
export { default as IntlError } from './IntlError.js';
|
|
8
|
+
export { default as IntlErrorCode } from './IntlErrorCode.js';
|
|
9
|
+
export { default as createTranslator } from './createTranslator.js';
|
|
10
|
+
export { default as createFormatter } from './createFormatter.js';
|
|
11
|
+
export { default as initializeConfig } from './initializeConfig.js';
|
|
12
|
+
export type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
|
|
13
|
+
export { createIntlFormatters as _createIntlFormatters } from './formatters.js';
|
|
14
|
+
export { createCache as _createCache } from './formatters.js';
|
|
15
|
+
export type { default as AppConfig, Locale, Messages } from './AppConfig.js';
|
|
16
|
+
export { default as hasLocale } from './hasLocale.js';
|
|
17
|
+
export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatOptions.js';
|
|
18
|
+
export type { default as Timezone } from './TimeZone.js';
|
|
19
|
+
export type { default as ICUArgs } from './ICUArgs.js';
|
|
20
|
+
export type { default as ICUTags } from './ICUTags.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type IntlConfig from './IntlConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enhances the incoming props with defaults.
|
|
4
|
+
*/
|
|
5
|
+
export default function initializeConfig<Props extends IntlConfig>({ formats, getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "formats" | "messages" | "onError" | "getMessageFallback"> & {
|
|
6
|
+
formats: NonNullable<IntlConfig["formats"]> | undefined;
|
|
7
|
+
messages: NonNullable<IntlConfig["messages"]> | undefined;
|
|
8
|
+
onError: (error: import("./IntlError.js").default) => void;
|
|
9
|
+
getMessageFallback: (info: {
|
|
10
|
+
error: import("./IntlError.js").default;
|
|
11
|
+
key: string;
|
|
12
|
+
namespace?: string;
|
|
13
|
+
}) => string;
|
|
14
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
2
|
-
import IntlError from './IntlError';
|
|
1
|
+
import type AbstractIntlMessages from './AbstractIntlMessages.js';
|
|
2
|
+
import IntlError from './IntlError.js';
|
|
3
3
|
export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './core/index.js';
|