@depup/use-intl 4.13.3-depup.0
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/LICENSE +21 -0
- package/README.md +33 -0
- package/changes.json +18 -0
- package/core.d.ts +2 -0
- package/dist/esm/development/core.js +76 -0
- package/dist/esm/development/format-message/format-only.js +145 -0
- package/dist/esm/development/format-message/index.js +138 -0
- package/dist/esm/development/formatters-r4aAmsMP.js +79 -0
- package/dist/esm/development/index.js +8 -0
- package/dist/esm/development/initializeConfig-CUsOI8u2.js +527 -0
- package/dist/esm/development/react.js +231 -0
- package/dist/esm/production/core.js +1 -0
- package/dist/esm/production/format-message/format-only.js +1 -0
- package/dist/esm/production/format-message/index.js +1 -0
- package/dist/esm/production/formatters-CJcico0N.js +1 -0
- package/dist/esm/production/index.js +1 -0
- package/dist/esm/production/initializeConfig-CHgjheii.js +1 -0
- package/dist/esm/production/react.js +1 -0
- package/dist/types/core/AbstractIntlMessages.d.ts +10 -0
- package/dist/types/core/AppConfig.d.ts +29 -0
- package/dist/types/core/DateTimeFormatOptions.d.ts +73 -0
- package/dist/types/core/Formats.d.ts +9 -0
- package/dist/types/core/ICUArgs.d.ts +3 -0
- package/dist/types/core/ICUTags.d.ts +2 -0
- package/dist/types/core/IntlConfig.d.ts +54 -0
- package/dist/types/core/IntlError.d.ts +6 -0
- package/dist/types/core/IntlErrorCode.d.ts +10 -0
- package/dist/types/core/MessageKeys.d.ts +10 -0
- package/dist/types/core/NumberFormatOptions.d.ts +3 -0
- package/dist/types/core/RelativeTimeFormatOptions.d.ts +7 -0
- package/dist/types/core/TimeZone.d.ts +2 -0
- package/dist/types/core/TranslationValues.d.ts +6 -0
- package/dist/types/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
- package/dist/types/core/createBaseTranslator.d.ts +21 -0
- package/dist/types/core/createFormatter.d.ts +47 -0
- package/dist/types/core/createTranslator.d.ts +59 -0
- package/dist/types/core/createTranslatorImpl.d.ts +17 -0
- package/dist/types/core/defaults.d.ts +11 -0
- package/dist/types/core/format-message/compile-format.d.ts +12 -0
- package/dist/types/core/format-message/format-only.d.ts +13 -0
- package/dist/types/core/format-message/index.d.ts +5 -0
- package/dist/types/core/format-message/types.d.ts +15 -0
- package/dist/types/core/formatters.d.ts +25 -0
- package/dist/types/core/hasLocale.d.ts +7 -0
- package/dist/types/core/index.d.ts +22 -0
- package/dist/types/core/initializeConfig.d.ts +14 -0
- package/dist/types/core/joinPath.d.ts +1 -0
- package/dist/types/core/resolveNamespace.d.ts +5 -0
- package/dist/types/core/types.d.ts +6 -0
- package/dist/types/core/validateMessages.d.ts +3 -0
- package/dist/types/core.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/react/IntlContext.d.ts +8 -0
- package/dist/types/react/IntlProvider.d.ts +7 -0
- package/dist/types/react/index.d.ts +9 -0
- package/dist/types/react/useExtracted.d.ts +42 -0
- package/dist/types/react/useFormatter.d.ts +2 -0
- package/dist/types/react/useIntlContext.d.ts +2 -0
- 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/format-message/format-only.d.ts +2 -0
- package/format-message.d.ts +2 -0
- package/package.json +115 -0
- package/react.d.ts +2 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, useState, useEffect } from 'react';
|
|
2
|
+
import { b as createCache, c as createIntlFormatters, I as IntlError, a as IntlErrorCode } from './formatters-r4aAmsMP.js';
|
|
3
|
+
import { i as initializeConfig, r as resolveNamespace, a as createBaseTranslator, c as createFormatter } from './initializeConfig-CUsOI8u2.js';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const IntlContext = /*#__PURE__*/createContext(undefined);
|
|
9
|
+
|
|
10
|
+
function IntlProvider({
|
|
11
|
+
children,
|
|
12
|
+
formats,
|
|
13
|
+
getMessageFallback,
|
|
14
|
+
locale,
|
|
15
|
+
messages,
|
|
16
|
+
now,
|
|
17
|
+
onError,
|
|
18
|
+
timeZone
|
|
19
|
+
}) {
|
|
20
|
+
const prevContext = useContext(IntlContext);
|
|
21
|
+
|
|
22
|
+
// The formatter cache is released when the locale changes. For
|
|
23
|
+
// long-running apps with a persistent `IntlProvider` at the root,
|
|
24
|
+
// this can reduce the memory footprint (e.g. in React Native).
|
|
25
|
+
const cache = useMemo(() => {
|
|
26
|
+
return prevContext?.cache || createCache();
|
|
27
|
+
}, [locale, prevContext?.cache]);
|
|
28
|
+
const formatters = useMemo(() => prevContext?.formatters || createIntlFormatters(cache), [cache, prevContext?.formatters]);
|
|
29
|
+
|
|
30
|
+
// Memoizing this value helps to avoid triggering a re-render of all
|
|
31
|
+
// context consumers in case the configuration didn't change. However,
|
|
32
|
+
// if some of the non-primitive values change, a re-render will still
|
|
33
|
+
// be triggered. Note that there's no need to put `memo` on `IntlProvider`
|
|
34
|
+
// itself, because the `children` typically change on every render.
|
|
35
|
+
// There's some burden on the consumer side if it's important to reduce
|
|
36
|
+
// re-renders, put that's how React works.
|
|
37
|
+
// See: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#context-updates-and-render-optimizations
|
|
38
|
+
const value = useMemo(() => ({
|
|
39
|
+
...initializeConfig({
|
|
40
|
+
locale,
|
|
41
|
+
// (required by provider)
|
|
42
|
+
formats: formats === undefined ? prevContext?.formats : formats,
|
|
43
|
+
getMessageFallback: getMessageFallback || prevContext?.getMessageFallback,
|
|
44
|
+
messages: messages === undefined ? prevContext?.messages : messages,
|
|
45
|
+
now: now || prevContext?.now,
|
|
46
|
+
onError: onError || prevContext?.onError,
|
|
47
|
+
timeZone: timeZone || prevContext?.timeZone
|
|
48
|
+
}),
|
|
49
|
+
formatters,
|
|
50
|
+
cache
|
|
51
|
+
}), [cache, formats, formatters, getMessageFallback, locale, messages, now, onError, prevContext, timeZone]);
|
|
52
|
+
return /*#__PURE__*/jsx(IntlContext.Provider, {
|
|
53
|
+
value: value,
|
|
54
|
+
children: children
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function useIntlContext() {
|
|
59
|
+
const context = useContext(IntlContext);
|
|
60
|
+
if (!context) {
|
|
61
|
+
throw new Error('No intl context found. Have you configured the provider? See https://next-intl.dev/docs/usage/configuration#server-client-components' );
|
|
62
|
+
}
|
|
63
|
+
return context;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let hasWarnedForMissingTimezone = false;
|
|
67
|
+
const isServer = typeof window === 'undefined';
|
|
68
|
+
function useTranslationsImpl(allMessagesPrefixed, namespacePrefixed, namespacePrefix) {
|
|
69
|
+
const {
|
|
70
|
+
cache,
|
|
71
|
+
formats: globalFormats,
|
|
72
|
+
formatters,
|
|
73
|
+
getMessageFallback,
|
|
74
|
+
locale,
|
|
75
|
+
onError,
|
|
76
|
+
timeZone
|
|
77
|
+
} = useIntlContext();
|
|
78
|
+
|
|
79
|
+
// The `namespacePrefix` is part of the type system.
|
|
80
|
+
// See the comment in the hook invocation.
|
|
81
|
+
const allMessages = allMessagesPrefixed[namespacePrefix];
|
|
82
|
+
const namespace = resolveNamespace(namespacePrefixed, namespacePrefix);
|
|
83
|
+
if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
|
|
84
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
85
|
+
hasWarnedForMissingTimezone = true;
|
|
86
|
+
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` ));
|
|
87
|
+
}
|
|
88
|
+
const translate = useMemo(() => createBaseTranslator({
|
|
89
|
+
cache,
|
|
90
|
+
formatters,
|
|
91
|
+
getMessageFallback,
|
|
92
|
+
messages: allMessages,
|
|
93
|
+
namespace,
|
|
94
|
+
onError,
|
|
95
|
+
formats: globalFormats,
|
|
96
|
+
locale,
|
|
97
|
+
timeZone
|
|
98
|
+
}), [cache, formatters, getMessageFallback, allMessages, namespace, onError, globalFormats, locale, timeZone]);
|
|
99
|
+
return translate;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
104
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
105
|
+
*
|
|
106
|
+
* If no namespace is provided, all available messages are returned.
|
|
107
|
+
* The namespace can also indicate nesting by using a dot
|
|
108
|
+
* (e.g. `namespace.Component`).
|
|
109
|
+
*/
|
|
110
|
+
function useTranslations(namespace) {
|
|
111
|
+
const context = useIntlContext();
|
|
112
|
+
const messages = context.messages;
|
|
113
|
+
|
|
114
|
+
// We have to wrap the actual hook so the type inference for the optional
|
|
115
|
+
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
116
|
+
// The prefix ("!") is arbitrary.
|
|
117
|
+
// @ts-expect-error Use the explicit annotation instead
|
|
118
|
+
return useTranslationsImpl({
|
|
119
|
+
'!': messages
|
|
120
|
+
},
|
|
121
|
+
// @ts-expect-error
|
|
122
|
+
namespace ? `!.${namespace}` : '!', '!');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function useLocale() {
|
|
126
|
+
return useIntlContext().locale;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getNow() {
|
|
130
|
+
return new Date();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @see https://next-intl.dev/docs/usage/dates-times#relative-times-usenow
|
|
135
|
+
*/
|
|
136
|
+
function useNow(options) {
|
|
137
|
+
const updateInterval = options?.updateInterval;
|
|
138
|
+
const {
|
|
139
|
+
now: globalNow
|
|
140
|
+
} = useIntlContext();
|
|
141
|
+
const [now, setNow] = useState(globalNow || getNow());
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!updateInterval) return;
|
|
144
|
+
const intervalId = setInterval(() => {
|
|
145
|
+
setNow(getNow());
|
|
146
|
+
}, updateInterval);
|
|
147
|
+
return () => {
|
|
148
|
+
clearInterval(intervalId);
|
|
149
|
+
};
|
|
150
|
+
}, [globalNow, updateInterval]);
|
|
151
|
+
return updateInterval == null && globalNow ? globalNow : now;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function useTimeZone() {
|
|
155
|
+
return useIntlContext().timeZone;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function useMessages() {
|
|
159
|
+
const context = useIntlContext();
|
|
160
|
+
if (!context.messages) {
|
|
161
|
+
throw new Error('No messages found. Have you configured them correctly? See https://next-intl.dev/docs/configuration#messages' );
|
|
162
|
+
}
|
|
163
|
+
return context.messages;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function useFormatter() {
|
|
167
|
+
const {
|
|
168
|
+
formats,
|
|
169
|
+
formatters,
|
|
170
|
+
locale,
|
|
171
|
+
now: globalNow,
|
|
172
|
+
onError,
|
|
173
|
+
timeZone
|
|
174
|
+
} = useIntlContext();
|
|
175
|
+
return useMemo(() => createFormatter({
|
|
176
|
+
formats,
|
|
177
|
+
locale,
|
|
178
|
+
now: globalNow,
|
|
179
|
+
onError,
|
|
180
|
+
timeZone,
|
|
181
|
+
_formatters: formatters
|
|
182
|
+
}), [formats, formatters, globalNow, locale, onError, timeZone]);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function getArgs(messageOrParams, ...rest) {
|
|
186
|
+
let message, values, formats;
|
|
187
|
+
if (typeof messageOrParams === 'string') {
|
|
188
|
+
message = messageOrParams;
|
|
189
|
+
values = rest[0];
|
|
190
|
+
formats = rest[1];
|
|
191
|
+
} else {
|
|
192
|
+
message = messageOrParams.message;
|
|
193
|
+
values = messageOrParams.values;
|
|
194
|
+
formats = messageOrParams.formats;
|
|
195
|
+
// `description` is not used at runtime
|
|
196
|
+
}
|
|
197
|
+
// @ts-expect-error -- Secret fallback parameter
|
|
198
|
+
return [undefined,
|
|
199
|
+
// Always use fallback if not compiled
|
|
200
|
+
values, formats, message];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Note: This API is usually compiled into `useTranslations`,
|
|
204
|
+
// but there is some fallback handling which allows this hook
|
|
205
|
+
// to still work when not being compiled.
|
|
206
|
+
//
|
|
207
|
+
// This is relevant for:
|
|
208
|
+
// - Isolated environments like tests, Storybook, etc.
|
|
209
|
+
// - Fallbacks in case an extracted message is not yet available
|
|
210
|
+
function useExtracted(namespace) {
|
|
211
|
+
const t = useTranslations(namespace);
|
|
212
|
+
function translateFn(...params) {
|
|
213
|
+
// @ts-expect-error -- Passing `undefined` as an ID is secretly allowed here
|
|
214
|
+
return t(...getArgs(...params));
|
|
215
|
+
}
|
|
216
|
+
translateFn.rich = (...params) =>
|
|
217
|
+
// @ts-expect-error -- Passing `undefined` as an ID is secretly allowed here
|
|
218
|
+
t.rich(...getArgs(...params));
|
|
219
|
+
translateFn.markup = (...params) =>
|
|
220
|
+
// @ts-expect-error -- Passing `undefined` as an ID is secretly allowed here
|
|
221
|
+
t.markup(...getArgs(...params));
|
|
222
|
+
translateFn.has = function translateHasFn(
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
224
|
+
message) {
|
|
225
|
+
// Not really something better we can do here
|
|
226
|
+
return true;
|
|
227
|
+
};
|
|
228
|
+
return translateFn;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { IntlProvider, useExtracted as _useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,b as r}from"./formatters-CJcico0N.js";export{I as IntlError,a as IntlErrorCode}from"./formatters-CJcico0N.js";import{r as s,a as t,d as o,b as m}from"./initializeConfig-CHgjheii.js";export{c as createFormatter,i as initializeConfig}from"./initializeConfig-CHgjheii.js";function n({_cache:a=r(),_formatters:i=e(a),getMessageFallback:n=o,messages:c,namespace:f,onError:g=m,...l}){return function({messages:e,namespace:a,...r},o){return e=e[o],a=s(a,o),t({...r,messages:e,namespace:a})}({...l,onError:g,cache:a,formatters:i,getMessageFallback:n,messages:{"!":c},namespace:f?`!.${f}`:"!"},"!")}function f(e,a){return e.includes(a)}export{r as _createCache,e as _createIntlFormatters,n as createTranslator,f as hasLocale};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,n,e,o,u){const f=[];for(const i of t){const t=r(i,n,e,o,u);Array.isArray(t)?f.push(...t):f.push(t)}return f}function r(r,i,s,a,c){if("string"==typeof r)return r;if(0===r){const t=c;return a.formatters.getNumberFormat(t.locale).format(t.value)}const[m,l,...g]=r;if(void 0===l){const t=n(s,m);return String(t)}if("number"!=typeof l||0===l)return function(r,e,o,u,i,s){const a=n(u,r),c=f(t(e,o,u,i,s));return a(Array.isArray(c)?c:[c])}(m,[l,...g],i,s,a,c);switch(l){case 1:return function(t,r,e,u,f,i){return o(r[String(n(u,t))]??r.other,e,u,f,i)}(m,g[0],i,s,a,c);case 2:return e(m,g[0],i,s,a,"cardinal");case 3:return e(m,g[0],i,s,a,"ordinal");case 4:return function(t,r,e,o,u){const f=n(o,t),i=function(t,r){if(t)return"string"==typeof t?r.formats?.number?.[t]?r.formats.number[t]:void 0:t}(r,u);return u.formatters.getNumberFormat(e,i).format(f)}(m,g[0],i,s,a);case 5:case 6:return u(m,g[0],i,s,a);default:return""}}function n(t,r){return t[r]}function e(t,r,e,u,f,i){const s=n(u,t),a=`=${s}`;return o(a in r?r[a]:r[f.formatters.getPluralRules(e,{type:i}).select(s)]??r.other,e,u,f,{value:s,locale:e})}function o(n,e,o,u,f){return"string"==typeof n?n:0===n?r(n,e,o,u,f):t(n,e,o,u,f)}function u(t,r,e,o,u,f){const i=n(o,t),s=function(t,r,n){if(t){if("string"==typeof t){const r=n.formats?.dateTime?.[t];return r}return t}}(r,0,u),a={...s,timeZone:s?.timeZone??u.timeZone};return u.formatters.getDateTimeFormat(e,a).format(i)}function f(t){if(0===t.length)return"";const r=[];let n="";for(const e of t)"string"==typeof e?n+=e:(n&&(r.push(n),n=""),r.push(e));return n&&r.push(n),1===r.length?r[0]:r}function i(...[,r,n,e]){const{formats:o,globalFormats:u,locale:i,...s}=e,a=function(r,n,e={},o){return"string"==typeof r?r:f(t(r,n,e,o,void 0))}(r,i,n,{formats:{dateTime:{...u?.dateTime,...o?.dateTime},number:{...u?.number,...o?.number}},...s});return a}i.raw=!1;export{i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{IntlMessageFormat as t}from"intl-messageformat";import{isValidElement as e}from"react";import{I as r,a as o,m as a}from"../formatters-CJcico0N.js";function m(...[m,s,i,n]){if(Array.isArray(s))throw new r(o.INVALID_MESSAGE,void 0);if("object"==typeof s)throw new r(o.INSUFFICIENT_PATH,void 0);if("string"==typeof s){const t=function(t,e){return e||/'[{}<#|']/.test(t)?void 0:t}(s,i);if(t)return t}const{cache:f,formats:c,formatters:g,globalFormats:u,locale:d,timeZone:A}=n;let p;g.getMessageFormat||(g.getMessageFormat=function(e,r){return a(((...e)=>new t(e[0],e[1],e[2],{formatters:r,...e[3]})),e.message)}(f,g));try{p=g.getMessageFormat(s,d,function(e,r,o){const a=t.formats.date,m=t.formats.time,s={...e?.dateTime,...r?.dateTime},i={date:{...a,...s},time:{...m,...s},number:{...e?.number,...r?.number}};return o&&["date","time"].forEach((t=>{const e=i[t];for(const[t,r]of Object.entries(e))e[t]={timeZone:o,...r}})),i}(u,c,A),{formatters:{...g,getDateTimeFormat:(t,e)=>g.getDateTimeFormat(t,{...e,timeZone:e?.timeZone??A})}})}catch(t){throw new r(o.INVALID_MESSAGE,void 0)}const w=p.format(i);return e(w)||Array.isArray(w)||"string"==typeof w?w:String(w)}m.raw=!0;export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{memoize as e,strategies as t}from"@formatjs/fast-memoize";class a extends Error{constructor(e,t){let a=e;t&&(a+=": "+t),super(a),this.code=e,t&&(this.originalMessage=t)}}var r=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}(r||{});function s(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function i(a,r){return e(a,{cache:(s=r,{create:()=>({get:e=>s[e],set(e,t){s[e]=t}})}),strategy:t.variadic});var s}function I(e,t){return i(((...t)=>new e(...t)),t)}function l(e){return{getDateTimeFormat:I(Intl.DateTimeFormat,e.dateTime),getNumberFormat:I(Intl.NumberFormat,e.number),getPluralRules:I(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:I(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:I(Intl.ListFormat,e.list),getDisplayNames:I(Intl.DisplayNames,e.displayNames)}}export{a as I,r as a,s as b,l as c,i as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{I as IntlError,a as IntlErrorCode,b as _createCache,c as _createIntlFormatters}from"./formatters-CJcico0N.js";export{createTranslator,hasLocale}from"./core.js";export{c as createFormatter,i as initializeConfig}from"./initializeConfig-CHgjheii.js";export{IntlProvider,_useExtracted,useFormatter,useLocale,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cloneElement as e,isValidElement as t}from"react";import r from"use-intl/format-message";import{I as n,a as o,c as a,b as s}from"./formatters-CJcico0N.js";function c(...e){return e.filter(Boolean).join(".")}function i(e){return c(e.namespace,e.key)}function u(e){console.error(e)}function m(e,t,r,n){const o=c(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 f(a){const s=function(e,t,r){try{if(!t)throw new Error(void 0);const n=r?m(e,t,r):t;if(!n)throw new Error(r);return n}catch(e){return new n(o.MISSING_MESSAGE,e.message)}}(a.locale,a.messages,a.namespace);return function({cache:a,formats:s,formatters:u,getMessageFallback:f=i,locale:l,messagesOrError:g,namespace:y,onError:h,timeZone:w}){const E=g instanceof n;function d(e,t,r,o){const a=new n(t,r);return h(a),o??f({error:a,key:e,namespace:y})}function p(i,p,S,M){const T=M;let N;if(E){if(!T)return h(g),f({error:g,key:i,namespace:y});N=T}else{const e=g;try{N=m(l,e,i,y)}catch(e){if(!T)return d(i,o.MISSING_MESSAGE,e.message,T);N=T}}try{const n=c(y,i);return r(n,N,p?function(r){const n={};return Object.keys(r).forEach((o=>{let a=0;const s=r[o];let c;c="function"==typeof s?r=>{const n=s(r);return t(n)?e(n,{key:o+a++}):n}:s,n[o]=c})),n}(p):p,{cache:a,formatters:u,globalFormats:s,formats:S,locale:l,timeZone:w})}catch(e){let t,r;return e instanceof n?(t=e.code,r=e.originalMessage):(t=o.FORMATTING_ERROR,r=e.message),d(i,t,r,T)}}function S(e,t,r,n){const a=p(e,t,r,n);return"string"!=typeof a?d(e,o.INVALID_MESSAGE,void 0):a}return S.rich=p,S.markup=(e,t,r,n)=>p(e,t,r,n),S.raw=e=>{if(E)return h(g),f({error:g,key:e,namespace:y});const t=g;try{return m(l,t,e,y)}catch(t){return d(e,o.MISSING_MESSAGE,t.message)}},S.has=e=>{if(E)return!1;try{return m(l,g,e,y),!0}catch{return!1}},S}({...a,messagesOrError:s})}function l(e,t){return e===t?void 0:e.slice((t+".").length)}const g=3600,y=86400,h=7*y,w=2628e3,E=7884e3,d=365*y,p={second:1,seconds:1,minute:60,minutes:60,hour:g,hours:g,day:y,days:y,week:h,weeks:h,month:w,months:w,quarter:E,quarters:E,year:d,years:d};function S(e){const{_cache:t=s(),_formatters:r=a(t),formats:c,locale:i,onError:m=u,timeZone:f}=e;function l(e){return e?.timeZone||(f?e={...e,timeZone:f}:m(new n(o.ENVIRONMENT_FALLBACK,void 0))),e}function E(e,t,r,a,s){let c;try{c=function(e,t,r){let a;if("string"==typeof t){const r=t;if(a=e?.[r],!a){const e=new n(o.MISSING_FORMAT,void 0);throw m(e),e}}else a=t;return r&&(a={...a,...r}),a}(r,e,t)}catch{return s()}try{return a(c)}catch(e){return m(new n(o.FORMATTING_ERROR,e.message)),s()}}function S(e,t,n){return E(t,n,c?.dateTime,(t=>(t=l(t),r.getDateTimeFormat(i,t).format(e))),(()=>String(e)))}function M(){return e.now?e.now:(m(new n(o.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:S,number:function(e,t,n){return E(t,n,c?.number,(t=>r.getNumberFormat(i,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let n,o;const a={};t instanceof Date||"number"==typeof t?n=new Date(t):t&&(n=null!=t.now?new Date(t.now):M(),o=t.unit,a.style=t.style,a.numberingSystem=t.numberingSystem),n||(n=M());const s=(new Date(e).getTime()-n.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<60?"second":t<g?"minute":t<y?"hour":t<h?"day":t<w?"week":t<d?"month":"year"}(s)),a.numeric="second"===o?"auto":"always";const c=function(e,t){return Math.round(e/p[t])}(s,o);return r.getRelativeTimeFormat(i,a).format(c,o)}catch(t){return m(new n(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t,n){const o=[],a=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),a.set(e,t)):e=String(t),o.push(e),s++}return E(t,n,c?.list,(e=>{const t=r.getListFormat(i,e).formatToParts(o).map((e=>"literal"===e.type?e.value:a.get(e.value)||e.value));return a.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,n,o){return E(n,o,c?.dateTime,(n=>(n=l(n),r.getDateTimeFormat(i,n).formatRange(e,t))),(()=>[S(e),S(t)].join(" – ")))},displayName:function(e,t,n){return E(t,n,c?.displayName,(t=>r.getDisplayNames(i,t).of(e)),(()=>e))}}}function M({formats:e,getMessageFallback:t,messages:r,onError:n,...o}){return{...o,formats:e||void 0,messages:r||void 0,onError:n||u,getMessageFallback:t||i}}export{f as a,u as b,S as c,i as d,M as i,l as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext as e,useContext as r,useMemo as t,useState as o,useEffect as a}from"react";import{b as n,c as s,I as c,a as i}from"./formatters-CJcico0N.js";import{i as m,r as l,a as f,c as u}from"./initializeConfig-CHgjheii.js";import{jsx as d}from"react/jsx-runtime";const g=e(void 0);function w({children:e,formats:o,getMessageFallback:a,locale:c,messages:i,now:l,onError:f,timeZone:u}){const w=r(g),p=t((()=>w?.cache||n()),[c,w?.cache]),E=t((()=>w?.formatters||s(p)),[p,w?.formatters]),h=t((()=>({...m({locale:c,formats:void 0===o?w?.formats:o,getMessageFallback:a||w?.getMessageFallback,messages:void 0===i?w?.messages:i,now:l||w?.now,onError:f||w?.onError,timeZone:u||w?.timeZone}),formatters:E,cache:p})),[p,o,E,a,c,i,l,f,w,u]);return d(g.Provider,{value:h,children:e})}function p(){const e=r(g);if(!e)throw new Error(void 0);return e}let E=!1;const h="undefined"==typeof window;function v(e){return function(e,r,o){const{cache:a,formats:n,formatters:s,getMessageFallback:m,locale:u,onError:d,timeZone:g}=p(),w=e[o],v=l(r,o);return g||E||!h||(E=!0,d(new c(i.ENVIRONMENT_FALLBACK,void 0))),t((()=>f({cache:a,formatters:s,getMessageFallback:m,messages:w,namespace:v,onError:d,formats:n,locale:u,timeZone:g})),[a,s,m,w,v,d,n,u,g])}({"!":p().messages},e?`!.${e}`:"!","!")}function Z(){return p().locale}function k(){return new Date}function b(e){const r=e?.updateInterval,{now:t}=p(),[n,s]=o(t||k());return a((()=>{if(!r)return;const e=setInterval((()=>{s(k())}),r);return()=>{clearInterval(e)}}),[t,r]),null==r&&t?t:n}function x(){return p().timeZone}function F(){const e=p();if(!e.messages)throw new Error(void 0);return e.messages}function I(){const{formats:e,formatters:r,locale:o,now:a,onError:n,timeZone:s}=p();return t((()=>u({formats:e,locale:o,now:a,onError:n,timeZone:s,_formatters:r})),[e,r,a,o,n,s])}function M(e){throw v(e),new Error("[next-intl] `useExtracted` was called in production without compilation. Include modules that call `useExtracted` in `srcPath` and use `transpilePackages` for 3rd-party packages.")}export{w as IntlProvider,M as _useExtracted,I as useFormatter,Z as useLocale,F as useMessages,b as useNow,x as useTimeZone,v as useTranslations};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A generic type that describes the shape of messages.
|
|
3
|
+
*
|
|
4
|
+
* Optionally, messages can be strictly-typed in order to get type safety for message
|
|
5
|
+
* namespaces and keys. See https://next-intl.dev/docs/usage/typescript
|
|
6
|
+
*/
|
|
7
|
+
type AbstractIntlMessages = {
|
|
8
|
+
[id: string]: AbstractIntlMessages | string;
|
|
9
|
+
};
|
|
10
|
+
export default AbstractIntlMessages;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
displayName: AppFormats extends {
|
|
13
|
+
displayName: infer AppDisplayNameFormats;
|
|
14
|
+
} ? keyof AppDisplayNameFormats : string;
|
|
15
|
+
list: AppFormats extends {
|
|
16
|
+
list: infer AppListFormats;
|
|
17
|
+
} ? keyof AppListFormats : string;
|
|
18
|
+
number: AppFormats extends {
|
|
19
|
+
number: infer AppNumberFormats;
|
|
20
|
+
} ? keyof AppNumberFormats : string;
|
|
21
|
+
} : {
|
|
22
|
+
dateTime: string;
|
|
23
|
+
displayName: string;
|
|
24
|
+
list: string;
|
|
25
|
+
number: string;
|
|
26
|
+
};
|
|
27
|
+
export type Messages = AppConfig extends {
|
|
28
|
+
Messages: infer AppMessages;
|
|
29
|
+
} ? AppMessages : Record<string, any>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type TimeZone from './TimeZone.js';
|
|
2
|
+
/**
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
|
|
4
|
+
*/
|
|
5
|
+
type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
|
|
6
|
+
/**
|
|
7
|
+
* Examples:
|
|
8
|
+
* - numeric: "2021"
|
|
9
|
+
* - 2-digit: "21"
|
|
10
|
+
*/
|
|
11
|
+
year?: 'numeric' | '2-digit';
|
|
12
|
+
/** Examples:
|
|
13
|
+
* - numeric: "3"
|
|
14
|
+
* - 2-digit: "03"
|
|
15
|
+
* - long: "March"
|
|
16
|
+
* - short: "Mar"
|
|
17
|
+
* - narrow: "M"
|
|
18
|
+
*/
|
|
19
|
+
month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
|
|
20
|
+
/** Examples:
|
|
21
|
+
* - numeric: "2"
|
|
22
|
+
* - 2-digit: "02"
|
|
23
|
+
*/
|
|
24
|
+
day?: 'numeric' | '2-digit';
|
|
25
|
+
/** Examples:
|
|
26
|
+
* - numeric: "2"
|
|
27
|
+
* - 2-digit: "02"
|
|
28
|
+
*/
|
|
29
|
+
hour?: 'numeric' | '2-digit';
|
|
30
|
+
/** Examples:
|
|
31
|
+
* - numeric: "2"
|
|
32
|
+
* - 2-digit: "02"
|
|
33
|
+
*/
|
|
34
|
+
minute?: 'numeric' | '2-digit';
|
|
35
|
+
/** Examples:
|
|
36
|
+
* - numeric: "2"
|
|
37
|
+
* - 2-digit: "02"
|
|
38
|
+
*/
|
|
39
|
+
second?: 'numeric' | '2-digit';
|
|
40
|
+
/** Examples:
|
|
41
|
+
* - long: "Thursday"
|
|
42
|
+
* - short: "Thu"
|
|
43
|
+
* - narrow: "T"
|
|
44
|
+
*/
|
|
45
|
+
weekday?: 'long' | 'short' | 'narrow';
|
|
46
|
+
/** Examples:
|
|
47
|
+
* - long: "Anno Domini"
|
|
48
|
+
* - short: "AD", narrow "A"
|
|
49
|
+
*/
|
|
50
|
+
era?: 'long' | 'short' | 'narrow';
|
|
51
|
+
/** If this is set to `true`, a 12-hour am/pm format is used. Otherwise a 24-hour time.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
hour12?: boolean;
|
|
55
|
+
/** Examples:
|
|
56
|
+
* - long: "Pacific Daylight Time"
|
|
57
|
+
* - short: "PDT"
|
|
58
|
+
*/
|
|
59
|
+
timeZoneName?: 'long' | 'short';
|
|
60
|
+
/**
|
|
61
|
+
* One of the [database names from the TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
|
|
62
|
+
*/
|
|
63
|
+
timeZone?: TimeZone;
|
|
64
|
+
localeMatcher?: 'best fit' | 'lookup';
|
|
65
|
+
formatMatcher?: 'best fit' | 'basic';
|
|
66
|
+
dateStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
67
|
+
timeStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
68
|
+
calendar?: 'buddhist' | 'chinese' | 'coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | 'hebrew' | 'indian' | 'islamic' | 'iso8601' | 'japanese' | 'persian' | 'roc';
|
|
69
|
+
dayPeriod?: 'narrow' | 'short' | 'long';
|
|
70
|
+
numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | 'gujr' | 'guru' | 'hanidec' | 'khmr' | 'knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | 'mong' | 'mymr' | 'orya' | 'tamldec' | 'telu' | 'thai' | 'tibt';
|
|
71
|
+
hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
|
|
72
|
+
};
|
|
73
|
+
export default DateTimeFormatOptions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
|
|
2
|
+
import type NumberFormatOptions from './NumberFormatOptions.js';
|
|
3
|
+
type Formats = {
|
|
4
|
+
dateTime?: Record<string, DateTimeFormatOptions>;
|
|
5
|
+
displayName?: Record<string, Intl.DisplayNamesOptions>;
|
|
6
|
+
list?: Record<string, Intl.ListFormatOptions>;
|
|
7
|
+
number?: Record<string, NumberFormatOptions>;
|
|
8
|
+
};
|
|
9
|
+
export default Formats;
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Should be used for entry points that configure the library.
|
|
8
|
+
*/
|
|
9
|
+
type IntlConfig = {
|
|
10
|
+
/** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
|
|
11
|
+
locale: Locale;
|
|
12
|
+
/** Global formats can be provided to achieve consistent
|
|
13
|
+
* formatting across components. */
|
|
14
|
+
formats?: Formats | null;
|
|
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
|
+
timeZone?: TimeZone;
|
|
17
|
+
/** This callback will be invoked when an error is encountered during
|
|
18
|
+
* resolving a message or formatting it. This defaults to `console.error` to
|
|
19
|
+
* keep your app running. You can customize the handling by taking
|
|
20
|
+
* `error.code` into account. */
|
|
21
|
+
onError?(error: IntlError): void;
|
|
22
|
+
/** Will be called when a message couldn't be resolved or formatting it led to
|
|
23
|
+
* an error. This defaults to `${namespace}.${key}` You can use this to
|
|
24
|
+
* customize what will be rendered in this case. */
|
|
25
|
+
getMessageFallback?(info: {
|
|
26
|
+
error: IntlError;
|
|
27
|
+
key: string;
|
|
28
|
+
namespace?: string;
|
|
29
|
+
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* Providing this value will have two effects:
|
|
32
|
+
* 1. It will be used as the default for the `now` argument of
|
|
33
|
+
* `useFormatter().formatRelativeTime` if no explicit value is provided.
|
|
34
|
+
* 2. It will be returned as a static value from the `useNow` hook. Note
|
|
35
|
+
* however that when `updateInterval` is configured on the `useNow` hook,
|
|
36
|
+
* the global `now` value will only be used for the initial render, but
|
|
37
|
+
* afterwards the current date will be returned continuously.
|
|
38
|
+
*/
|
|
39
|
+
now?: Date;
|
|
40
|
+
/** All messages that will be available. */
|
|
41
|
+
messages?: DeepPartial<Messages> | null;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
/**
|
|
45
|
+
* A stricter set of the configuration that should be used internally
|
|
46
|
+
* once defaults are assigned to `IntlConfiguration`.
|
|
47
|
+
*/
|
|
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']>;
|
|
53
|
+
};
|
|
54
|
+
export default IntlConfig;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare enum IntlErrorCode {
|
|
2
|
+
MISSING_MESSAGE = "MISSING_MESSAGE",
|
|
3
|
+
MISSING_FORMAT = "MISSING_FORMAT",
|
|
4
|
+
ENVIRONMENT_FALLBACK = "ENVIRONMENT_FALLBACK",
|
|
5
|
+
INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
|
|
6
|
+
INVALID_MESSAGE = "INVALID_MESSAGE",
|
|
7
|
+
INVALID_KEY = "INVALID_KEY",
|
|
8
|
+
FORMATTING_ERROR = "FORMATTING_ERROR"
|
|
9
|
+
}
|
|
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,2 @@
|
|
|
1
|
+
type TimeZone = 'Africa/Abidjan' | 'Africa/Accra' | 'Africa/Addis_Ababa' | 'Africa/Algiers' | 'Africa/Asmara' | 'Africa/Bamako' | 'Africa/Bangui' | 'Africa/Banjul' | 'Africa/Bissau' | 'Africa/Blantyre' | 'Africa/Brazzaville' | 'Africa/Bujumbura' | 'Africa/Cairo' | 'Africa/Casablanca' | 'Africa/Ceuta' | 'Africa/Conakry' | 'Africa/Dakar' | 'Africa/Dar_es_Salaam' | 'Africa/Djibouti' | 'Africa/Douala' | 'Africa/El_Aaiun' | 'Africa/Freetown' | 'Africa/Gaborone' | 'Africa/Harare' | 'Africa/Johannesburg' | 'Africa/Juba' | 'Africa/Kampala' | 'Africa/Khartoum' | 'Africa/Kigali' | 'Africa/Kinshasa' | 'Africa/Lagos' | 'Africa/Libreville' | 'Africa/Lome' | 'Africa/Luanda' | 'Africa/Lubumbashi' | 'Africa/Lusaka' | 'Africa/Malabo' | 'Africa/Maputo' | 'Africa/Maseru' | 'Africa/Mbabane' | 'Africa/Mogadishu' | 'Africa/Monrovia' | 'Africa/Nairobi' | 'Africa/Ndjamena' | 'Africa/Niamey' | 'Africa/Nouakchott' | 'Africa/Ouagadougou' | 'Africa/Porto-Novo' | 'Africa/Sao_Tome' | 'Africa/Tripoli' | 'Africa/Tunis' | 'Africa/Windhoek' | 'America/Adak' | 'America/Anchorage' | 'America/Anguilla' | 'America/Antigua' | 'America/Araguaina' | 'America/Argentina/Buenos_Aires' | 'America/Argentina/Catamarca' | 'America/Argentina/Cordoba' | 'America/Argentina/Jujuy' | 'America/Argentina/La_Rioja' | 'America/Argentina/Mendoza' | 'America/Argentina/Rio_Gallegos' | 'America/Argentina/Salta' | 'America/Argentina/San_Juan' | 'America/Argentina/San_Luis' | 'America/Argentina/Tucuman' | 'America/Argentina/Ushuaia' | 'America/Aruba' | 'America/Asuncion' | 'America/Atikokan' | 'America/Bahia' | 'America/Bahia_Banderas' | 'America/Barbados' | 'America/Belem' | 'America/Belize' | 'America/Blanc-Sablon' | 'America/Boa_Vista' | 'America/Bogota' | 'America/Boise' | 'America/Cambridge_Bay' | 'America/Campo_Grande' | 'America/Cancun' | 'America/Caracas' | 'America/Cayenne' | 'America/Cayman' | 'America/Chicago' | 'America/Chihuahua' | 'America/Costa_Rica' | 'America/Creston' | 'America/Cuiaba' | 'America/Curacao' | 'America/Danmarkshavn' | 'America/Dawson' | 'America/Dawson_Creek' | 'America/Denver' | 'America/Detroit' | 'America/Dominica' | 'America/Edmonton' | 'America/Eirunepe' | 'America/El_Salvador' | 'America/Fort_Nelson' | 'America/Fortaleza' | 'America/Glace_Bay' | 'America/Godthab' | 'America/Goose_Bay' | 'America/Grand_Turk' | 'America/Grenada' | 'America/Guadeloupe' | 'America/Guatemala' | 'America/Guayaquil' | 'America/Guyana' | 'America/Halifax' | 'America/Havana' | 'America/Hermosillo' | 'America/Indiana/Indianapolis' | 'America/Indiana/Knox' | 'America/Indiana/Marengo' | 'America/Indiana/Petersburg' | 'America/Indiana/Tell_City' | 'America/Indiana/Vevay' | 'America/Indiana/Vincennes' | 'America/Indiana/Winamac' | 'America/Inuvik' | 'America/Iqaluit' | 'America/Jamaica' | 'America/Juneau' | 'America/Kentucky/Louisville' | 'America/Kentucky/Monticello' | 'America/Kralendijk' | 'America/La_Paz' | 'America/Lima' | 'America/Los_Angeles' | 'America/Lower_Princes' | 'America/Maceio' | 'America/Managua' | 'America/Manaus' | 'America/Marigot' | 'America/Martinique' | 'America/Matamoros' | 'America/Mazatlan' | 'America/Menominee' | 'America/Merida' | 'America/Metlakatla' | 'America/Mexico_City' | 'America/Miquelon' | 'America/Moncton' | 'America/Monterrey' | 'America/Montevideo' | 'America/Montserrat' | 'America/Nassau' | 'America/New_York' | 'America/Nipigon' | 'America/Nome' | 'America/Noronha' | 'America/North_Dakota/Beulah' | 'America/North_Dakota/Center' | 'America/North_Dakota/New_Salem' | 'America/Ojinaga' | 'America/Panama' | 'America/Pangnirtung' | 'America/Paramaribo' | 'America/Phoenix' | 'America/Port-au-Prince' | 'America/Port_of_Spain' | 'America/Porto_Velho' | 'America/Puerto_Rico' | 'America/Punta_Arenas' | 'America/Rainy_River' | 'America/Rankin_Inlet' | 'America/Recife' | 'America/Regina' | 'America/Resolute' | 'America/Rio_Branco' | 'America/Santarem' | 'America/Santiago' | 'America/Santo_Domingo' | 'America/Sao_Paulo' | 'America/Scoresbysund' | 'America/Sitka' | 'America/St_Barthelemy' | 'America/St_Johns' | 'America/St_Kitts' | 'America/St_Lucia' | 'America/St_Thomas' | 'America/St_Vincent' | 'America/Swift_Current' | 'America/Tegucigalpa' | 'America/Thule' | 'America/Thunder_Bay' | 'America/Tijuana' | 'America/Toronto' | 'America/Tortola' | 'America/Vancouver' | 'America/Whitehorse' | 'America/Winnipeg' | 'America/Yakutat' | 'America/Yellowknife' | 'Antarctica/Casey' | 'Antarctica/Davis' | 'Antarctica/DumontDUrville' | 'Antarctica/Macquarie' | 'Antarctica/Mawson' | 'Antarctica/Palmer' | 'Antarctica/Rothera' | 'Antarctica/Syowa' | 'Antarctica/Troll' | 'Antarctica/Vostok' | 'Arctic/Longyearbyen' | 'Asia/Almaty' | 'Asia/Amman' | 'Asia/Anadyr' | 'Asia/Aqtau' | 'Asia/Aqtobe' | 'Asia/Ashgabat' | 'Asia/Atyrau' | 'Asia/Baghdad' | 'Asia/Baku' | 'Asia/Bangkok' | 'Asia/Barnaul' | 'Asia/Beirut' | 'Asia/Bishkek' | 'Asia/Brunei' | 'Asia/Chita' | 'Asia/Choibalsan' | 'Asia/Colombo' | 'Asia/Damascus' | 'Asia/Dhaka' | 'Asia/Dili' | 'Asia/Dubai' | 'Asia/Dushanbe' | 'Asia/Famagusta' | 'Asia/Gaza' | 'Asia/Hebron' | 'Asia/Ho_Chi_Minh' | 'Asia/Hong_Kong' | 'Asia/Hovd' | 'Asia/Irkutsk' | 'Asia/Jakarta' | 'Asia/Jayapura' | 'Asia/Jerusalem' | 'Asia/Kabul' | 'Asia/Kamchatka' | 'Asia/Karachi' | 'Asia/Kathmandu' | 'Asia/Khandyga' | 'Asia/Kolkata' | 'Asia/Krasnoyarsk' | 'Asia/Kuala_Lumpur' | 'Asia/Kuching' | 'Asia/Macau' | 'Asia/Magadan' | 'Asia/Makassar' | 'Asia/Manila' | 'Asia/Nicosia' | 'Asia/Novokuznetsk' | 'Asia/Novosibirsk' | 'Asia/Omsk' | 'Asia/Oral' | 'Asia/Phnom_Penh' | 'Asia/Pontianak' | 'Asia/Pyongyang' | 'Asia/Qatar' | 'Asia/Qostanay' | 'Asia/Qyzylorda' | 'Asia/Riyadh' | 'Asia/Sakhalin' | 'Asia/Samarkand' | 'Asia/Seoul' | 'Asia/Shanghai' | 'Asia/Singapore' | 'Asia/Srednekolymsk' | 'Asia/Taipei' | 'Asia/Tashkent' | 'Asia/Tbilisi' | 'Asia/Tehran' | 'Asia/Thimphu' | 'Asia/Tokyo' | 'Asia/Tomsk' | 'Asia/Ulaanbaatar' | 'Asia/Urumqi' | 'Asia/Ust-Nera' | 'Asia/Vladivostok' | 'Asia/Yakutsk' | 'Asia/Yangon' | 'Asia/Yekaterinburg' | 'Asia/Yerevan' | 'Atlantic/Azores' | 'Atlantic/Bermuda' | 'Atlantic/Canary' | 'Atlantic/Cape_Verde' | 'Atlantic/Faroe' | 'Atlantic/Madeira' | 'Atlantic/Reykjavik' | 'Atlantic/South_Georgia' | 'Atlantic/St_Helena' | 'Atlantic/Stanley' | 'Australia/Adelaide' | 'Australia/Brisbane' | 'Australia/Broken_Hill' | 'Australia/Currie' | 'Australia/Darwin' | 'Australia/Eucla' | 'Australia/Hobart' | 'Australia/Lindeman' | 'Australia/Lord_Howe' | 'Australia/Melbourne' | 'Australia/Perth' | 'Australia/Sydney' | 'Europe/Amsterdam' | 'Europe/Andorra' | 'Europe/Astrakhan' | 'Europe/Athens' | 'Europe/Belgrade' | 'Europe/Berlin' | 'Europe/Bratislava' | 'Europe/Brussels' | 'Europe/Bucharest' | 'Europe/Budapest' | 'Europe/Busingen' | 'Europe/Chisinau' | 'Europe/Copenhagen' | 'Europe/Dublin' | 'Europe/Gibraltar' | 'Europe/Guernsey' | 'Europe/Helsinki' | 'Europe/Isle_of_Man' | 'Europe/Istanbul' | 'Europe/Jersey' | 'Europe/Kaliningrad' | 'Europe/Kiev' | 'Europe/Kirov' | 'Europe/Lisbon' | 'Europe/Ljubljana' | 'Europe/London' | 'Europe/Luxembourg' | 'Europe/Madrid' | 'Europe/Malta' | 'Europe/Mariehamn' | 'Europe/Minsk' | 'Europe/Monaco' | 'Europe/Moscow' | 'Europe/Oslo' | 'Europe/Paris' | 'Europe/Podgorica' | 'Europe/Prague' | 'Europe/Riga' | 'Europe/Rome' | 'Europe/Samara' | 'Europe/San_Marino' | 'Europe/Sarajevo' | 'Europe/Saratov' | 'Europe/Simferopol' | 'Europe/Skopje' | 'Europe/Sofia' | 'Europe/Stockholm' | 'Europe/Tallinn' | 'Europe/Tirane' | 'Europe/Ulyanovsk' | 'Europe/Uzhgorod' | 'Europe/Vaduz' | 'Europe/Vatican' | 'Europe/Vienna' | 'Europe/Vilnius' | 'Europe/Volgograd' | 'Europe/Warsaw' | 'Europe/Zagreb' | 'Europe/Zaporozhye' | 'Europe/Zurich' | 'Indian/Antananarivo' | 'Indian/Chagos' | 'Indian/Christmas' | 'Indian/Cocos' | 'Indian/Comoro' | 'Indian/Kerguelen' | 'Indian/Mahe' | 'Indian/Maldives' | 'Indian/Mauritius' | 'Indian/Mayotte' | 'Indian/Reunion' | 'Pacific/Apia' | 'Pacific/Auckland' | 'Pacific/Bougainville' | 'Pacific/Chatham' | 'Pacific/Chuuk' | 'Pacific/Easter' | 'Pacific/Efate' | 'Pacific/Enderbury' | 'Pacific/Fakaofo' | 'Pacific/Fiji' | 'Pacific/Funafuti' | 'Pacific/Galapagos' | 'Pacific/Gambier' | 'Pacific/Guadalcanal' | 'Pacific/Guam' | 'Pacific/Honolulu' | 'Pacific/Kiritimati' | 'Pacific/Kosrae' | 'Pacific/Kwajalein' | 'Pacific/Majuro' | 'Pacific/Marquesas' | 'Pacific/Nauru' | 'Pacific/Niue' | 'Pacific/Norfolk' | 'Pacific/Noumea' | 'Pacific/Pago_Pago' | 'Pacific/Palau' | 'Pacific/Pitcairn' | 'Pacific/Pohnpei' | 'Pacific/Port_Moresby' | 'Pacific/Rarotonga' | 'Pacific/Tahiti' | 'Pacific/Tarawa' | 'Pacific/Tongatapu' | 'Pacific/Wake' | 'Pacific/Wallis' | 'UTC' | 'W-SU' | 'WET' | 'Zulu' | (string & {});
|
|
2
|
+
export default TimeZone;
|
|
@@ -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>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Formats as IntlFormats } from 'intl-messageformat';
|
|
2
|
+
import type Formats from './Formats.js';
|
|
3
|
+
import type TimeZone from './TimeZone.js';
|
|
4
|
+
/**
|
|
5
|
+
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
6
|
+
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
7
|
+
* include both a time and a date in a value, therefore the separation doesn't
|
|
8
|
+
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
9
|
+
* to convert the format before `intl-messageformat` can be used.
|
|
10
|
+
*/
|
|
11
|
+
export default function convertFormatsToIntlMessageFormat(globalFormats?: Formats, inlineFormats?: Formats, timeZone?: TimeZone): Partial<IntlFormats>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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, IntlCache } from './formatters.js';
|
|
9
|
+
export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
|
|
10
|
+
cache: IntlCache;
|
|
11
|
+
formatters: Formatters;
|
|
12
|
+
namespace?: string;
|
|
13
|
+
messagesOrError: Messages | IntlError;
|
|
14
|
+
};
|
|
15
|
+
export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(config: Omit<CreateBaseTranslatorProps<Messages>, 'messagesOrError'>): {
|
|
16
|
+
<TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats, _fallback?: never): string;
|
|
17
|
+
rich: (key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode;
|
|
18
|
+
markup(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode>[0], values: MarkupTranslationValues, formats?: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode>[2], _fallback?: never): string;
|
|
19
|
+
raw(key: string): any;
|
|
20
|
+
has(key: string): boolean;
|
|
21
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
displayName: {
|
|
43
|
+
(value: string, options: Intl.DisplayNamesOptions): string;
|
|
44
|
+
(value: string, format: FormatNames["displayName"], options?: Intl.DisplayNamesOptions): string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export {};
|