1import { useEffect, useReducer, useMemo } from 'react';
2import ExpoLocalization, { addCalendarListener, addLocaleListener, removeSubscription, } from './ExpoLocalization';
3export * from './Localization.types';
4// @needsAudit
5/**
6 * @deprecated Use Localization.getLocales() instead.
7 * Three-character ISO 4217 currency code. Returns `null` on web.
8 *
9 * @example `'USD'`, `'EUR'`, `'CNY'`, `null`
10 */
11export const currency = ExpoLocalization.currency;
12// @needsAudit
13/**
14 * @deprecated Use Localization.getLocales() instead.
15 * Decimal separator used for formatting numbers.
16 *
17 * @example `','`, `'.'`
18 */
19export const decimalSeparator = ExpoLocalization.decimalSeparator;
20// @needsAudit
21/**
22 * @deprecated Use Localization.getLocales() instead.
23 * Digit grouping separator used when formatting numbers larger than 1000.
24 *
25 * @example `'.'`, `''`, `','`
26 */
27export const digitGroupingSeparator = ExpoLocalization.digitGroupingSeparator;
28// @needsAudit
29/**
30 * @deprecated Use Localization.getLocales() instead.
31 * A list of all the supported language ISO codes.
32 */
33export const isoCurrencyCodes = ExpoLocalization.isoCurrencyCodes;
34// @needsAudit
35/**
36 * @deprecated Use Localization.getLocales() instead.
37 * Boolean value that indicates whether the system uses the metric system.
38 * On Android and web, this is inferred from the current region.
39 */
40export const isMetric = ExpoLocalization.isMetric;
41// @needsAudit
42/**
43 * @deprecated Use Localization.getLocales() instead.
44 * Returns if the system's language is written from Right-to-Left.
45 * This can be used to build features like [bidirectional icons](https://material.io/design/usability/bidirectionality.html).
46 *
47 * Returns `false` in Server Side Rendering (SSR) environments.
48 */
49export const isRTL = ExpoLocalization.isRTL;
50// @needsAudit
51/**
52 * Consider using Localization.getLocales() for a list of user preferred locales instead.
53 * An [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag),
54 * consisting of a two-character language code and optional script, region and variant codes.
55 *
56 * @example `'en'`, `'en-US'`, `'zh-Hans'`, `'zh-Hans-CN'`, `'en-emodeng'`
57 */
58export const locale = ExpoLocalization.locale;
59// @needsAudit
60/**
61 * @deprecated Use Localization.getLocales() instead.
62 * List of all the native languages provided by the user settings.
63 * These are returned in the order the user defines in their device settings.
64 *
65 * @example `['en', 'en-US', 'zh-Hans', 'zh-Hans-CN', 'en-emodeng']`
66 */
67export const locales = ExpoLocalization.locales;
68// @needsAudit
69/**
70 * @deprecated Use Localization.getLocales() instead.
71 * The current time zone in display format.
72 * On Web time zone is calculated with Intl.DateTimeFormat().resolvedOptions().timeZone. For a
73 * better estimation you could use the moment-timezone package but it will add significant bloat to
74 * your website's bundle size.
75 *
76 * @example `'America/Los_Angeles'`
77 */
78export const timezone = ExpoLocalization.timezone;
79// @needsAudit
80/**
81 * @deprecated Use Localization.getLocales() instead.
82 * The region code for your device that comes from the Region setting under Language & Region on iOS.
83 * This value is always available on iOS, but might return `null` on Android or web.
84 *
85 * @example `'US'`, `'NZ'`, `null`
86 */
87export const region = ExpoLocalization.region;
88/**
89 * List of user's locales, returned as an array of objects of type `Locale`.
90 * Guaranteed to contain at least 1 element.
91 * These are returned in the order the user defines in their device settings.
92 * On the web currency and measurements systems are not provided, instead returned as null.
93 * If needed, you can infer them from the current region using a lookup table.
94 * @example `[{
95    "languageTag": "pl-PL",
96    "languageCode": "pl",
97    "textDirection": "ltr",
98    "digitGroupingSeparator": " ",
99    "decimalSeparator": ",",
100    "measurementSystem": "metric",
101    "currencyCode": "PLN",
102    "currencySymbol": "zł",
103    "regionCode": "PL"
104  }]`
105 */
106export const getLocales = ExpoLocalization.getLocales;
107/**
108 * List of user's preferred calendars, returned as an array of objects of type `Calendar`.
109 * Guaranteed to contain at least 1 element.
110 * For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.
111 * @example `[
112    {
113      "calendar": "gregory",
114      "timeZone": "Europe/Warsaw",
115      "uses24hourClock": true,
116      "firstWeekday": 1
117    }
118  ]`
119 */
120export const getCalendars = ExpoLocalization.getCalendars;
121/**
122 * A hook providing a list of user's locales, returned as an array of objects of type `Locale`.
123 * Guaranteed to contain at least 1 element.
124 * These are returned in the order the user defines in their device settings.
125 * On the web currency and measurements systems are not provided, instead returned as null.
126 * If needed, you can infer them from the current region using a lookup table.
127 * If the OS settings change, the hook will rerender with a new list of locales.
128 * @example `[{
129    "languageTag": "pl-PL",
130    "languageCode": "pl",
131    "textDirection": "ltr",
132    "digitGroupingSeparator": " ",
133    "decimalSeparator": ",",
134    "measurementSystem": "metric",
135    "currencyCode": "PLN",
136    "currencySymbol": "zł",
137    "regionCode": "PL"
138  }]`
139 */
140export function useLocales() {
141    const [key, invalidate] = useReducer((k) => k + 1, 0);
142    const locales = useMemo(() => getLocales(), [key]);
143    useEffect(() => {
144        const subscription = addLocaleListener(invalidate);
145        return () => {
146            removeSubscription(subscription);
147        };
148    }, []);
149    return locales;
150}
151/**
152 * A hook providing a list of user's preferred calendars, returned as an array of objects of type `Calendar`.
153 * Guaranteed to contain at least 1 element.
154 * For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.
155 * If the OS settings change, the hook will rerender with a new list of calendars.
156 * @example `[
157    {
158      "calendar": "gregory",
159      "timeZone": "Europe/Warsaw",
160      "uses24hourClock": true,
161      "firstWeekday": 1
162    }
163  ]`
164 */
165export function useCalendars() {
166    const [key, invalidate] = useReducer((k) => k + 1, 0);
167    const calendars = useMemo(() => getCalendars(), [key]);
168    useEffect(() => {
169        const subscription = addCalendarListener(invalidate);
170        return () => {
171            removeSubscription(subscription);
172        };
173    }, []);
174    return calendars;
175}
176// @needsAudit
177/**
178 * Get the latest native values from the device. Locale can be changed on some Android devices
179 * without resetting the app.
180 * > On iOS, changing the locale will cause the device to reset meaning the constants will always be
181 * correct.
182 *
183 * @example
184 * ```ts
185 * // When the app returns from the background on Android...
186 *
187 * const { locale } = await Localization.getLocalizationAsync();
188 * ```
189 * @deprecated
190 * Use Localization.getLocales() or Localization.getCalendars() instead.
191 */
192export async function getLocalizationAsync() {
193    return await ExpoLocalization.getLocalizationAsync();
194}
195//# sourceMappingURL=Localization.js.map