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.getCalendars() 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    "temperatureUnit": "celsius"
105  }]`
106 */
107export const getLocales = ExpoLocalization.getLocales;
108/**
109 * List of user's preferred calendars, returned as an array of objects of type `Calendar`.
110 * Guaranteed to contain at least 1 element.
111 * For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.
112 * @example `[
113    {
114      "calendar": "gregory",
115      "timeZone": "Europe/Warsaw",
116      "uses24hourClock": true,
117      "firstWeekday": 1
118    }
119  ]`
120 */
121export const getCalendars = ExpoLocalization.getCalendars;
122/**
123 * A hook providing a list of user's locales, returned as an array of objects of type `Locale`.
124 * Guaranteed to contain at least 1 element.
125 * These are returned in the order the user defines in their device settings.
126 * On the web currency and measurements systems are not provided, instead returned as null.
127 * If needed, you can infer them from the current region using a lookup table.
128 * If the OS settings change, the hook will rerender with a new list of locales.
129 * @example `[{
130    "languageTag": "pl-PL",
131    "languageCode": "pl",
132    "textDirection": "ltr",
133    "digitGroupingSeparator": " ",
134    "decimalSeparator": ",",
135    "measurementSystem": "metric",
136    "currencyCode": "PLN",
137    "currencySymbol": "zł",
138    "regionCode": "PL",
139    "temperatureUnit": "celsius"
140  }]`
141 */
142export function useLocales() {
143    const [key, invalidate] = useReducer((k) => k + 1, 0);
144    const locales = useMemo(() => getLocales(), [key]);
145    useEffect(() => {
146        const subscription = addLocaleListener(invalidate);
147        return () => {
148            removeSubscription(subscription);
149        };
150    }, []);
151    return locales;
152}
153/**
154 * A hook providing a list of user's preferred calendars, returned as an array of objects of type `Calendar`.
155 * Guaranteed to contain at least 1 element.
156 * For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.
157 * If the OS settings change, the hook will rerender with a new list of calendars.
158 * @example `[
159    {
160      "calendar": "gregory",
161      "timeZone": "Europe/Warsaw",
162      "uses24hourClock": true,
163      "firstWeekday": 1
164    }
165  ]`
166 */
167export function useCalendars() {
168    const [key, invalidate] = useReducer((k) => k + 1, 0);
169    const calendars = useMemo(() => getCalendars(), [key]);
170    useEffect(() => {
171        const subscription = addCalendarListener(invalidate);
172        return () => {
173            removeSubscription(subscription);
174        };
175    }, []);
176    return calendars;
177}
178// @needsAudit
179/**
180 * Get the latest native values from the device. Locale can be changed on some Android devices
181 * without resetting the app.
182 * > On iOS, changing the locale will cause the device to reset meaning the constants will always be
183 * correct.
184 *
185 * @example
186 * ```ts
187 * // When the app returns from the background on Android...
188 *
189 * const { locale } = await Localization.getLocalizationAsync();
190 * ```
191 * @deprecated
192 * Use Localization.getLocales() or Localization.getCalendars() instead.
193 */
194export async function getLocalizationAsync() {
195    return await ExpoLocalization.getLocalizationAsync();
196}
197//# sourceMappingURL=Localization.js.map