use-intl 2.20.2 → 2.22.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/README.md +13 -16
- package/dist/core/RelativeTimeFormatOptions.d.ts +5 -0
- package/dist/core/createFormatter.d.ts +2 -1
- package/dist/core/createIntl.d.ts +1 -1
- package/dist/core/use-intl.esm3.js +56 -39
- package/dist/core/use-intl.esm3.js.map +1 -1
- package/dist/core/use-intl.esm5.js +2 -2
- package/dist/core/use-intl.esm7.js +7 -197
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/core/use-intl.esm8.js +197 -7
- package/dist/core/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm12.js +2 -2
- package/dist/react/useFormatter.d.ts +1 -1
- package/dist/react/useIntl.d.ts +1 -1
- package/dist/src/core/RelativeTimeFormatOptions.d.ts +5 -0
- package/dist/src/core/RelativeTimeFormatOptions.js +2 -0
- package/dist/src/core/RelativeTimeFormatOptions.js.map +1 -0
- package/dist/src/core/createFormatter.d.ts +2 -1
- package/dist/src/core/createFormatter.js +63 -39
- package/dist/src/core/createFormatter.js.map +1 -1
- package/dist/src/core/createIntl.d.ts +1 -1
- package/dist/src/react/useFormatter.d.ts +1 -1
- package/dist/src/react/useIntl.d.ts +1 -1
- package/dist/use-intl.cjs.development.js +56 -39
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/package.json +2 -2
- package/src/core/RelativeTimeFormatOptions.tsx +6 -0
- package/src/core/createFormatter.tsx +78 -45
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
Internationalization is an essential part of the user experience. use-intl gives you everything you need to get language subtleties right and has always got your back whenever you need to fine-tune a translation.
|
|
10
10
|
|
|
11
|
-
- 🌟 **ICU message syntax**: Localize your messages with interpolation,
|
|
11
|
+
- 🌟 **ICU message syntax**: Localize your messages with interpolation, cardinal & ordinal plurals, enum-based label selection and rich text.
|
|
12
12
|
- 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
|
|
13
13
|
- ✅ **Type-safe**: Speed up development with autocompletion for message keys and catch typos early with compile-time checks.
|
|
14
14
|
- 💡 **Hooks-only API**: Learn a single API that can be used across your code base to turn translations into plain strings or rich text.
|
|
@@ -19,36 +19,33 @@ Internationalization is an essential part of the user experience. use-intl gives
|
|
|
19
19
|
This library is based on the premise that messages can be grouped by namespaces (typically a component name).
|
|
20
20
|
|
|
21
21
|
```jsx
|
|
22
|
-
//
|
|
23
|
-
import {useTranslations
|
|
22
|
+
// UserProfile.tsx
|
|
23
|
+
import {useTranslations} from 'next-intl';
|
|
24
24
|
|
|
25
|
-
function
|
|
26
|
-
const t = useTranslations('
|
|
27
|
-
const format = useFormatter();
|
|
25
|
+
export default function UserProfile({user}) {
|
|
26
|
+
const t = useTranslations('UserProfile');
|
|
28
27
|
|
|
29
28
|
return (
|
|
30
29
|
<section>
|
|
31
|
-
<
|
|
32
|
-
<p>{t('
|
|
33
|
-
<p>{t('
|
|
34
|
-
<Image alt={t('portrait', {username: user.name})} src={user.portrait} />
|
|
30
|
+
<h1>{t('title', {firstName: user.firstName})}</h1>
|
|
31
|
+
<p>{t('membership', {memberSince: user.memberSince})}</p>
|
|
32
|
+
<p>{t('followers', {count: user.numFollowers})}</p>
|
|
35
33
|
</section>
|
|
36
34
|
);
|
|
37
35
|
}
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
```
|
|
38
|
+
```json
|
|
41
39
|
// en.json
|
|
42
40
|
{
|
|
43
|
-
"
|
|
44
|
-
"title": "
|
|
41
|
+
"UserProfile": {
|
|
42
|
+
"title": "{username}'s profile",
|
|
43
|
+
"membership": "Member since {memberSince, date, short}",
|
|
45
44
|
"followers": "{count, plural, ↵
|
|
46
45
|
=0 {No followers yet} ↵
|
|
47
46
|
=1 {One follower} ↵
|
|
48
47
|
other {# followers} ↵
|
|
49
|
-
}"
|
|
50
|
-
"lastSeen": "Last seen {time}",
|
|
51
|
-
"portrait": "Portrait of {username}"
|
|
48
|
+
}"
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
```
|
|
@@ -2,6 +2,7 @@ import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
|
2
2
|
import Formats from './Formats';
|
|
3
3
|
import IntlError from './IntlError';
|
|
4
4
|
import NumberFormatOptions from './NumberFormatOptions';
|
|
5
|
+
import RelativeTimeFormatOptions from './RelativeTimeFormatOptions';
|
|
5
6
|
import TimeZone from './TimeZone';
|
|
6
7
|
type Props = {
|
|
7
8
|
locale: string;
|
|
@@ -13,7 +14,7 @@ type Props = {
|
|
|
13
14
|
export default function createFormatter({ formats, locale, now: globalNow, onError, timeZone: globalTimeZone }: Props): {
|
|
14
15
|
dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
|
|
15
16
|
number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
|
|
16
|
-
relativeTime: (date: number | Date,
|
|
17
|
+
relativeTime: (date: number | Date, nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions) => string;
|
|
17
18
|
list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions) => string;
|
|
18
19
|
};
|
|
19
20
|
export {};
|
|
@@ -3,5 +3,5 @@ import createFormatter from './createFormatter';
|
|
|
3
3
|
export default function createIntl(...args: Parameters<typeof createFormatter>): {
|
|
4
4
|
formatDateTime: (value: number | Date, formatOrOptions?: string | import("./DateTimeFormatOptions").default | undefined) => string;
|
|
5
5
|
formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
6
|
-
formatRelativeTime: (date: number | Date,
|
|
6
|
+
formatRelativeTime: (date: number | Date, nowOrOptions?: number | Date | import("./RelativeTimeFormatOptions").default | undefined) => string;
|
|
7
7
|
};
|
|
@@ -2,43 +2,53 @@ import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
|
2
2
|
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
3
3
|
import { defaultOnError } from './use-intl.esm6.js';
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var SECOND = 1;
|
|
6
|
+
var MINUTE = SECOND * 60;
|
|
6
7
|
var HOUR = MINUTE * 60;
|
|
7
8
|
var DAY = HOUR * 24;
|
|
8
9
|
var WEEK = DAY * 7;
|
|
9
10
|
var MONTH = DAY * (365 / 12); // Approximation
|
|
11
|
+
var QUARTER = MONTH * 3;
|
|
10
12
|
var YEAR = DAY * 365;
|
|
11
|
-
|
|
13
|
+
var UNIT_SECONDS = {
|
|
14
|
+
second: SECOND,
|
|
15
|
+
seconds: SECOND,
|
|
16
|
+
minute: MINUTE,
|
|
17
|
+
minutes: MINUTE,
|
|
18
|
+
hour: HOUR,
|
|
19
|
+
hours: HOUR,
|
|
20
|
+
day: DAY,
|
|
21
|
+
days: DAY,
|
|
22
|
+
week: WEEK,
|
|
23
|
+
weeks: WEEK,
|
|
24
|
+
month: MONTH,
|
|
25
|
+
months: MONTH,
|
|
26
|
+
quarter: QUARTER,
|
|
27
|
+
quarters: QUARTER,
|
|
28
|
+
year: YEAR,
|
|
29
|
+
years: YEAR
|
|
30
|
+
};
|
|
31
|
+
function resolveRelativeTimeUnit(seconds) {
|
|
12
32
|
var absValue = Math.abs(seconds);
|
|
13
|
-
var value, unit;
|
|
14
|
-
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
15
|
-
// will include fractions like '2.1 hours ago'.
|
|
16
33
|
if (absValue < MINUTE) {
|
|
17
|
-
|
|
18
|
-
value = Math.round(seconds);
|
|
34
|
+
return 'second';
|
|
19
35
|
} else if (absValue < HOUR) {
|
|
20
|
-
|
|
21
|
-
value = Math.round(seconds / MINUTE);
|
|
36
|
+
return 'minute';
|
|
22
37
|
} else if (absValue < DAY) {
|
|
23
|
-
|
|
24
|
-
value = Math.round(seconds / HOUR);
|
|
38
|
+
return 'hour';
|
|
25
39
|
} else if (absValue < WEEK) {
|
|
26
|
-
|
|
27
|
-
value = Math.round(seconds / DAY);
|
|
40
|
+
return 'day';
|
|
28
41
|
} else if (absValue < MONTH) {
|
|
29
|
-
|
|
30
|
-
value = Math.round(seconds / WEEK);
|
|
42
|
+
return 'week';
|
|
31
43
|
} else if (absValue < YEAR) {
|
|
32
|
-
|
|
33
|
-
value = Math.round(seconds / MONTH);
|
|
34
|
-
} else {
|
|
35
|
-
unit = 'year';
|
|
36
|
-
value = Math.round(seconds / YEAR);
|
|
44
|
+
return 'month';
|
|
37
45
|
}
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
return 'year';
|
|
47
|
+
}
|
|
48
|
+
function calculateRelativeTimeValue(seconds, unit) {
|
|
49
|
+
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
50
|
+
// will include fractions like '2.1 hours ago'.
|
|
51
|
+
return Math.round(seconds / UNIT_SECONDS[unit]);
|
|
42
52
|
}
|
|
43
53
|
function createFormatter(_ref) {
|
|
44
54
|
var formats = _ref.formats,
|
|
@@ -100,25 +110,32 @@ function createFormatter(_ref) {
|
|
|
100
110
|
return new Intl.NumberFormat(locale, options).format(value);
|
|
101
111
|
});
|
|
102
112
|
}
|
|
113
|
+
function getGlobalNow() {
|
|
114
|
+
if (globalNow) {
|
|
115
|
+
return globalNow;
|
|
116
|
+
} else {
|
|
117
|
+
onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, process.env.NODE_ENV !== 'production' ? "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" : undefined));
|
|
118
|
+
return new Date();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function extractNowDate(nowOrOptions) {
|
|
122
|
+
if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {
|
|
123
|
+
return new Date(nowOrOptions);
|
|
124
|
+
}
|
|
125
|
+
if ((nowOrOptions == null ? void 0 : nowOrOptions.now) !== undefined) {
|
|
126
|
+
return new Date(nowOrOptions.now);
|
|
127
|
+
}
|
|
128
|
+
return getGlobalNow();
|
|
129
|
+
}
|
|
103
130
|
function relativeTime( /** The date time that needs to be formatted. */
|
|
104
131
|
date, /** The reference point in time to which `date` will be formatted in relation to. */
|
|
105
|
-
|
|
132
|
+
nowOrOptions) {
|
|
106
133
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
now = globalNow;
|
|
110
|
-
} else {
|
|
111
|
-
onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, process.env.NODE_ENV !== 'production' ? "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" : undefined));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
var dateDate = date instanceof Date ? date : new Date(date);
|
|
115
|
-
var nowDate = now instanceof Date ? now :
|
|
116
|
-
// @ts-expect-error -- `undefined` is fine for the `Date` constructor
|
|
117
|
-
new Date(now);
|
|
134
|
+
var dateDate = new Date(date);
|
|
135
|
+
var nowDate = extractNowDate(nowOrOptions);
|
|
118
136
|
var seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
value = _getRelativeTimeForma.value;
|
|
137
|
+
var unit = typeof nowOrOptions === 'number' || nowOrOptions instanceof Date || (nowOrOptions == null ? void 0 : nowOrOptions.unit) === undefined ? resolveRelativeTimeUnit(seconds) : nowOrOptions.unit;
|
|
138
|
+
var value = calculateRelativeTimeValue(seconds, unit);
|
|
122
139
|
return new Intl.RelativeTimeFormat(locale, {
|
|
123
140
|
numeric: 'auto'
|
|
124
141
|
}).format(value, unit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: TimeZone;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone: globalTimeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (!options?.timeZone) {\n if (globalTimeZone) {\n options = {...options, timeZone: globalTimeZone};\n } else {\n onError(\n new IntlError(\n IntlErrorCode.ENVIRONMENT_FALLBACK,\n process.env.NODE_ENV !== 'production'\n ? `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`\n : undefined\n )\n );\n }\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n onError(\n new IntlError(\n IntlErrorCode.ENVIRONMENT_FALLBACK,\n process.env.NODE_ENV !== 'production'\n ? `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`\n : undefined\n )\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate =\n now instanceof Date\n ? now\n : // @ts-expect-error -- `undefined` is fine for the `Date` constructor\n new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","globalTimeZone","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","ENVIRONMENT_FALLBACK","Intl","DateTimeFormat","format","number","NumberFormat","relativeTime","date","dateDate","Date","nowDate","getTime","_getRelativeTimeForma","RelativeTimeFormat","numeric","list","ListFormat"],"mappings":";;;;AAOA,IAAMA,MAAM,GAAG,EAAE,CAAA;AACjB,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAE,CAAA;AACxB,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAE,CAAA;AACrB,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAC,CAAA;AACpB,IAAME,KAAK,GAAGF,GAAG,IA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AAO,CAACC,OAAO,EAAE,IAAI,IAAI,CAAA;AAC/D,MAAA,IAAAC,qBAAA,GAAsBpD,2BAA2B,CAACC,OAAO,CAAC;QAAnDK,IAAI,GAAA8C,qBAAA,CAAJ9C,IAAI;QAAED,KAAK,GAAA+C,qBAAA,CAAL/C,KAAK,CAAA;AAElB,MAAA,OAAO,IAAIoC,IAAI,CAACY,kBAAkB,CAAC1C,MAAM,EAAE;AACzC2C,QAAAA,OAAO,EAAE,MAAA;AACV,OAAA,CAAC,CAACX,MAAM,CAACtC,KAAK,EAAEC,IAAI,CAAC,CAAA;KACvB,CAAC,OAAOkB,KAAK,EAAE;AACdT,MAAAA,OAAO,CACL,IAAIU,SAAS,CAACC,aAAa,CAACS,gBAAgB,EAAGX,KAAe,CAACY,OAAO,CAAC,CACxE,CAAA;MACD,OAAOF,MAAM,CAACa,IAAI,CAAC,CAAA;AACpB,KAAA;AACH,GAAA;AAEA,EAAA,SAASQ,IAAIA,CACXlD,KAAuB,EACvBgB,eAAiD,EAAA;AAEjD,IAAA,OAAOW,iBAAiB,CAAC3B,KAAK,EAAEgB,eAAe,EAAEX,OAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAE6C,IAAI,EAAE,UAACjC,OAAO,EAAA;AAAA,MAAA,OACtE,IAAImB,IAAI,CAACe,UAAU,CAAC7C,MAAM,EAAEW,OAAO,CAAC,CAACqB,MAAM,CAACtC,KAAK,CAAC,CAAA;KACnD,CAAA,CAAA;AACH,GAAA;EAEA,OAAO;AAACgC,IAAAA,QAAQ,EAARA,QAAQ;AAAEO,IAAAA,MAAM,EAANA,MAAM;AAAEE,IAAAA,YAAY,EAAZA,YAAY;AAAES,IAAAA,IAAI,EAAJA,IAAAA;GAAK,CAAA;AAC/C;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport RelativeTimeFormatOptions from './RelativeTimeFormatOptions';\nimport TimeZone from './TimeZone';\nimport {defaultOnError} from './defaults';\n\nconst SECOND = 1;\nconst MINUTE = SECOND * 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst QUARTER = MONTH * 3;\nconst YEAR = DAY * 365;\n\nconst UNIT_SECONDS: Record<Intl.RelativeTimeFormatUnit, number> = {\n second: SECOND,\n seconds: SECOND,\n minute: MINUTE,\n minutes: MINUTE,\n hour: HOUR,\n hours: HOUR,\n day: DAY,\n days: DAY,\n week: WEEK,\n weeks: WEEK,\n month: MONTH,\n months: MONTH,\n quarter: QUARTER,\n quarters: QUARTER,\n year: YEAR,\n years: YEAR\n} as const;\n\nfunction resolveRelativeTimeUnit(seconds: number) {\n const absValue = Math.abs(seconds);\n\n if (absValue < MINUTE) {\n return 'second';\n } else if (absValue < HOUR) {\n return 'minute';\n } else if (absValue < DAY) {\n return 'hour';\n } else if (absValue < WEEK) {\n return 'day';\n } else if (absValue < MONTH) {\n return 'week';\n } else if (absValue < YEAR) {\n return 'month';\n }\n return 'year';\n}\n\nfunction calculateRelativeTimeValue(\n seconds: number,\n unit: Intl.RelativeTimeFormatUnit\n) {\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n return Math.round(seconds / UNIT_SECONDS[unit]);\n}\n\ntype Props = {\n locale: string;\n timeZone?: TimeZone;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone: globalTimeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (!options?.timeZone) {\n if (globalTimeZone) {\n options = {...options, timeZone: globalTimeZone};\n } else {\n onError(\n new IntlError(\n IntlErrorCode.ENVIRONMENT_FALLBACK,\n process.env.NODE_ENV !== 'production'\n ? `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`\n : undefined\n )\n );\n }\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function getGlobalNow() {\n if (globalNow) {\n return globalNow;\n } else {\n onError(\n new IntlError(\n IntlErrorCode.ENVIRONMENT_FALLBACK,\n process.env.NODE_ENV !== 'production'\n ? `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`\n : undefined\n )\n );\n return new Date();\n }\n }\n\n function extractNowDate(\n nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions\n ) {\n if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {\n return new Date(nowOrOptions);\n }\n if (nowOrOptions?.now !== undefined) {\n return new Date(nowOrOptions.now);\n }\n return getGlobalNow();\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions\n ) {\n try {\n const dateDate = new Date(date);\n const nowDate = extractNowDate(nowOrOptions);\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n\n const unit =\n typeof nowOrOptions === 'number' ||\n nowOrOptions instanceof Date ||\n nowOrOptions?.unit === undefined\n ? resolveRelativeTimeUnit(seconds)\n : nowOrOptions.unit;\n\n const value = calculateRelativeTimeValue(seconds, unit);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"names":["SECOND","MINUTE","HOUR","DAY","WEEK","MONTH","QUARTER","YEAR","UNIT_SECONDS","second","seconds","minute","minutes","hour","hours","day","days","week","weeks","month","months","quarter","quarters","year","years","resolveRelativeTimeUnit","absValue","Math","abs","calculateRelativeTimeValue","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","globalTimeZone","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","value","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","ENVIRONMENT_FALLBACK","Intl","DateTimeFormat","format","number","NumberFormat","getGlobalNow","Date","extractNowDate","nowOrOptions","relativeTime","date","dateDate","nowDate","getTime","RelativeTimeFormat","numeric","list","ListFormat"],"mappings":";;;;AAQA,IAAMA,MAAM,GAAG,CAAC,CAAA;AAChB,IAAMC,MAAM,GAAGD,MAAM,GAAG,EAAE,CAAA;AAC1B,IAAME,IAAI,GAAGD,MAAM,GAAG,EAAE,CAAA;AACxB,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAE,CAAA;AACrB,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAC,CAAA;AACpB,IAAME,KAAK,GAAGF,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;AAC/B,IAAMG,OAAO,GAAGD,KAAK,GAAG,CAAC,CAAA;AACzB,IAAME,IAAI,GAAGJ,GAAG,GAAG,GAAG,CAAA;AAEtB,IAAMK,YAAY,GAAgD;AAChEC,EAAAA,MAAM,EAAET,MAAM;AACdU,EAAAA,OAAO,EAAEV,MAAM;AACfW,EAAAA,MAAM,EAAEV,MAAM;AACdW,EAAAA,OAAO,EAAEX,MAAM;AACfY,EAAAA,IAAI,EAAEX,IAAI;AACVY,EAAAA,KAAK,EAAEZ,IAAI;AACXa,EAAAA,GAAG,EAAEZ,GAAG;AACRa,EAAAA,IAAI,EAAEb,GAAG;AACTc,EAAAA,IAAI,EAAEb,IAAI;AACVc,EAAAA,KAAK,EAAEd,IAAI;AACXe,EAAAA,KAAK,EAAEd,KAAK;AACZe,EAAAA,MAAM,EAAEf,KAAK;AACbgB,EAAAA,OAAO,EAAEf,OAAO;AAChBgB,EAAAA,QAAQ,EAAEhB,OAAO;AACjBiB,EAAAA,I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CAAC,GAChCgE,YAAY,CAAC5C,IAAI,CAAA;AAEvB,MAAA,IAAM2B,KAAK,GAAG5B,0BAA0B,CAACnB,OAAO,EAAEoB,IAAI,CAAC,CAAA;AAEvD,MAAA,OAAO,IAAIoC,IAAI,CAACc,kBAAkB,CAAC7C,MAAM,EAAE;AACzC8C,QAAAA,OAAO,EAAE,MAAA;AACV,OAAA,CAAC,CAACb,MAAM,CAACX,KAAK,EAAE3B,IAAI,CAAC,CAAA;KACvB,CAAC,OAAOkB,KAAK,EAAE;AACdT,MAAAA,OAAO,CACL,IAAIU,SAAS,CAACC,aAAa,CAACU,gBAAgB,EAAGZ,KAAe,CAACa,OAAO,CAAC,CACxE,CAAA;MACD,OAAOF,MAAM,CAACiB,IAAI,CAAC,CAAA;AACpB,KAAA;AACH,GAAA;AAEA,EAAA,SAASM,IAAIA,CACXzB,KAAuB,EACvBZ,eAAiD,EAAA;AAEjD,IAAA,OAAOW,iBAAiB,CAACC,KAAK,EAAEZ,eAAe,EAAEX,OAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAEgD,IAAI,EAAE,UAACpC,OAAO,EAAA;AAAA,MAAA,OACtE,IAAIoB,IAAI,CAACiB,UAAU,CAAChD,MAAM,EAAEW,OAAO,CAAC,CAACsB,MAAM,CAACX,KAAK,CAAC,CAAA;KACnD,CAAA,CAAA;AACH,GAAA;EAEA,OAAO;AAACK,IAAAA,QAAQ,EAARA,QAAQ;AAAEO,IAAAA,MAAM,EAANA,MAAM;AAAEM,IAAAA,YAAY,EAAZA,YAAY;AAAEO,IAAAA,IAAI,EAAJA,IAAAA;GAAK,CAAA;AAC/C;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
2
|
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
3
|
-
import createBaseTranslator, { getMessagesOrError } from './use-intl.
|
|
4
|
-
import resolveNamespace from './use-intl.
|
|
3
|
+
import createBaseTranslator, { getMessagesOrError } from './use-intl.esm8.js';
|
|
4
|
+
import resolveNamespace from './use-intl.esm7.js';
|
|
5
5
|
|
|
6
6
|
var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
|
|
7
7
|
function createTranslatorImpl(_ref, namespacePrefix) {
|
|
@@ -1,200 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function resolvePath(messages, key, namespace) {
|
|
9
|
-
if (!messages) {
|
|
10
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages available at `" + namespace + "`." : undefined);
|
|
11
|
-
}
|
|
12
|
-
var message = messages;
|
|
13
|
-
key.split('.').forEach(function (part) {
|
|
14
|
-
var next = message[part];
|
|
15
|
-
if (part == null || next == null) {
|
|
16
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "Could not resolve `" + key + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
|
|
17
|
-
}
|
|
18
|
-
message = next;
|
|
19
|
-
});
|
|
20
|
-
return message;
|
|
21
|
-
}
|
|
22
|
-
function prepareTranslationValues(values) {
|
|
23
|
-
if (Object.keys(values).length === 0) return undefined;
|
|
24
|
-
// Workaround for https://github.com/formatjs/formatjs/issues/1467
|
|
25
|
-
var transformedValues = {};
|
|
26
|
-
Object.keys(values).forEach(function (key) {
|
|
27
|
-
var index = 0;
|
|
28
|
-
var value = values[key];
|
|
29
|
-
var transformed;
|
|
30
|
-
if (typeof value === 'function') {
|
|
31
|
-
transformed = function transformed(chunks) {
|
|
32
|
-
var result = value(chunks);
|
|
33
|
-
return isValidElement(result) ? cloneElement(result, {
|
|
34
|
-
key: key + index++
|
|
35
|
-
}) : result;
|
|
36
|
-
};
|
|
37
|
-
} else {
|
|
38
|
-
transformed = value;
|
|
39
|
-
}
|
|
40
|
-
transformedValues[key] = transformed;
|
|
41
|
-
});
|
|
42
|
-
return transformedValues;
|
|
43
|
-
}
|
|
44
|
-
function getMessagesOrError(_ref) {
|
|
45
|
-
var messages = _ref.messages,
|
|
46
|
-
namespace = _ref.namespace,
|
|
47
|
-
_ref$onError = _ref.onError,
|
|
48
|
-
onError = _ref$onError === void 0 ? defaultOnError : _ref$onError;
|
|
49
|
-
try {
|
|
50
|
-
if (!messages) {
|
|
51
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages were configured on the provider." : undefined);
|
|
52
|
-
}
|
|
53
|
-
var retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
|
|
54
|
-
if (!retrievedMessages) {
|
|
55
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages for namespace `" + namespace + "` found." : undefined);
|
|
56
|
-
}
|
|
57
|
-
return retrievedMessages;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
60
|
-
onError(intlError);
|
|
61
|
-
return intlError;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function getPlainMessage(candidate, values) {
|
|
65
|
-
if (values) return undefined;
|
|
66
|
-
var unescapedMessage = candidate.replace(/'([{}])/gi, '$1');
|
|
67
|
-
// Placeholders can be in the message if there are default values,
|
|
68
|
-
// or if the user has forgotten to provide values. In the latter
|
|
69
|
-
// case we need to compile the message to receive an error.
|
|
70
|
-
var hasPlaceholders = /<|{/.test(unescapedMessage);
|
|
71
|
-
if (!hasPlaceholders) {
|
|
72
|
-
return unescapedMessage;
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
function createBaseTranslator(_ref2) {
|
|
77
|
-
var defaultTranslationValues = _ref2.defaultTranslationValues,
|
|
78
|
-
globalFormats = _ref2.formats,
|
|
79
|
-
_ref2$getMessageFallb = _ref2.getMessageFallback,
|
|
80
|
-
getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
|
|
81
|
-
locale = _ref2.locale,
|
|
82
|
-
messageFormatCache = _ref2.messageFormatCache,
|
|
83
|
-
messagesOrError = _ref2.messagesOrError,
|
|
84
|
-
namespace = _ref2.namespace,
|
|
85
|
-
onError = _ref2.onError,
|
|
86
|
-
timeZone = _ref2.timeZone;
|
|
87
|
-
function getFallbackFromErrorAndNotify(key, code, message) {
|
|
88
|
-
var error = new IntlError(code, message);
|
|
89
|
-
onError(error);
|
|
90
|
-
return getMessageFallback({
|
|
91
|
-
error: error,
|
|
92
|
-
key: key,
|
|
93
|
-
namespace: namespace
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function translateBaseFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
97
|
-
key, /** Key value pairs for values to interpolate into the message. */
|
|
98
|
-
values, /** Provide custom formats for numbers, dates and times. */
|
|
99
|
-
formats) {
|
|
100
|
-
if (messagesOrError instanceof IntlError) {
|
|
101
|
-
// We have already warned about this during render
|
|
102
|
-
return getMessageFallback({
|
|
103
|
-
error: messagesOrError,
|
|
104
|
-
key: key,
|
|
105
|
-
namespace: namespace
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
var messages = messagesOrError;
|
|
109
|
-
var message;
|
|
110
|
-
try {
|
|
111
|
-
message = resolvePath(messages, key, namespace);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
114
|
-
}
|
|
115
|
-
function joinPath(parts) {
|
|
116
|
-
return parts.filter(function (part) {
|
|
117
|
-
return part != null;
|
|
118
|
-
}).join('.');
|
|
119
|
-
}
|
|
120
|
-
var cacheKey = joinPath([locale, namespace, key, String(message)]);
|
|
121
|
-
var messageFormat;
|
|
122
|
-
if (messageFormatCache != null && messageFormatCache.has(cacheKey)) {
|
|
123
|
-
messageFormat = messageFormatCache.get(cacheKey);
|
|
124
|
-
} else {
|
|
125
|
-
if (typeof message === 'object') {
|
|
126
|
-
var code, errorMessage;
|
|
127
|
-
if (Array.isArray(message)) {
|
|
128
|
-
code = IntlErrorCode.INVALID_MESSAGE;
|
|
129
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
130
|
-
errorMessage = "Message at `" + joinPath([namespace, key]) + "` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages";
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
code = IntlErrorCode.INSUFFICIENT_PATH;
|
|
134
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
135
|
-
errorMessage = "Message at `" + joinPath([namespace, key]) + "` 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";
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return getFallbackFromErrorAndNotify(key, code, errorMessage);
|
|
139
|
-
}
|
|
140
|
-
// Hot path that avoids creating an `IntlMessageFormat` instance
|
|
141
|
-
var plainMessage = getPlainMessage(message, values);
|
|
142
|
-
if (plainMessage) return plainMessage;
|
|
143
|
-
try {
|
|
144
|
-
messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
|
|
145
|
-
} catch (error) {
|
|
146
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
|
|
147
|
-
}
|
|
148
|
-
messageFormatCache == null || messageFormatCache.set(cacheKey, messageFormat);
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
var formattedMessage = messageFormat.format(
|
|
152
|
-
// @ts-ignore `intl-messageformat` expects a different format
|
|
153
|
-
// for rich text elements since a recent minor update. This
|
|
154
|
-
// needs to be evaluated in detail, possibly also in regards
|
|
155
|
-
// to be able to format to parts.
|
|
156
|
-
prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
|
|
157
|
-
if (formattedMessage == null) {
|
|
158
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
|
|
159
|
-
}
|
|
160
|
-
// Limit the function signature to return strings or React elements
|
|
161
|
-
return isValidElement(formattedMessage) ||
|
|
162
|
-
// Arrays of React elements
|
|
163
|
-
Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function translateFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
169
|
-
key, /** Key value pairs for values to interpolate into the message. */
|
|
170
|
-
values, /** Provide custom formats for numbers, dates and times. */
|
|
171
|
-
formats) {
|
|
172
|
-
var result = translateBaseFn(key, values, formats);
|
|
173
|
-
if (typeof result !== 'string') {
|
|
174
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== 'production' ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
177
|
-
}
|
|
178
|
-
translateFn.rich = translateBaseFn;
|
|
179
|
-
translateFn.raw = function ( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
180
|
-
key) {
|
|
181
|
-
if (messagesOrError instanceof IntlError) {
|
|
182
|
-
// We have already warned about this during render
|
|
183
|
-
return getMessageFallback({
|
|
184
|
-
error: messagesOrError,
|
|
185
|
-
key: key,
|
|
186
|
-
namespace: namespace
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
var messages = messagesOrError;
|
|
190
|
-
try {
|
|
191
|
-
return resolvePath(messages, key, namespace);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
return translateFn;
|
|
1
|
+
/**
|
|
2
|
+
* For the strictly typed messages to work we have to wrap the namespace into
|
|
3
|
+
* a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
|
|
4
|
+
*/
|
|
5
|
+
function resolveNamespace(namespace, namespacePrefix) {
|
|
6
|
+
return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
|
|
197
7
|
}
|
|
198
8
|
|
|
199
|
-
export {
|
|
9
|
+
export { resolveNamespace as default };
|
|
200
10
|
//# sourceMappingURL=use-intl.esm7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport MessageFormatCache from './MessageFormatCache';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nexport function getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nfunction getPlainMessage(candidate: string, values?: unknown) {\n if (values) return undefined;\n\n const unescapedMessage = candidate.replace(/'([{}])/gi, '$1');\n\n // Placeholders can be in the message if there are default values,\n // or if the user has forgotten to provide values. In the latter\n // case we need to compile the message to receive an error.\n const hasPlaceholders = /<|{/.test(unescapedMessage);\n\n if (!hasPlaceholders) {\n return unescapedMessage;\n }\n\n return undefined;\n}\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messageFormatCache,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([locale, namespace, key, String(message)]);\n\n let messageFormat: IntlMessageFormat;\n if (messageFormatCache?.has(cacheKey)) {\n messageFormat = messageFormatCache.get(cacheKey)!;\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` 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`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n // Hot path that avoids creating an `IntlMessageFormat` instance\n const plainMessage = getPlainMessage(message as string, values);\n if (plainMessage) return plainMessage;\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n messageFormatCache?.set(cacheKey, messageFormat);\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","_ref","_ref$onError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","getPlainMessage","candidate","unescapedMessage","replace","hasPlaceholders","test","createBaseTranslator","_ref2","defaultTranslationValues","globalFormats","formats","_ref2$getMessageFallb","getMessageFallback","defaultGetMessageFallback","locale","messageFormatCache","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","joinPath","parts","filter","join","cacheKey","String","messageFormat","has","get","errorMessage","Array","isArray","INVALID_MESSAGE","INSUFFICIENT_PATH","plainMessage","IntlMessageFormat","convertFormatsToIntlMessageFormat","_extends","set","formattedMessage","format","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAqBA,SAASA,WAAWA,CAClBC,QAA0C,EAC1CC,GAAW,EACXC,SAAkB,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,CAACxD,GAAG,EAAEa,MAAM,EAAEiC,OAAO,CAAC,CAAA;AAEpD,IAAA,IAAI,OAAOxB,MAAM,KAAK,QAAQ,EAAE;MAC9B,OAAOgC,6BAA6B,CAClCtD,GAAG,EACHkC,aAAa,CAACmC,eAAe,EAC7BlE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAChBL,eAAAA,GAAAA,GAAG,GAClBC,OAAAA,IAAAA,SAAS,GAAkBA,aAAAA,GAAAA,SAAS,GAAO,GAAA,GAAA,UAC7C,CACAK,GAAAA,qFAAAA,GAAAA,SAAS,CACd,CAAA;AACF,KAAA;AAED,IAAA,OAAOgB,MAAM,CAAA;AACf,GAAA;EAEAyD,WAAW,CAACC,IAAI,GAAGxB,eAAe,CAAA;EAElCuB,WAAW,CAACE,GAAG,GAAG;AAEhBjF,EAAAA,GAAW,EACJ;IACP,IAAIoD,eAAe,YAAYnB,SAAS,EAAE;AACxC;AACA,MAAA,OAAOe,kBAAkB,CAAC;AACxBjB,QAAAA,KAAK,EAAEqB,eAAe;AACtBpD,QAAAA,GAAG,EAAHA,GAAG;AACHC,QAAAA,SAAS,EAATA,SAAAA;AACD,OAAA,CAAC,CAAA;AACH,KAAA;IACD,IAAMF,QAAQ,GAAGqD,eAAe,CAAA;IAEhC,IAAI;AACF,MAAA,OAAOtD,WAAW,CAACC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,CAAC,CAAA;KAC7C,CAAC,OAAO8B,KAAK,EAAE;MACd,OAAOuB,6BAA6B,CAClCtD,GAAG,EACHkC,aAAa,CAACC,eAAe,EAC5BJ,KAAe,CAACxB,OAAO,CACzB,CAAA;AACF,KAAA;GACF,CAAA;AAED,EAAA,OAAOwE,WAAW,CAAA;AACpB;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}
|