use-intl 0.0.0-canary-5bbd7ad56b530e283b07cff950de61d6af81f00c

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -0
  3. package/_IntlProvider.d.ts +1 -0
  4. package/_useLocale.d.ts +1 -0
  5. package/core.d.ts +1 -0
  6. package/dist/_IntlProvider.js +7 -0
  7. package/dist/_useLocale.js +7 -0
  8. package/dist/core.js +7 -0
  9. package/dist/development/IntlContext-BKfsnzBx.js +7 -0
  10. package/dist/development/_IntlProvider.js +61 -0
  11. package/dist/development/_useLocale-0Rl9uR82.js +19 -0
  12. package/dist/development/_useLocale.js +11 -0
  13. package/dist/development/core.js +69 -0
  14. package/dist/development/createFormatter-TZTkYRKI.js +542 -0
  15. package/dist/development/index.js +31 -0
  16. package/dist/development/initializeConfig-o7L_y07P.js +185 -0
  17. package/dist/development/react.js +151 -0
  18. package/dist/esm/IntlContext-DoS4CDM3.js +1 -0
  19. package/dist/esm/_IntlProvider.js +1 -0
  20. package/dist/esm/_useLocale-v-ZT5JoE.js +1 -0
  21. package/dist/esm/_useLocale.js +1 -0
  22. package/dist/esm/core.js +1 -0
  23. package/dist/esm/createFormatter-D1WNHqdE.js +1 -0
  24. package/dist/esm/index.js +1 -0
  25. package/dist/esm/initializeConfig-D2A8plWf.js +1 -0
  26. package/dist/esm/react.js +1 -0
  27. package/dist/index.js +7 -0
  28. package/dist/production/IntlContext-DcFt0tgW.js +1 -0
  29. package/dist/production/_IntlProvider.js +1 -0
  30. package/dist/production/_useLocale-CpTrqBDt.js +1 -0
  31. package/dist/production/_useLocale.js +1 -0
  32. package/dist/production/core.js +1 -0
  33. package/dist/production/createFormatter-CTr0qKAI.js +1 -0
  34. package/dist/production/index.js +1 -0
  35. package/dist/production/initializeConfig-AbYTngyP.js +1 -0
  36. package/dist/production/react.js +1 -0
  37. package/dist/react.js +7 -0
  38. package/dist/types/src/_IntlProvider.d.ts +1 -0
  39. package/dist/types/src/_useLocale.d.ts +1 -0
  40. package/dist/types/src/core/AbstractIntlMessages.d.ts +9 -0
  41. package/dist/types/src/core/DateTimeFormatOptions.d.ts +73 -0
  42. package/dist/types/src/core/Formats.d.ts +8 -0
  43. package/dist/types/src/core/IntlConfig.d.ts +58 -0
  44. package/dist/types/src/core/IntlError.d.ts +14 -0
  45. package/dist/types/src/core/NumberFormatOptions.d.ts +3 -0
  46. package/dist/types/src/core/RelativeTimeFormatOptions.d.ts +7 -0
  47. package/dist/types/src/core/TimeZone.d.ts +2 -0
  48. package/dist/types/src/core/TranslationValues.d.ts +6 -0
  49. package/dist/types/src/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
  50. package/dist/types/src/core/createBaseTranslator.d.ts +24 -0
  51. package/dist/types/src/core/createFormatter.d.ts +27 -0
  52. package/dist/types/src/core/createFormatter.test.d.ts +1 -0
  53. package/dist/types/src/core/createTranslator.d.ts +71 -0
  54. package/dist/types/src/core/createTranslator.test.d.ts +1 -0
  55. package/dist/types/src/core/createTranslatorImpl.d.ts +17 -0
  56. package/dist/types/src/core/defaults.d.ts +11 -0
  57. package/dist/types/src/core/formatters.d.ts +25 -0
  58. package/dist/types/src/core/index.d.ts +16 -0
  59. package/dist/types/src/core/initializeConfig.d.ts +13 -0
  60. package/dist/types/src/core/joinPath.d.ts +1 -0
  61. package/dist/types/src/core/resolveNamespace.d.ts +5 -0
  62. package/dist/types/src/core/utils/MessageKeys.d.ts +5 -0
  63. package/dist/types/src/core/utils/NamespaceKeys.d.ts +5 -0
  64. package/dist/types/src/core/utils/NestedKeyOf.d.ts +4 -0
  65. package/dist/types/src/core/utils/NestedValueOf.d.ts +2 -0
  66. package/dist/types/src/core/validateMessages.d.ts +3 -0
  67. package/dist/types/src/core.d.ts +1 -0
  68. package/dist/types/src/index.d.ts +2 -0
  69. package/dist/types/src/react/IntlContext.d.ts +8 -0
  70. package/dist/types/src/react/IntlProvider.d.ts +7 -0
  71. package/dist/types/src/react/IntlProvider.test.d.ts +1 -0
  72. package/dist/types/src/react/index.d.ts +7 -0
  73. package/dist/types/src/react/index.test.d.ts +1 -0
  74. package/dist/types/src/react/useFormatter.d.ts +2 -0
  75. package/dist/types/src/react/useFormatter.test.d.ts +1 -0
  76. package/dist/types/src/react/useIntlContext.d.ts +2 -0
  77. package/dist/types/src/react/useLocale.d.ts +1 -0
  78. package/dist/types/src/react/useLocale.test.d.ts +1 -0
  79. package/dist/types/src/react/useMessages.d.ts +2 -0
  80. package/dist/types/src/react/useMessages.test.d.ts +1 -0
  81. package/dist/types/src/react/useNow.d.ts +23 -0
  82. package/dist/types/src/react/useNow.test.d.ts +1 -0
  83. package/dist/types/src/react/useTimeZone.d.ts +1 -0
  84. package/dist/types/src/react/useTimeZone.test.d.ts +1 -0
  85. package/dist/types/src/react/useTranslations.d.ts +62 -0
  86. package/dist/types/src/react/useTranslations.test.d.ts +1 -0
  87. package/dist/types/src/react/useTranslationsImpl.d.ts +9 -0
  88. package/dist/types/src/react.d.ts +1 -0
  89. package/dist/types/test/setup.d.ts +1 -0
  90. package/package.json +73 -0
  91. package/react.d.ts +1 -0
