use-intl 3.25.0 → 4.0.0-beta-00a79d4

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.
Files changed (119) hide show
  1. package/core.d.ts +2 -1
  2. package/dist/esm/development/core.js +82 -0
  3. package/dist/esm/development/index.js +7 -0
  4. package/dist/{development/createFormatter-D2v4ATzl.js → esm/development/initializeConfig-DSmAVNvj.js} +277 -129
  5. package/dist/esm/development/react.js +184 -0
  6. package/dist/esm/production/core.js +1 -0
  7. package/dist/esm/production/index.js +1 -0
  8. package/dist/esm/production/initializeConfig-BE7tJS3N.js +1 -0
  9. package/dist/esm/production/react.js +1 -0
  10. package/dist/types/{src/core → core}/AbstractIntlMessages.d.ts +3 -2
  11. package/dist/types/core/AppConfig.d.ts +25 -0
  12. package/dist/types/{src/core → core}/DateTimeFormatOptions.d.ts +1 -1
  13. package/dist/types/{src/core → core}/Formats.d.ts +2 -2
  14. package/dist/types/core/ICUArgs.d.ts +3 -0
  15. package/dist/types/core/ICUTags.d.ts +2 -0
  16. package/dist/types/{src/core → core}/IntlConfig.d.ts +6 -13
  17. package/dist/types/core/IntlError.d.ts +6 -0
  18. package/dist/types/{src/core/IntlError.d.ts → core/IntlErrorCode.d.ts} +2 -6
  19. package/dist/types/core/MessageKeys.d.ts +10 -0
  20. package/dist/types/core/TranslationValues.d.ts +9 -0
  21. package/dist/types/{src/core → core}/convertFormatsToIntlMessageFormat.d.ts +4 -4
  22. package/dist/types/{src/core → core}/createBaseTranslator.d.ts +9 -12
  23. package/dist/types/core/createFormatter.d.ts +28 -0
  24. package/dist/types/core/createTranslator.d.ts +52 -0
  25. package/dist/types/core/createTranslatorImpl.d.ts +17 -0
  26. package/dist/types/{src/core → core}/defaults.d.ts +1 -1
  27. package/dist/types/{src/core → core}/formatters.d.ts +1 -1
  28. package/dist/types/core/hasLocale.d.ts +10 -0
  29. package/dist/types/core/index.d.ts +20 -0
  30. package/dist/types/{src/core → core}/initializeConfig.d.ts +4 -4
  31. package/dist/types/core/types.d.ts +3 -0
  32. package/dist/types/{src/core → core}/validateMessages.d.ts +2 -2
  33. package/dist/types/core.d.ts +1 -0
  34. package/dist/types/index.d.ts +2 -0
  35. package/dist/types/{src/react → react}/IntlContext.d.ts +2 -2
  36. package/dist/types/react/IntlProvider.d.ts +7 -0
  37. package/dist/types/react/index.d.ts +7 -0
  38. package/dist/types/{src/react → react}/useFormatter.d.ts +1 -1
  39. package/dist/types/{src/react → react}/useIntlContext.d.ts +1 -1
  40. package/dist/types/react/useLocale.d.ts +2 -0
  41. package/dist/types/react/useMessages.d.ts +2 -0
  42. package/dist/types/react/useNow.d.ts +8 -0
  43. package/dist/types/react/useTimeZone.d.ts +1 -0
  44. package/dist/types/react/useTranslations.d.ts +12 -0
  45. package/dist/types/react/useTranslationsImpl.d.ts +9 -0
  46. package/dist/types/react.d.ts +1 -0
  47. package/package.json +18 -24
  48. package/react.d.ts +2 -1
  49. package/_IntlProvider.d.ts +0 -1
  50. package/_useLocale.d.ts +0 -1
  51. package/dist/_IntlProvider.js +0 -7
  52. package/dist/_useLocale.js +0 -7
  53. package/dist/core.js +0 -7
  54. package/dist/development/IntlContext-BKfsnzBx.js +0 -7
  55. package/dist/development/_IntlProvider.js +0 -61
  56. package/dist/development/_useLocale-0Rl9uR82.js +0 -19
  57. package/dist/development/_useLocale.js +0 -11
  58. package/dist/development/core.js +0 -69
  59. package/dist/development/index.js +0 -31
  60. package/dist/development/initializeConfig-BhfMSHP7.js +0 -185
  61. package/dist/development/react.js +0 -151
  62. package/dist/esm/IntlContext-DoS4CDM3.js +0 -1
  63. package/dist/esm/_IntlProvider.js +0 -1
  64. package/dist/esm/_useLocale-v-ZT5JoE.js +0 -1
  65. package/dist/esm/_useLocale.js +0 -1
  66. package/dist/esm/core.js +0 -1
  67. package/dist/esm/createFormatter-zqPbsiYR.js +0 -1
  68. package/dist/esm/index.js +0 -1
  69. package/dist/esm/initializeConfig-D2A8plWf.js +0 -1
  70. package/dist/esm/react.js +0 -1
  71. package/dist/index.js +0 -7
  72. package/dist/production/IntlContext-DcFt0tgW.js +0 -1
  73. package/dist/production/_IntlProvider.js +0 -1
  74. package/dist/production/_useLocale-CpTrqBDt.js +0 -1
  75. package/dist/production/_useLocale.js +0 -1
  76. package/dist/production/core.js +0 -1
  77. package/dist/production/createFormatter-CZeYe_QF.js +0 -1
  78. package/dist/production/index.js +0 -1
  79. package/dist/production/initializeConfig-AbYTngyP.js +0 -1
  80. package/dist/production/react.js +0 -1
  81. package/dist/react.js +0 -7
  82. package/dist/types/src/_IntlProvider.d.ts +0 -1
  83. package/dist/types/src/_useLocale.d.ts +0 -1
  84. package/dist/types/src/core/TranslationValues.d.ts +0 -6
  85. package/dist/types/src/core/createFormatter.d.ts +0 -27
  86. package/dist/types/src/core/createFormatter.test.d.ts +0 -1
  87. package/dist/types/src/core/createTranslator.d.ts +0 -71
  88. package/dist/types/src/core/createTranslator.test.d.ts +0 -1
  89. package/dist/types/src/core/createTranslatorImpl.d.ts +0 -17
  90. package/dist/types/src/core/index.d.ts +0 -18
  91. package/dist/types/src/core/utils/MessageKeys.d.ts +0 -5
  92. package/dist/types/src/core/utils/NamespaceKeys.d.ts +0 -5
  93. package/dist/types/src/core/utils/NestedKeyOf.d.ts +0 -4
  94. package/dist/types/src/core/utils/NestedValueOf.d.ts +0 -2
  95. package/dist/types/src/core.d.ts +0 -1
  96. package/dist/types/src/index.d.ts +0 -2
  97. package/dist/types/src/react/IntlProvider.d.ts +0 -7
  98. package/dist/types/src/react/IntlProvider.test.d.ts +0 -1
  99. package/dist/types/src/react/index.d.ts +0 -7
  100. package/dist/types/src/react/index.test.d.ts +0 -1
  101. package/dist/types/src/react/useFormatter.test.d.ts +0 -1
  102. package/dist/types/src/react/useLocale.d.ts +0 -1
  103. package/dist/types/src/react/useLocale.test.d.ts +0 -1
  104. package/dist/types/src/react/useMessages.d.ts +0 -2
  105. package/dist/types/src/react/useMessages.test.d.ts +0 -1
  106. package/dist/types/src/react/useNow.d.ts +0 -23
  107. package/dist/types/src/react/useNow.test.d.ts +0 -1
  108. package/dist/types/src/react/useTimeZone.d.ts +0 -1
  109. package/dist/types/src/react/useTimeZone.test.d.ts +0 -1
  110. package/dist/types/src/react/useTranslations.d.ts +0 -62
  111. package/dist/types/src/react/useTranslations.test.d.ts +0 -1
  112. package/dist/types/src/react/useTranslationsImpl.d.ts +0 -9
  113. package/dist/types/src/react.d.ts +0 -1
  114. package/dist/types/test/setup.d.ts +0 -1
  115. /package/dist/types/{src/core → core}/NumberFormatOptions.d.ts +0 -0
  116. /package/dist/types/{src/core → core}/RelativeTimeFormatOptions.d.ts +0 -0
  117. /package/dist/types/{src/core → core}/TimeZone.d.ts +0 -0
  118. /package/dist/types/{src/core → core}/joinPath.d.ts +0 -0
  119. /package/dist/types/{src/core → core}/resolveNamespace.d.ts +0 -0
