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