@@ -0,0 +1,7 @@
1
+ type RelativeTimeFormatOptions = {
2
+ now?: number | Date;
3
+ unit?: Intl.RelativeTimeFormatUnit;
4
+ numberingSystem?: string;
5
+ style?: Intl.RelativeTimeFormatStyle;
6
+ };
7
+ export default RelativeTimeFormatOptions;
@@ -0,0 +1,2 @@
1
+ type TimeZone = 'Africa/Abidjan' | 'Africa/Accra' | 'Africa/Addis_Ababa' | 'Africa/Algiers' | 'Africa/Asmara' | 'Africa/Bamako' | 'Africa/Bangui' | 'Africa/Banjul' | 'Africa/Bissau' | 'Africa/Blantyre' | 'Africa/Brazzaville' | 'Africa/Bujumbura' | 'Africa/Cairo' | 'Africa/Casablanca' | 'Africa/Ceuta' | 'Africa/Conakry' | 'Africa/Dakar' | 'Africa/Dar_es_Salaam' | 'Africa/Djibouti' | 'Africa/Douala' | 'Africa/El_Aaiun' | 'Africa/Freetown' | 'Africa/Gaborone' | 'Africa/Harare' | 'Africa/Johannesburg' | 'Africa/Juba' | 'Africa/Kampala' | 'Africa/Khartoum' | 'Africa/Kigali' | 'Africa/Kinshasa' | 'Africa/Lagos' | 'Africa/Libreville' | 'Africa/Lome' | 'Africa/Luanda' | 'Africa/Lubumbashi' | 'Africa/Lusaka' | 'Africa/Malabo' | 'Africa/Maputo' | 'Africa/Maseru' | 'Africa/Mbabane' | 'Africa/Mogadishu' | 'Africa/Monrovia' | 'Africa/Nairobi' | 'Africa/Ndjamena' | 'Africa/Niamey' | 'Africa/Nouakchott' | 'Africa/Ouagadougou' | 'Africa/Porto-Novo' | 'Africa/Sao_Tome' | 'Africa/Tripoli' | 'Africa/Tunis' | 'Africa/Windhoek' | 'America/Adak' | 'America/Anchorage' | 'America/Anguilla' | 'America/Antigua' | 'America/Araguaina' | 'America/Argentina/Buenos_Aires' | 'America/Argentina/Catamarca' | 'America/Argentina/Cordoba' | 'America/Argentina/Jujuy' | 'America/Argentina/La_Rioja' | 'America/Argentina/Mendoza' | 'America/Argentina/Rio_Gallegos' | 'America/Argentina/Salta' | 'America/Argentina/San_Juan' | 'America/Argentina/San_Luis' | 'America/Argentina/Tucuman' | 'America/Argentina/Ushuaia' | 'America/Aruba' | 'America/Asuncion' | 'America/Atikokan' | 'America/Bahia' | 'America/Bahia_Banderas' | 'America/Barbados' | 'America/Belem' | 'America/Belize' | 'America/Blanc-Sablon' | 'America/Boa_Vista' | 'America/Bogota' | 'America/Boise' | 'America/Cambridge_Bay' | 'America/Campo_Grande' | 'America/Cancun' | 'America/Caracas' | 'America/Cayenne' | 'America/Cayman' | 'America/Chicago' | 'America/Chihuahua' | 'America/Costa_Rica' | 'America/Creston' | 'America/Cuiaba' | 'America/Curacao' | 'America/Danmarkshavn' | 'America/Dawson' | 'America/Dawson_Creek' | 'America/Denver' | 'America/Detroit' | 'America/Dominica' | 'America/Edmonton' | 'America/Eirunepe' | 'America/El_Salvador' | 'America/Fort_Nelson' | 'America/Fortaleza' | 'America/Glace_Bay' | 'America/Godthab' | 'America/Goose_Bay' | 'America/Grand_Turk' | 'America/Grenada' | 'America/Guadeloupe' | 'America/Guatemala' | 'America/Guayaquil' | 'America/Guyana' | 'America/Halifax' | 'America/Havana' | 'America/Hermosillo' | 'America/Indiana/Indianapolis' | 'America/Indiana/Knox' | 'America/Indiana/Marengo' | 'America/Indiana/Petersburg' | 'America/Indiana/Tell_City' | 'America/Indiana/Vevay' | 'America/Indiana/Vincennes' | 'America/Indiana/Winamac' | 'America/Inuvik' | 'America/Iqaluit' | 'America/Jamaica' | 'America/Juneau' | 'America/Kentucky/Louisville' | 'America/Kentucky/Monticello' | 'America/Kralendijk' | 'America/La_Paz' | 'America/Lima' | 'America/Los_Angeles' | 'America/Lower_Princes' | 'America/Maceio' | 'America/Managua' | 'America/Manaus' | 'America/Marigot' | 'America/Martinique' | 'America/Matamoros' | 'America/Mazatlan' | 'America/Menominee' | 'America/Merida' | 'America/Metlakatla' | 'America/Mexico_City' | 'America/Miquelon' | 'America/Moncton' | 'America/Monterrey' | 'America/Montevideo' | 'America/Montserrat' | 'America/Nassau' | 'America/New_York' | 'America/Nipigon' | 'America/Nome' | 'America/Noronha' | 'America/North_Dakota/Beulah' | 'America/North_Dakota/Center' | 'America/North_Dakota/New_Salem' | 'America/Ojinaga' | 'America/Panama' | 'America/Pangnirtung' | 'America/Paramaribo' | 'America/Phoenix' | 'America/Port-au-Prince' | 'America/Port_of_Spain' | 'America/Porto_Velho' | 'America/Puerto_Rico' | 'America/Punta_Arenas' | 'America/Rainy_River' | 'America/Rankin_Inlet' | 'America/Recife' | 'America/Regina' | 'America/Resolute' | 'America/Rio_Branco' | 'America/Santarem' | 'America/Santiago' | 'America/Santo_Domingo' | 'America/Sao_Paulo' | 'America/Scoresbysund' | 'America/Sitka' | 'America/St_Barthelemy' | 'America/St_Johns' | 'America/St_Kitts' | 'America/St_Lucia' | 'America/St_Thomas' | 'America/St_Vincent' | 'America/Swift_Current' | 'America/Tegucigalpa' | 'America/Thule' | 'America/Thunder_Bay' | 'America/Tijuana' | 'America/Toronto' | 'America/Tortola' | 'America/Vancouver' | 'America/Whitehorse' | 'America/Winnipeg' | 'America/Yakutat' | 'America/Yellowknife' | 'Antarctica/Casey' | 'Antarctica/Davis' | 'Antarctica/DumontDUrville' | 'Antarctica/Macquarie' | 'Antarctica/Mawson' | 'Antarctica/Palmer' | 'Antarctica/Rothera' | 'Antarctica/Syowa' | 'Antarctica/Troll' | 'Antarctica/Vostok' | 'Arctic/Longyearbyen' | 'Asia/Almaty' | 'Asia/Amman' | 'Asia/Anadyr' | 'Asia/Aqtau' | 'Asia/Aqtobe' | 'Asia/Ashgabat' | 'Asia/Atyrau' | 'Asia/Baghdad' | 'Asia/Baku' | 'Asia/Bangkok' | 'Asia/Barnaul' | 'Asia/Beirut' | 'Asia/Bishkek' | 'Asia/Brunei' | 'Asia/Chita' | 'Asia/Choibalsan' | 'Asia/Colombo' | 'Asia/Damascus' | 'Asia/Dhaka' | 'Asia/Dili' | 'Asia/Dubai' | 'Asia/Dushanbe' | 'Asia/Famagusta' | 'Asia/Gaza' | 'Asia/Hebron' | 'Asia/Ho_Chi_Minh' | 'Asia/Hong_Kong' | 'Asia/Hovd' | 'Asia/Irkutsk' | 'Asia/Jakarta' | 'Asia/Jayapura' | 'Asia/Jerusalem' | 'Asia/Kabul' | 'Asia/Kamchatka' | 'Asia/Karachi' | 'Asia/Kathmandu' | 'Asia/Khandyga' | 'Asia/Kolkata' | 'Asia/Krasnoyarsk' | 'Asia/Kuala_Lumpur' | 'Asia/Kuching' | 'Asia/Macau' | 'Asia/Magadan' | 'Asia/Makassar' | 'Asia/Manila' | 'Asia/Nicosia' | 'Asia/Novokuznetsk' | 'Asia/Novosibirsk' | 'Asia/Omsk' | 'Asia/Oral' | 'Asia/Phnom_Penh' | 'Asia/Pontianak' | 'Asia/Pyongyang' | 'Asia/Qatar' | 'Asia/Qostanay' | 'Asia/Qyzylorda' | 'Asia/Riyadh' | 'Asia/Sakhalin' | 'Asia/Samarkand' | 'Asia/Seoul' | 'Asia/Shanghai' | 'Asia/Singapore' | 'Asia/Srednekolymsk' | 'Asia/Taipei' | 'Asia/Tashkent' | 'Asia/Tbilisi' | 'Asia/Tehran' | 'Asia/Thimphu' | 'Asia/Tokyo' | 'Asia/Tomsk' | 'Asia/Ulaanbaatar' | 'Asia/Urumqi' | 'Asia/Ust-Nera' | 'Asia/Vladivostok' | 'Asia/Yakutsk' | 'Asia/Yangon' | 'Asia/Yekaterinburg' | 'Asia/Yerevan' | 'Atlantic/Azores' | 'Atlantic/Bermuda' | 'Atlantic/Canary' | 'Atlantic/Cape_Verde' | 'Atlantic/Faroe' | 'Atlantic/Madeira' | 'Atlantic/Reykjavik' | 'Atlantic/South_Georgia' | 'Atlantic/St_Helena' | 'Atlantic/Stanley' | 'Australia/Adelaide' | 'Australia/Brisbane' | 'Australia/Broken_Hill' | 'Australia/Currie' | 'Australia/Darwin' | 'Australia/Eucla' | 'Australia/Hobart' | 'Australia/Lindeman' | 'Australia/Lord_Howe' | 'Australia/Melbourne' | 'Australia/Perth' | 'Australia/Sydney' | 'Europe/Amsterdam' | 'Europe/Andorra' | 'Europe/Astrakhan' | 'Europe/Athens' | 'Europe/Belgrade' | 'Europe/Berlin' | 'Europe/Bratislava' | 'Europe/Brussels' | 'Europe/Bucharest' | 'Europe/Budapest' | 'Europe/Busingen' | 'Europe/Chisinau' | 'Europe/Copenhagen' | 'Europe/Dublin' | 'Europe/Gibraltar' | 'Europe/Guernsey' | 'Europe/Helsinki' | 'Europe/Isle_of_Man' | 'Europe/Istanbul' | 'Europe/Jersey' | 'Europe/Kaliningrad' | 'Europe/Kiev' | 'Europe/Kirov' | 'Europe/Lisbon' | 'Europe/Ljubljana' | 'Europe/London' | 'Europe/Luxembourg' | 'Europe/Madrid' | 'Europe/Malta' | 'Europe/Mariehamn' | 'Europe/Minsk' | 'Europe/Monaco' | 'Europe/Moscow' | 'Europe/Oslo' | 'Europe/Paris' | 'Europe/Podgorica' | 'Europe/Prague' | 'Europe/Riga' | 'Europe/Rome' | 'Europe/Samara' | 'Europe/San_Marino' | 'Europe/Sarajevo' | 'Europe/Saratov' | 'Europe/Simferopol' | 'Europe/Skopje' | 'Europe/Sofia' | 'Europe/Stockholm' | 'Europe/Tallinn' | 'Europe/Tirane' | 'Europe/Ulyanovsk' | 'Europe/Uzhgorod' | 'Europe/Vaduz' | 'Europe/Vatican' | 'Europe/Vienna' | 'Europe/Vilnius' | 'Europe/Volgograd' | 'Europe/Warsaw' | 'Europe/Zagreb' | 'Europe/Zaporozhye' | 'Europe/Zurich' | 'Indian/Antananarivo' | 'Indian/Chagos' | 'Indian/Christmas' | 'Indian/Cocos' | 'Indian/Comoro' | 'Indian/Kerguelen' | 'Indian/Mahe' | 'Indian/Maldives' | 'Indian/Mauritius' | 'Indian/Mayotte' | 'Indian/Reunion' | 'Pacific/Apia' | 'Pacific/Auckland' | 'Pacific/Bougainville' | 'Pacific/Chatham' | 'Pacific/Chuuk' | 'Pacific/Easter' | 'Pacific/Efate' | 'Pacific/Enderbury' | 'Pacific/Fakaofo' | 'Pacific/Fiji' | 'Pacific/Funafuti' | 'Pacific/Galapagos' | 'Pacific/Gambier' | 'Pacific/Guadalcanal' | 'Pacific/Guam' | 'Pacific/Honolulu' | 'Pacific/Kiritimati' | 'Pacific/Kosrae' | 'Pacific/Kwajalein' | 'Pacific/Majuro' | 'Pacific/Marquesas' | 'Pacific/Nauru' | 'Pacific/Niue' | 'Pacific/Norfolk' | 'Pacific/Noumea' | 'Pacific/Pago_Pago' | 'Pacific/Palau' | 'Pacific/Pitcairn' | 'Pacific/Pohnpei' | 'Pacific/Port_Moresby' | 'Pacific/Rarotonga' | 'Pacific/Tahiti' | 'Pacific/Tarawa' | 'Pacific/Tongatapu' | 'Pacific/Wake' | 'Pacific/Wallis' | 'UTC' | 'W-SU' | 'WET' | 'Zulu' | (string & {});
2
+ export default TimeZone;
@@ -0,0 +1,6 @@
1
+ import { 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;
@@ -0,0 +1,11 @@
1
+ import { Formats as IntlFormats } from 'intl-messageformat';
2
+ import Formats from './Formats';
3
+ import TimeZone from './TimeZone';
4
+ /**
5
+ * `intl-messageformat` uses separate keys for `date` and `time`, but there's
6
+ * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
7
+ * include both a time and a date in a value, therefore the separation doesn't
8
+ * seem so useful. We offer a single `dateTime` namespace instead, but we have
9
+ * to convert the format before `intl-messageformat` can be used.
10
+ */
11
+ export default function convertFormatsToIntlMessageFormat(formats: Formats, timeZone?: TimeZone): Partial<IntlFormats>;
@@ -0,0 +1,24 @@
1
+ import { ReactElement, ReactNodeArray } from 'react';
2
+ import AbstractIntlMessages from './AbstractIntlMessages';
3
+ import Formats from './Formats';
4
+ import { InitializedIntlConfig } from './IntlConfig';
5
+ import IntlError from './IntlError';
6
+ import TranslationValues, { MarkupTranslationValues, RichTranslationValues } from './TranslationValues';
7
+ import { Formatters, IntlCache } from './formatters';
8
+ import MessageKeys from './utils/MessageKeys';
9
+ import NestedKeyOf from './utils/NestedKeyOf';
10
+ import NestedValueOf from './utils/NestedValueOf';
11
+ export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
12
+ cache: IntlCache;
13
+ formatters: Formatters;
14
+ defaultTranslationValues?: RichTranslationValues;
15
+ namespace?: string;
16
+ messagesOrError: Messages | IntlError;
17
+ };
18
+ export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(config: Omit<CreateBaseTranslatorProps<Messages>, 'messagesOrError'>): {
19
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats): string;
20
+ rich: (key: string, values?: RichTranslationValues, formats?: Formats) => string | ReactElement | ReactNodeArray;
21
+ markup(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => string | ReactElement | ReactNodeArray>[0], values: MarkupTranslationValues, formats?: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => string | ReactElement | ReactNodeArray>[2]): string;
22
+ raw(key: string): any;
23
+ has(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => string | ReactElement | ReactNodeArray>[0]): boolean;
24
+ };
@@ -0,0 +1,27 @@
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 {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ import { ReactElement, ReactNodeArray } 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): string | ReactElement | ReactNodeArray;
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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
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) => string | import("react").ReactElement | import("react").ReactNodeArray;
14
+ markup(key: Parameters<(key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => string | import("react").ReactElement | import("react").ReactNodeArray>[0], values: import("./TranslationValues").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => string | import("react").ReactElement | import("react").ReactNodeArray>[2]): string;
15
+ raw(key: string): any;
16
+ has(key: Parameters<(key: string, values?: import("./TranslationValues").RichTranslationValues, formats?: import("./Formats").default) => string | import("react").ReactElement | import("react").ReactNodeArray>[0]): boolean;
17
+ };
@@ -0,0 +1,11 @@
1
+ import IntlError from './IntlError';
2
+ /**
3
+ * Contains defaults that are used for all entry points into the core.
4
+ * See also `InitializedIntlConfiguration`.
5
+ */
6
+ export declare function defaultGetMessageFallback(props: {
7
+ error: IntlError;
8
+ key: string;
9
+ namespace?: string;
10
+ }): string;
11
+ export declare function defaultOnError(error: IntlError): void;
@@ -0,0 +1,25 @@
1
+ import type IntlMessageFormat from 'intl-messageformat';
2
+ export type IntlCache = {
3
+ dateTime: Record<string, Intl.DateTimeFormat>;
4
+ number: Record<string, Intl.NumberFormat>;
5
+ message: Record<string, IntlMessageFormat>;
6
+ relativeTime: Record<string, Intl.RelativeTimeFormat>;
7
+ pluralRules: Record<string, Intl.PluralRules>;
8
+ list: Record<string, Intl.ListFormat>;
9
+ displayNames: Record<string, Intl.DisplayNames>;
10
+ };
11
+ export declare function createCache(): IntlCache;
12
+ export declare function memoFn<Fn extends (...args: Array<any>) => any>(fn: Fn, cache: Record<string, ReturnType<Fn> | undefined>): Fn;
13
+ export type IntlFormatters = {
14
+ getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
15
+ getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
16
+ getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
17
+ getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
18
+ getListFormat(...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
19
+ getDisplayNames(...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
20
+ };
21
+ export declare function createIntlFormatters(cache: IntlCache): IntlFormatters;
22
+ export type MessageFormatter = (...args: ConstructorParameters<typeof IntlMessageFormat>) => IntlMessageFormat;
23
+ export type Formatters = IntlFormatters & {
24
+ getMessageFormat?: MessageFormatter;
25
+ };
@@ -0,0 +1,16 @@
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 { default as IntlError, IntlErrorCode } from './IntlError';
8
+ export { default as createTranslator } from './createTranslator';
9
+ export { default as createFormatter } from './createFormatter';
10
+ export { default as initializeConfig } from './initializeConfig';
11
+ export type { default as MessageKeys } from './utils/MessageKeys';
12
+ export type { default as NamespaceKeys } from './utils/NamespaceKeys';
13
+ export type { default as NestedKeyOf } from './utils/NestedKeyOf';
14
+ export type { default as NestedValueOf } from './utils/NestedValueOf';
15
+ export { createIntlFormatters as _createIntlFormatters } from './formatters';
16
+ export { createCache as _createCache } from './formatters';
@@ -0,0 +1,13 @@
1
+ import IntlConfig from './IntlConfig';
2
+ /**
3
+ * Enhances the incoming props with defaults.
4
+ */
5
+ export default function initializeConfig<Props extends IntlConfig>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
6
+ messages: import("./AbstractIntlMessages").default | undefined;
7
+ onError: (error: import("./IntlError").default) => void;
8
+ getMessageFallback: (info: {
9
+ error: import("./IntlError").default;
10
+ key: string;
11
+ namespace?: string;
12
+ }) => string;
13
+ };
@@ -0,0 +1 @@
1
+ export default function joinPath(...parts: Array<string | undefined>): string;
@@ -0,0 +1,5 @@
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
+ export default function resolveNamespace(namespace: string, namespacePrefix: string): string | undefined;
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,2 @@
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;
@@ -0,0 +1,3 @@
1
+ import AbstractIntlMessages from './AbstractIntlMessages';
2
+ import IntlError from './IntlError';
3
+ export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
@@ -0,0 +1 @@
1
+ export * from './core/index';
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ export * from './react';
@@ -0,0 +1,8 @@
1
+ import type { InitializedIntlConfig } from '../core/IntlConfig';
2
+ import type { Formatters, IntlCache } from '../core/formatters';
3
+ export type IntlContextValue = InitializedIntlConfig & {
4
+ formatters: Formatters;
5
+ cache: IntlCache;
6
+ };
7
+ declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
8
+ export default IntlContext;
@@ -0,0 +1,7 @@
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 {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
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';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import createFormatter from '../core/createFormatter';
2
+ export default function useFormatter(): ReturnType<typeof createFormatter>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { IntlContextValue } from './IntlContext';
2
+ export default function useIntlContext(): IntlContextValue;
@@ -0,0 +1 @@
1
+ export default function useLocale(): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { AbstractIntlMessages } from '../core';
2
+ export default function useMessages(): AbstractIntlMessages;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
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 {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export default function useTimeZone(): import("../core/TimeZone").default | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { ReactElement, ReactNodeArray } 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): string | ReactElement | ReactNodeArray;
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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
+ import NestedKeyOf from '../core/utils/NestedKeyOf';
3
+ export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): {
4
+ <TargetKey extends unknown>(key: TargetKey, values?: import("../core").TranslationValues, formats?: import("../core").Formats): string;
5
+ rich: (key: string, values?: import("../core").RichTranslationValues, formats?: import("../core").Formats) => string | import("react").ReactElement | import("react").ReactNodeArray;
6
+ markup(key: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: import("../core").Formats) => string | import("react").ReactElement | import("react").ReactNodeArray>[0], values: import("../core").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: import("../core").Formats) => string | import("react").ReactElement | import("react").ReactNodeArray>[2]): string;
7
+ raw(key: string): any;
8
+ has(key: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: import("../core").Formats) => string | import("react").ReactElement | import("react").ReactNodeArray>[0]): boolean;
9
+ };
@@ -0,0 +1 @@
1
+ export * from './react/index';
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "use-intl",
3
+ "version": "0.0.0-canary-5bbd7ad56b530e283b07cff950de61d6af81f00c",
4
+ "sideEffects": false,
5
+ "author": "Jan Amann <jan@amann.work>",
6
+ "description": "Internationalization (i18n) for React",
7
+ "license": "MIT",
8
+ "homepage": "https://next-intl-docs.vercel.app/",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/amannn/next-intl/tree/main/packages/use-intl"
12
+ },
13
+ "scripts": {
14
+ "build": "rm -rf dist && rollup -c",
15
+ "test": "TZ=Europe/Berlin vitest",
16
+ "lint": "pnpm run lint:source && pnpm run lint:package",
17
+ "lint:source": "eslint src test && tsc --noEmit",
18
+ "lint:package": "publint && attw --pack",
19
+ "prepublishOnly": "turbo build",
20
+ "size": "size-limit"
21
+ },
22
+ "main": "./dist/index.js",
23
+ "module": "dist/esm/index.js",
24
+ "typings": "./dist/types/src/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/types/src/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./core": {
31
+ "types": "./core.d.ts",
32
+ "default": "./dist/core.js"
33
+ },
34
+ "./react": {
35
+ "types": "./react.d.ts",
36
+ "default": "./dist/react.js"
37
+ },
38
+ "./_useLocale": {
39
+ "types": "./_useLocale.d.ts",
40
+ "default": "./dist/_useLocale.js"
41
+ },
42
+ "./_IntlProvider": {
43
+ "types": "./_IntlProvider.d.ts",
44
+ "default": "./dist/_IntlProvider.js"
45
+ }
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "core.d.ts",
50
+ "react.d.ts",
51
+ "_useLocale.d.ts",
52
+ "_IntlProvider.d.ts"
53
+ ],
54
+ "keywords": [
55
+ "react",
56
+ "intl",
57
+ "i18n",
58
+ "internationalization",
59
+ "localization",
60
+ "translate",
61
+ "translation",
62
+ "format",
63
+ "formatting"
64
+ ],
65
+ "dependencies": {
66
+ "@formatjs/fast-memoize": "^2.2.0",
67
+ "intl-messageformat": "^10.5.14"
68
+ },
69
+ "peerDependencies": {
70
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
71
+ },
72
+ "gitHead": "dcb31a81d57ffc42072cf150c2d4b808a679a00c"
73
+ }
package/react.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/types/src/react';