@@ -1,151 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _IntlProvider = require('./_IntlProvider.js');
6
- var _useLocale = require('./_useLocale-0Rl9uR82.js');
7
- var React = require('react');
8
- var createFormatter = require('./createFormatter-D2v4ATzl.js');
9
- var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
10
- require('./IntlContext-BKfsnzBx.js');
11
- require('intl-messageformat');
12
- require('@formatjs/fast-memoize');
13
-
14
- let hasWarnedForMissingTimezone = false;
15
- const isServer = typeof window === 'undefined';
16
- function useTranslationsImpl(allMessagesPrefixed, namespacePrefixed, namespacePrefix) {
17
- const {
18
- cache,
19
- defaultTranslationValues,
20
- formats: globalFormats,
21
- formatters,
22
- getMessageFallback,
23
- locale,
24
- onError,
25
- timeZone
26
- } = _useLocale.useIntlContext();
27
-
28
- // The `namespacePrefix` is part of the type system.
29
- // See the comment in the hook invocation.
30
- const allMessages = allMessagesPrefixed[namespacePrefix];
31
- const namespace = createFormatter.resolveNamespace(namespacePrefixed, namespacePrefix);
32
- if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
33
- // eslint-disable-next-line react-compiler/react-compiler
34
- hasWarnedForMissingTimezone = true;
35
- onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone" ));
36
- }
37
- const translate = React.useMemo(() => createFormatter.createBaseTranslator({
38
- cache,
39
- formatters,
40
- getMessageFallback,
41
- messages: allMessages,
42
- defaultTranslationValues,
43
- namespace,
44
- onError,
45
- formats: globalFormats,
46
- locale,
47
- timeZone
48
- }), [cache, formatters, getMessageFallback, allMessages, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
49
- return translate;
50
- }
51
-
52
- /**
53
- * Translates messages from the given namespace by using the ICU syntax.
54
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
55
- *
56
- * If no namespace is provided, all available messages are returned.
57
- * The namespace can also indicate nesting by using a dot
58
- * (e.g. `namespace.Component`).
59
- */
60
- function useTranslations(namespace) {
61
- const context = _useLocale.useIntlContext();
62
- const messages = context.messages;
63
-
64
- // We have to wrap the actual hook so the type inference for the optional
65
- // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
66
- // The prefix ("!") is arbitrary.
67
- return useTranslationsImpl({
68
- '!': messages
69
- },
70
- // @ts-expect-error
71
- namespace ? "!.".concat(namespace) : '!', '!');
72
- }
73
-
74
- function getNow() {
75
- return new Date();
76
- }
77
-
78
- /**
79
- * Reading the current date via `new Date()` in components should be avoided, as
80
- * it causes components to be impure and can lead to flaky tests. Instead, this
81
- * hook can be used.
82
- *
83
- * By default, it returns the time when the component mounts. If `updateInterval`
84
- * is specified, the value will be updated based on the interval.
85
- *
86
- * You can however also return a static value from this hook, if you
87
- * configure the `now` parameter on the context provider. Note however,
88
- * that if `updateInterval` is configured in this case, the component
89
- * will initialize with the global value, but will afterwards update
90
- * continuously based on the interval.
91
- *
92
- * For unit tests, this can be mocked to a constant value. For end-to-end
93
- * testing, an environment parameter can be passed to the `now` parameter
94
- * of the provider to mock this to a static value.
95
- */
96
- function useNow(options) {
97
- const updateInterval = options === null || options === void 0 ? void 0 : options.updateInterval;
98
- const {
99
- now: globalNow
100
- } = _useLocale.useIntlContext();
101
- const [now, setNow] = React.useState(globalNow || getNow());
102
- React.useEffect(() => {
103
- if (!updateInterval) return;
104
- const intervalId = setInterval(() => {
105
- setNow(getNow());
106
- }, updateInterval);
107
- return () => {
108
- clearInterval(intervalId);
109
- };
110
- }, [globalNow, updateInterval]);
111
- return updateInterval == null && globalNow ? globalNow : now;
112
- }
113
-
114
- function useTimeZone() {
115
- return _useLocale.useIntlContext().timeZone;
116
- }
117
-
118
- function useMessages() {
119
- const context = _useLocale.useIntlContext();
120
- if (!context.messages) {
121
- throw new Error('No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages' );
122
- }
123
- return context.messages;
124
- }
125
-
126
- function useFormatter() {
127
- const {
128
- formats,
129
- formatters,
130
- locale,
131
- now: globalNow,
132
- onError,
133
- timeZone
134
- } = _useLocale.useIntlContext();
135
- return React.useMemo(() => createFormatter.createFormatter({
136
- formats,
137
- locale,
138
- now: globalNow,
139
- onError,
140
- timeZone,
141
- _formatters: formatters
142
- }), [formats, formatters, globalNow, locale, onError, timeZone]);
143
- }
144
-
145
- exports.IntlProvider = _IntlProvider.IntlProvider;
146
- exports.useLocale = _useLocale.useLocale;
147
- exports.useFormatter = useFormatter;
148
- exports.useMessages = useMessages;
149
- exports.useNow = useNow;
150
- exports.useTimeZone = useTimeZone;
151
- exports.useTranslations = useTranslations;
@@ -1 +0,0 @@
1
- import{createContext as o}from"react";const r=o(void 0);export{r as I};
@@ -1 +0,0 @@
1
- import e,{useMemo as a}from"react";import{b as o,c as t,i as r}from"./initializeConfig-D2A8plWf.js";import{I as s}from"./IntlContext-DoS4CDM3.js";import"@formatjs/fast-memoize";function l(l){let{children:n,defaultTranslationValues:i,formats:m,getMessageFallback:c,locale:f,messages:g,now:u,onError:p,timeZone:d}=l;const b=a((()=>o()),[f]),j=a((()=>t(b)),[b]),E=a((()=>({...r({locale:f,defaultTranslationValues:i,formats:m,getMessageFallback:c,messages:g,now:u,onError:p,timeZone:d}),formatters:j,cache:b})),[b,i,m,j,c,f,g,u,p,d]);return e.createElement(s.Provider,{value:E},n)}export{l as IntlProvider};
@@ -1 +0,0 @@
1
- import{useContext as o}from"react";import{I as t}from"./IntlContext-DoS4CDM3.js";function e(){const e=o(t);if(!e)throw new Error("No intl context found. Have you configured the provider? See https://next-intl-docs.vercel.app/docs/usage/configuration#client-server-components");return e}function n(){return e().locale}export{e as a,n as u};
@@ -1 +0,0 @@
1
- export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import"react";import"./IntlContext-DoS4CDM3.js";
package/dist/esm/core.js DELETED
@@ -1 +0,0 @@
1
- import{b as e,c as r,e as t,d as s}from"./initializeConfig-D2A8plWf.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";import{r as o,a as m}from"./createFormatter-zqPbsiYR.js";export{c as createFormatter}from"./createFormatter-zqPbsiYR.js";import"@formatjs/fast-memoize";import"intl-messageformat";import"react";function n(a){let{_cache:i=e(),_formatters:c=r(i),getMessageFallback:n=t,messages:f,namespace:l,onError:g=s,...p}=a;return function(e,a){let{messages:r,namespace:t,...s}=e;return r=r[a],t=o(t,a),m({...s,messages:r,namespace:t})}({...p,onError:g,cache:i,formatters:c,getMessageFallback:n,messages:{"!":f},namespace:l?"!.".concat(l):"!"},"!")}export{e as _createCache,r as _createIntlFormatters,n as createTranslator};
@@ -1 +0,0 @@
1
- import e from"intl-messageformat";import{isValidElement as t,cloneElement as n}from"react";import{I as r,a as o,j as a,d as s,e as i,m as c,b as u,c as m}from"./initializeConfig-D2A8plWf.js";function l(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function f(e,t,n,r){const o=a(r,n);if(!t)throw new Error("No messages available at `".concat(r,"`."));let s=t;return n.split(".").forEach((t=>{const n=s[t];if(null==t||null==n)throw new Error("Could not resolve `".concat(o,"` in messages for locale `").concat(e,"`."));s=n})),s}function g(u){const m=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:s;try{if(!t)throw new Error("No messages were configured on the provider.");const r=n?f(e,t,n):t;if(!r)throw new Error("No messages for namespace `".concat(n,"` found."));return r}catch(e){const t=new r(o.MISSING_MESSAGE,e.message);return a(t),t}}(u.locale,u.messages,u.namespace,u.onError);return function(s){let{cache:u,defaultTranslationValues:m,formats:g,formatters:d,getMessageFallback:p=i,locale:h,messagesOrError:y,namespace:v,onError:w,timeZone:E}=s;const T=y instanceof r;function S(e,t,n){const o=new r(t,n);return w(o),p({error:o,key:e,namespace:v})}function b(r,s,i){if(T)return p({error:y,key:r,namespace:v});const w=y;let b,M;try{b=f(h,w,r,v)}catch(e){return S(r,o.MISSING_MESSAGE,e.message)}if("object"==typeof b){let e,t;return Array.isArray(b)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(v,r),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=o.INSUFFICIENT_PATH,t="Message at `".concat(a(v,r),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),S(r,e,t)}const I=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(b,s);if(I)return I;d.getMessageFormat||(d.getMessageFormat=function(t,n){const r=c((function(){return new e(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:n,...arguments.length<=3?void 0:arguments[3]})}),t.message);return r}(u,d));try{M=d.getMessageFormat(b,h,function(t,n){const r=n?{...t,dateTime:l(t.dateTime,n)}:t,o=e.formats.date,a=n?l(o,n):o,s=e.formats.time,i=n?l(s,n):s;return{...r,date:{...a,...r.dateTime},time:{...i,...r.dateTime}}}({...g,...i},E),{formatters:{...d,getDateTimeFormat:(e,t)=>d.getDateTimeFormat(e,{timeZone:E,...t})}})}catch(e){const t=e;return S(r,o.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}try{const e=M.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const r=s(e);return t(r)?n(r,{key:o+a++}):r}:s,r[o]=i})),r}({...m,...s}));if(null==e)throw new Error("Unable to format `".concat(r,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return S(r,o.FORMATTING_ERROR,e.message)}}function M(e,t,n){const r=b(e,t,n);return"string"!=typeof r?S(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return M.rich=b,M.markup=(e,t,n)=>{const a=b(e,t,n);if("string"!=typeof a){const t=new r(o.FORMATTING_ERROR,"`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})");return w(t),p({error:t,key:e,namespace:v})}return a},M.raw=e=>{if(T)return p({error:y,key:e,namespace:v});const t=y;try{return f(h,t,e,v)}catch(t){return S(e,o.MISSING_MESSAGE,t.message)}},M.has=e=>{if(T)return!1;try{return f(h,y,e,v),!0}catch(e){return!1}},M}({...u,messagesOrError:m})}function d(e,t){return e===t?void 0:e.slice((t+".").length)}const p=60,h=60*p,y=24*h,v=7*y,w=y*(365/12),E=3*w,T=365*y,S={second:1,seconds:1,minute:p,minutes:p,hour:h,hours:h,day:y,days:y,week:v,weeks:v,month:w,months:w,quarter:E,quarters:E,year:T,years:T};function b(e){let{_cache:t=u(),_formatters:n=m(t),formats:a,locale:i,now:c,onError:l=s,timeZone:f}=e;function g(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(f?e={...e,timeZone:f}:l(new r(o.ENVIRONMENT_FALLBACK,"The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),e}function d(e,t,n,a){let s;try{s=function(e,t){let n;if("string"==typeof t){const a=t;if(n=null==e?void 0:e[a],!n){const e=new r(o.MISSING_FORMAT,"Format `".concat(a,"` is not available. You can configure it on the provider or provide custom options."));throw l(e),e}}else n=t;return n}(t,e)}catch(e){return a()}try{return n(s)}catch(e){return l(new r(o.FORMATTING_ERROR,e.message)),a()}}function E(e,t){return d(t,null==a?void 0:a.dateTime,(t=>(t=g(t),n.getDateTimeFormat(i,t).format(e))),(()=>String(e)))}function b(){return c||(l(new r(o.ENVIRONMENT_FALLBACK,"The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now")),new Date)}return{dateTime:E,number:function(e,t){return d(t,null==a?void 0:a.number,(t=>n.getNumberFormat(i,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const a={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):b(),o=t.unit,a.style=t.style,a.numberingSystem=t.numberingSystem),r||(r=b());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<p?"second":t<h?"minute":t<y?"hour":t<v?"day":t<w?"week":t<T?"month":"year"}(s)),a.numeric="second"===o?"auto":"always";const c=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(i,a).format(c,o)}catch(t){return l(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],o=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),o.set(e,t)):e=String(t),r.push(e),s++}return d(t,null==a?void 0:a.list,(e=>{const t=n.getListFormat(i,e).formatToParts(r).map((e=>"literal"===e.type?e.value:o.get(e.value)||e.value));return o.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,r){return d(r,null==a?void 0:a.dateTime,(r=>(r=g(r),n.getDateTimeFormat(i,r).formatRange(e,t))),(()=>[E(e),E(t)].join(" – ")))}}}export{g as a,b as c,d as r};
package/dist/esm/index.js DELETED
@@ -1 +0,0 @@
1
- export{I as IntlError,a as IntlErrorCode,b as _createCache,c as _createIntlFormatters,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-zqPbsiYR.js";export{IntlProvider}from"./_IntlProvider.js";export{useFormatter,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import"@formatjs/fast-memoize";import"intl-messageformat";import"react";import"./IntlContext-DoS4CDM3.js";
@@ -1 +0,0 @@
1
- import{memoize as e,strategies as t}from"@formatjs/fast-memoize";function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let 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}({});class a extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),n(this,"code",void 0),n(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function o(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter(Boolean).join(".")}function i(e){return o(e.namespace,e.key)}function s(e){console.error(e)}function l(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function u(n,r){return e(n,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:t.variadic});var a}function c(e,t){return u((function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e(...n)}),t)}function m(e){return{getDateTimeFormat:c(Intl.DateTimeFormat,e.dateTime),getNumberFormat:c(Intl.NumberFormat,e.number),getPluralRules:c(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:c(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:c(Intl.ListFormat,e.list),getDisplayNames:c(Intl.DisplayNames,e.displayNames)}}function f(e,t,n){Object.entries(e).forEach((e=>{let[r,a]=e;if(r.includes(".")){let e=r;n&&(e+=" (at ".concat(n,")")),t.push(e)}null!=a&&"object"==typeof a&&f(a,t,o(n,r))}))}function I(e,t){const n=[];f(e,n),n.length>0&&t(new a(r.INVALID_KEY,'Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid '.concat(1===n.length?"key":"keys",": ").concat(n.join(", "),'\n\nIf you\'re migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from "lodash";\n\nconst input = {\n "one.one": "1.1",\n "one.two": "1.2",\n "two.one.one": "2.1.1"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// "one": {\n// "one": "1.1",\n// "two": "1.2"\n// },\n// "two": {\n// "one": {\n// "one": "2.1.1"\n// }\n// }\n// }\n')))}function g(e){let{getMessageFallback:t,messages:n,onError:r,...a}=e;const o=r||s,l=t||i;return n&&I(n,o),{...a,messages:n,onError:o,getMessageFallback:l}}export{a as I,r as a,l as b,m as c,s as d,i as e,g as i,o as j,u as m};
package/dist/esm/react.js DELETED
@@ -1 +0,0 @@
1
- export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-v-ZT5JoE.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import{useMemo as t,useState as o,useEffect as r}from"react";import{r as n,a,c as s}from"./createFormatter-zqPbsiYR.js";import{I as i,a as c}from"./initializeConfig-D2A8plWf.js";import"./IntlContext-DoS4CDM3.js";import"intl-messageformat";import"@formatjs/fast-memoize";let m=!1;const l="undefined"==typeof window;function f(o){return function(o,r,s){const{cache:f,defaultTranslationValues:u,formats:d,formatters:p,getMessageFallback:g,locale:v,onError:h,timeZone:w}=e(),I=o[s],j=n(r,s);return w||m||!l||(m=!0,h(new i(c.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),t((()=>a({cache:f,formatters:p,getMessageFallback:g,messages:I,defaultTranslationValues:u,namespace:j,onError:h,formats:d,locale:v,timeZone:w})),[f,p,g,I,u,j,h,d,v,w])}({"!":e().messages},o?"!.".concat(o):"!","!")}function d(){return new Date}function p(t){const n=null==t?void 0:t.updateInterval,{now:a}=e(),[s,i]=o(a||d());return r((()=>{if(!n)return;const e=setInterval((()=>{i(d())}),n);return()=>{clearInterval(e)}}),[a,n]),null==n&&a?a:s}function g(){return e().timeZone}function v(){const t=e();if(!t.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return t.messages}function h(){const{formats:o,formatters:r,locale:n,now:a,onError:i,timeZone:c}=e();return t((()=>s({formats:o,locale:n,now:a,onError:i,timeZone:c,_formatters:r})),[o,r,a,n,i,c])}export{h as useFormatter,v as useMessages,p as useNow,g as useTimeZone,f as useTranslations};
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./production/index.js');
5
- } else {
6
- module.exports = require('./development/index.js');
7
- }
@@ -1 +0,0 @@
1
- "use strict";const t=require("react").createContext(void 0);exports.IntlContext=t;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-AbYTngyP.js"),r=require("./IntlContext-DcFt0tgW.js");function a(e){return e&&e.__esModule?e:{default:e}}require("@formatjs/fast-memoize");var o=a(e);exports.IntlProvider=function(a){let{children:s,defaultTranslationValues:n,formats:l,getMessageFallback:i,locale:u,messages:c,now:m,onError:f,timeZone:d}=a;const g=e.useMemo((()=>t.createCache()),[u]),M=e.useMemo((()=>t.createIntlFormatters(g)),[g]),v=e.useMemo((()=>({...t.initializeConfig({locale:u,defaultTranslationValues:n,formats:l,getMessageFallback:i,messages:c,now:m,onError:f,timeZone:d}),formatters:M,cache:g})),[g,n,l,M,i,u,c,m,f,d]);return o.default.createElement(r.IntlContext.Provider,{value:v},s)};
@@ -1 +0,0 @@
1
- "use strict";var t=require("react"),e=require("./IntlContext-DcFt0tgW.js");function r(){const r=t.useContext(e.IntlContext);if(!r)throw new Error(void 0);return r}exports.useIntlContext=r,exports.useLocale=function(){return r().locale};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_useLocale-CpTrqBDt.js");require("react"),require("./IntlContext-DcFt0tgW.js"),exports.useLocale=e.useLocale;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-CZeYe_QF.js"),r=require("./initializeConfig-AbYTngyP.js");require("intl-messageformat"),require("react"),require("@formatjs/fast-memoize"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports._createCache=r.createCache,exports._createIntlFormatters=r.createIntlFormatters,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(t){let{_cache:a=r.createCache(),_formatters:s=r.createIntlFormatters(a),getMessageFallback:o=r.defaultGetMessageFallback,messages:c,namespace:n,onError:i=r.defaultOnError,...l}=t;return function(r,t){let{messages:a,namespace:s,...o}=r;return a=a[t],s=e.resolveNamespace(s,t),e.createBaseTranslator({...o,messages:a,namespace:s})}({...l,onError:i,cache:a,formatters:s,getMessageFallback:o,messages:{"!":c},namespace:n?"!.".concat(n):"!"},"!")};
@@ -1 +0,0 @@
1
- "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-AbYTngyP.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let i=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}({});class s extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),a(this,"code",void 0),a(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function u(e,t){return e?Object.keys(e).reduce(((r,n)=>(r[n]={timeZone:t,...e[n]},r)),{}):e}function c(e,t,n,o){const a=r.joinPath(o,n);if(!t)throw new Error(a);let i=t;return n.split(".").forEach((t=>{const r=i[t];if(null==t||null==r)throw new Error(a+" (".concat(e,")"));i=r})),i}const l=60,m=60*l,f=24*m,g=7*f,E=f*(365/12),d=3*E,I=365*f,S={second:1,seconds:1,minute:l,minutes:l,hour:m,hours:m,day:f,days:f,week:g,weeks:g,month:E,months:E,quarter:d,quarters:d,year:I,years:I};exports.IntlError=s,exports.IntlErrorCode=i,exports.createBaseTranslator=function(e){const n=function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:r.defaultOnError;try{if(!t)throw new Error(void 0);const r=n?c(e,t,n):t;if(!r)throw new Error(n);return r}catch(e){const t=new s(i.MISSING_MESSAGE,e.message);return o(t),t}}(e.locale,e.messages,e.namespace,e.onError);return function(e){let{cache:n,defaultTranslationValues:a,formats:l,formatters:m,getMessageFallback:f=r.defaultGetMessageFallback,locale:g,messagesOrError:E,namespace:d,onError:I,timeZone:S}=e;const y=E instanceof s;function T(e,t,r){const n=new s(t,r);return I(n),f({error:n,key:e,namespace:d})}function h(e,s,I){if(y)return f({error:E,key:e,namespace:d});const h=E;let M,N;try{M=c(g,h,e,d)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}if("object"==typeof M){let t,r;return t=Array.isArray(M)?i.INVALID_MESSAGE:i.INSUFFICIENT_PATH,T(e,t,r)}const A=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(M,s);if(A)return A;m.getMessageFormat||(m.getMessageFormat=function(e,t){const n=r.memoFn((function(){return new o.default(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:t,...arguments.length<=3?void 0:arguments[3]})}),e.message);return n}(n,m));try{N=m.getMessageFormat(M,g,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,a=t?u(n,t):n,i=o.default.formats.time,s=t?u(i,t):i;return{...r,date:{...a,...r.dateTime},time:{...s,...r.dateTime}}}({...l,...I},S),{formatters:{...m,getDateTimeFormat:(e,t)=>m.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(t){const r=t;return T(e,i.INVALID_MESSAGE,r.message)}try{const e=N.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let i;i="function"==typeof a?e=>{const r=a(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:a,r[n]=i})),r}({...a,...s}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return T(e,i.FORMATTING_ERROR,t.message)}}function M(e,t,r){const n=h(e,t,r);return"string"!=typeof n?T(e,i.INVALID_MESSAGE,void 0):n}return M.rich=h,M.markup=(e,t,r)=>{const n=h(e,t,r);if("string"!=typeof n){const t=new s(i.FORMATTING_ERROR,void 0);return I(t),f({error:t,key:e,namespace:d})}return n},M.raw=e=>{if(y)return f({error:E,key:e,namespace:d});const t=E;try{return c(g,t,e,d)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}},M.has=e=>{if(y)return!1;try{return c(g,E,e,d),!0}catch(e){return!1}},M}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{_cache:t=r.createCache(),_formatters:n=r.createIntlFormatters(t),formats:o,locale:a,now:u,onError:c=r.defaultOnError,timeZone:d}=e;function y(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(d?e={...e,timeZone:d}:c(new s(i.ENVIRONMENT_FALLBACK,void 0))),e}function T(e,t,r,n){let o;try{o=function(e,t){let r;if("string"==typeof t){if(r=null==e?void 0:e[t],!r){const e=new s(i.MISSING_FORMAT,void 0);throw c(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return c(new s(i.FORMATTING_ERROR,e.message)),n()}}function h(e,t){return T(t,null==o?void 0:o.dateTime,(t=>(t=y(t),n.getDateTimeFormat(a,t).format(e))),(()=>String(e)))}function M(){return u||(c(new s(i.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:h,number:function(e,t){return T(t,null==o?void 0:o.number,(t=>n.getNumberFormat(a,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const i={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):M(),o=t.unit,i.style=t.style,i.numberingSystem=t.numberingSystem),r||(r=M());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<l?"second":t<m?"minute":t<f?"hour":t<g?"day":t<E?"week":t<I?"month":"year"}(s)),i.numeric="second"===o?"auto":"always";const u=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(a,i).format(u,o)}catch(t){return c(new s(i.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],i=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),i.set(e,t)):e=String(t),r.push(e),s++}return T(t,null==o?void 0:o.list,(e=>{const t=n.getListFormat(a,e).formatToParts(r).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,r){return T(r,null==o?void 0:o.dateTime,(r=>(r=y(r),n.getDateTimeFormat(a,r).formatRange(e,t))),(()=>[h(e),h(t)].join(" – ")))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-CZeYe_QF.js"),r=require("./core.js"),t=require("./initializeConfig-AbYTngyP.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-CpTrqBDt.js");require("intl-messageformat"),require("react"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports._createCache=t.createCache,exports._createIntlFormatters=t.createIntlFormatters,exports.initializeConfig=t.initializeConfig,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=a.useLocale;
@@ -1 +0,0 @@
1
- "use strict";var e=require("@formatjs/fast-memoize");function t(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(".")}function r(e){return t(e.namespace,e.key)}function a(e){console.error(e)}function n(t,r){return e.memoize(t,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:e.strategies.variadic});var a}function s(e,t){return n((function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];return new e(...r)}),t)}exports.createCache=function(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}},exports.createIntlFormatters=function(e){return{getDateTimeFormat:s(Intl.DateTimeFormat,e.dateTime),getNumberFormat:s(Intl.NumberFormat,e.number),getPluralRules:s(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:s(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:s(Intl.ListFormat,e.list),getDisplayNames:s(Intl.DisplayNames,e.displayNames)}},exports.defaultGetMessageFallback=r,exports.defaultOnError=a,exports.initializeConfig=function(e){let{getMessageFallback:t,messages:n,onError:s,...i}=e;return{...i,messages:n,onError:s||a,getMessageFallback:t||r}},exports.joinPath=t,exports.memoFn=n;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-CpTrqBDt.js"),r=require("react"),o=require("./createFormatter-CZeYe_QF.js");require("./initializeConfig-AbYTngyP.js"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,formatters:n,locale:s,now:a,onError:u,timeZone:l}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:s,now:a,onError:u,timeZone:l,_formatters:n})),[e,n,a,s,u,l])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),null==o&&n?n:s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{cache:l,defaultTranslationValues:i,formats:c,formatters:m,getMessageFallback:f,locale:I,onError:d,timeZone:x}=t.useIntlContext(),p=e[u],v=o.resolveNamespace(a,u);return x||n||!s||(n=!0,d(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({cache:l,formatters:m,getMessageFallback:f,messages:p,defaultTranslationValues:i,namespace:v,onError:d,formats:c,locale:I,timeZone:x})),[l,m,f,p,i,v,d,c,I,x])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
package/dist/react.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./production/react.js');
5
- } else {
6
- module.exports = require('./development/react.js');
7
- }
@@ -1 +0,0 @@
1
- export { default as IntlProvider } from './react/IntlProvider';
@@ -1 +0,0 @@
1
- export { default as useLocale } from './react/useLocale';
@@ -1,6 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export type TranslationValue = string | number | boolean | Date | null | undefined;
3
- type TranslationValues = Record<string, TranslationValue>;
4
- export type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
5
- export type MarkupTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
- export default TranslationValues;
@@ -1,27 +0,0 @@
1
- import { ReactElement } from 'react';
2
- import DateTimeFormatOptions from './DateTimeFormatOptions';
3
- import Formats from './Formats';
4
- import IntlError from './IntlError';
5
- import NumberFormatOptions from './NumberFormatOptions';
6
- import RelativeTimeFormatOptions from './RelativeTimeFormatOptions';
7
- import TimeZone from './TimeZone';
8
- import { Formatters, IntlCache } from './formatters';
9
- type Props = {
10
- locale: string;
11
- timeZone?: TimeZone;
12
- onError?(error: IntlError): void;
13
- formats?: Formats;
14
- now?: Date;
15
- /** @private */
16
- _formatters?: Formatters;
17
- /** @private */
18
- _cache?: IntlCache;
19
- };
20
- export default function createFormatter({ _cache: cache, _formatters: formatters, formats, locale, now: globalNow, onError, timeZone: globalTimeZone }: Props): {
21
- dateTime: (value: Date | number, formatOrOptions?: Extract<keyof IntlFormats["dateTime"], string> | DateTimeFormatOptions) => string;
22
- number: (value: number | bigint, formatOrOptions?: Extract<keyof IntlFormats["number"], string> | NumberFormatOptions) => string;
23
- relativeTime: (date: number | Date, nowOrOptions?: RelativeTimeFormatOptions["now"] | RelativeTimeFormatOptions) => string;
24
- list: <Value extends string | ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, formatOrOptions?: Extract<keyof IntlFormats["list"], string> | Intl.ListFormatOptions) => Value extends string ? string : Iterable<ReactElement>;
25
- dateTimeRange: (start: Date | number, end: Date | number, formatOrOptions?: Extract<keyof IntlFormats["dateTime"], string> | DateTimeFormatOptions) => string;
26
- };
27
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,71 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import Formats from './Formats';
3
- import IntlConfig from './IntlConfig';
4
- import TranslationValues, { MarkupTranslationValues, RichTranslationValues } from './TranslationValues';
5
- import { Formatters, IntlCache } from './formatters';
6
- import MessageKeys from './utils/MessageKeys';
7
- import NamespaceKeys from './utils/NamespaceKeys';
8
- import NestedKeyOf from './utils/NestedKeyOf';
9
- import NestedValueOf from './utils/NestedValueOf';
10
- /**
11
- * Translates messages from the given namespace by using the ICU syntax.
12
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
13
- *
14
- * If no namespace is provided, all available messages are returned.
15
- * The namespace can also indicate nesting by using a dot
16
- * (e.g. `namespace.Component`).
17
- */
18
- export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
19
- messages?: IntlConfig<IntlMessages>['messages'];
20
- namespace?: NestedKey;
21
- /** @private */
22
- _formatters?: Formatters;
23
- /** @private */
24
- _cache?: IntlCache;
25
- }): {
26
- <TargetKey extends MessageKeys<NestedValueOf<{
27
- '!': IntlMessages;
28
- }, [
29
- NestedKey
30
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
31
- '!': IntlMessages;
32
- }, [
33
- NestedKey
34
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats): string;
35
- rich<TargetKey extends MessageKeys<NestedValueOf<{
36
- '!': IntlMessages;
37
- }, [
38
- NestedKey
39
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
40
- '!': IntlMessages;
41
- }, [
42
- NestedKey
43
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Formats): ReactNode;
44
- markup<TargetKey extends MessageKeys<NestedValueOf<{
45
- '!': IntlMessages;
46
- }, [
47
- NestedKey
48
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
49
- '!': IntlMessages;
50
- }, [
51
- NestedKey
52
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: MarkupTranslationValues, formats?: Formats): string;
53
- raw<TargetKey extends MessageKeys<NestedValueOf<{
54
- '!': IntlMessages;
55
- }, [
56
- NestedKey
57
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
58
- '!': IntlMessages;
59
- }, [
60
- NestedKey
61
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
62
- has<TargetKey extends MessageKeys<NestedValueOf<{
63
- '!': IntlMessages;
64
- }, [
65
- NestedKey
66
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
67
- '!': IntlMessages;
68
- }, [
69
- NestedKey
70
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): boolean;
71
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import AbstractIntlMessages from './AbstractIntlMessages';
2
- import { InitializedIntlConfig } from './IntlConfig';
3
- import { Formatters, IntlCache } from './formatters';
4
- import NestedKeyOf from './utils/NestedKeyOf';
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<import(".").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import(".").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues").default, formats?: import("./Formats").default): string;
13
- rich: (key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => import("react").ReactNode;
14
- markup(key: Parameters<(key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => import("react").ReactNode>[0], values: import("./TranslationValues").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => import("react").ReactNode>[2]): string;
15
- raw(key: string): any;
16
- has(key: Parameters<(key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => import("react").ReactNode>[0]): boolean;
17
- };
@@ -1,18 +0,0 @@
1
- export type { default as AbstractIntlMessages } from './AbstractIntlMessages';
2
- export type { default as TranslationValues, RichTranslationValues, MarkupTranslationValues } from './TranslationValues';
3
- export type { default as Formats } from './Formats';
4
- export type { default as IntlConfig } from './IntlConfig';
5
- export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
6
- export type { default as NumberFormatOptions } from './NumberFormatOptions';
7
- export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatOptions';
8
- export type { default as Timezone } from './TimeZone';
9
- export { default as IntlError, IntlErrorCode } from './IntlError';
10
- export { default as createTranslator } from './createTranslator';
11
- export { default as createFormatter } from './createFormatter';
12
- export { default as initializeConfig } from './initializeConfig';
13
- export type { default as MessageKeys } from './utils/MessageKeys';
14
- export type { default as NamespaceKeys } from './utils/NamespaceKeys';
15
- export type { default as NestedKeyOf } from './utils/NestedKeyOf';
16
- export type { default as NestedValueOf } from './utils/NestedValueOf';
17
- export { createIntlFormatters as _createIntlFormatters } from './formatters';
18
- export { createCache as _createCache } from './formatters';
@@ -1,5 +0,0 @@
1
- import NestedValueOf from './NestedValueOf';
2
- type MessageKeys<ObjectType, Keys extends string> = {
3
- [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? Property : never;
4
- }[Keys];
5
- export default MessageKeys;
@@ -1,5 +0,0 @@
1
- import NestedValueOf from './NestedValueOf';
2
- type NamespaceKeys<ObjectType, Keys extends string> = {
3
- [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? never : Property;
4
- }[Keys];
5
- export default NamespaceKeys;
@@ -1,4 +0,0 @@
1
- type NestedKeyOf<ObjectType> = ObjectType extends object ? {
2
- [Key in keyof ObjectType]: `${Key & string}` | `${Key & string}.${NestedKeyOf<ObjectType[Key]>}`;
3
- }[keyof ObjectType] : never;
4
- export default NestedKeyOf;
@@ -1,2 +0,0 @@
1
- type NestedValueOf<ObjectType, Property extends string> = Property extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? NestedValueOf<ObjectType[Key], Rest> : never : Property extends keyof ObjectType ? ObjectType[Property] : never;
2
- export default NestedValueOf;
@@ -1 +0,0 @@
1
- export * from './core/index';
@@ -1,2 +0,0 @@
1
- export * from './core';
2
- export * from './react';
@@ -1,7 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import IntlConfig from '../core/IntlConfig';
3
- type Props = IntlConfig & {
4
- children: ReactNode;
5
- };
6
- export default function IntlProvider({ children, defaultTranslationValues, formats, getMessageFallback, locale, messages, now, onError, timeZone }: Props): React.JSX.Element;
7
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- export { default as IntlProvider } from './IntlProvider';
2
- export { default as useTranslations } from './useTranslations';
3
- export { default as useLocale } from './useLocale';
4
- export { default as useNow } from './useNow';
5
- export { default as useTimeZone } from './useTimeZone';
6
- export { default as useMessages } from './useMessages';
7
- export { default as useFormatter } from './useFormatter';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export default function useLocale(): string;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { AbstractIntlMessages } from '../core';
2
- export default function useMessages(): AbstractIntlMessages;
@@ -1 +0,0 @@
1
- export {};
@@ -1,23 +0,0 @@
1
- type Options = {
2
- updateInterval?: number;
3
- };
4
- /**
5
- * Reading the current date via `new Date()` in components should be avoided, as
6
- * it causes components to be impure and can lead to flaky tests. Instead, this
7
- * hook can be used.
8
- *
9
- * By default, it returns the time when the component mounts. If `updateInterval`
10
- * is specified, the value will be updated based on the interval.
11
- *
12
- * You can however also return a static value from this hook, if you
13
- * configure the `now` parameter on the context provider. Note however,
14
- * that if `updateInterval` is configured in this case, the component
15
- * will initialize with the global value, but will afterwards update
16
- * continuously based on the interval.
17
- *
18
- * For unit tests, this can be mocked to a constant value. For end-to-end
19
- * testing, an environment parameter can be passed to the `now` parameter
20
- * of the provider to mock this to a static value.
21
- */
22
- export default function useNow(options?: Options): Date;
23
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export default function useTimeZone(): import("..").Timezone | undefined;
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import Formats from '../core/Formats';
3
- import TranslationValues, { MarkupTranslationValues, RichTranslationValues } from '../core/TranslationValues';
4
- import MessageKeys from '../core/utils/MessageKeys';
5
- import NamespaceKeys from '../core/utils/NamespaceKeys';
6
- import NestedKeyOf from '../core/utils/NestedKeyOf';
7
- import NestedValueOf from '../core/utils/NestedValueOf';
8
- /**
9
- * Translates messages from the given namespace by using the ICU syntax.
10
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
11
- *
12
- * If no namespace is provided, all available messages are returned.
13
- * The namespace can also indicate nesting by using a dot
14
- * (e.g. `namespace.Component`).
15
- */
16
- export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(namespace?: NestedKey): {
17
- <TargetKey extends MessageKeys<NestedValueOf<{
18
- '!': IntlMessages;
19
- }, [
20
- NestedKey
21
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
22
- '!': IntlMessages;
23
- }, [
24
- NestedKey
25
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats): string;
26
- rich<TargetKey extends MessageKeys<NestedValueOf<{
27
- '!': IntlMessages;
28
- }, [
29
- NestedKey
30
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
31
- '!': IntlMessages;
32
- }, [
33
- NestedKey
34
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Formats): ReactNode;
35
- markup<TargetKey extends MessageKeys<NestedValueOf<{
36
- '!': IntlMessages;
37
- }, [
38
- NestedKey
39
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
40
- '!': IntlMessages;
41
- }, [
42
- NestedKey
43
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: MarkupTranslationValues, formats?: Formats): string;
44
- raw<TargetKey extends MessageKeys<NestedValueOf<{
45
- '!': IntlMessages;
46
- }, [
47
- NestedKey
48
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
49
- '!': IntlMessages;
50
- }, [
51
- NestedKey
52
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
53
- has<TargetKey extends MessageKeys<NestedValueOf<{
54
- '!': IntlMessages;
55
- }, [
56
- NestedKey
57
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
58
- '!': IntlMessages;
59
- }, [
60
- NestedKey
61
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): boolean;
62
- };
@@ -1 +0,0 @@
1
- export {};